From 155601b86a83ddf832afbb2502cac7c80de98f01 Mon Sep 17 00:00:00 2001 From: Asghar Ghorbani Date: Fri, 1 Nov 2024 15:23:28 +0100 Subject: [PATCH] feat: sync llama.rn (#72) * feat: sync llama.cpp * chore: use llama.rn under @pocketpalai scope * feat: expose xct settings in ui * feat: expose min_p in ui * chore: bump version --- .github/workflows/ci.yml | 8 +- android/app/build.gradle | 6 +- ios/PocketPal.xcodeproj/project.pbxproj | 26 +++--- ios/Podfile.lock | 8 +- jest.config.js | 2 +- jest/fixtures/models.ts | 5 +- package.json | 4 +- patches/llama.rn+0.3.11.patch | 10 --- src/hooks/__tests__/useChatSession.test.ts | 10 ++- src/hooks/useChatSession.ts | 14 +-- .../ChatScreen/__tests__/ChatScreen.test.tsx | 4 +- .../CompletionSettings/CompletionSettings.tsx | 5 +- .../__tests__/CompletionSettings.test.tsx | 12 +++ .../ModelSettings/ModelSettings.tsx | 2 +- src/store/ChatSessionStore.ts | 2 +- src/store/ModelStore.ts | 2 +- src/store/defaultModels.ts | 89 +++++++++++++++++++ src/utils/chat.ts | 35 ++++---- src/utils/types.ts | 2 +- yarn.lock | 10 +-- 20 files changed, 181 insertions(+), 75 deletions(-) delete mode 100644 patches/llama.rn+0.3.11.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbcf9ec..653d3d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,13 @@ jobs: cache: 'gradle' - name: Build Android - run: yarn build:android + run: yarn build:android # TODO: change to build:android:release + + - name: Upload Android APK + uses: actions/upload-artifact@v3 + with: + name: android-debug-apk # TODO: change to release-apk + path: android/app/build/outputs/apk/debug/app-debug.apk # Job for iOS build build-ios: diff --git a/android/app/build.gradle b/android/app/build.gradle index e82fe41..b3d8c28 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -78,11 +78,11 @@ android { namespace "com.pocketpal" defaultConfig { - applicationId project.hasProperty('appId') ? project.appId : "com.pocketpalai" + applicationId "com.pocketpalai" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 10 - versionName "1.4.3" + versionCode 11 + versionName "1.4.4" ndk { abiFilters "arm64-v8a", "x86_64" } diff --git a/ios/PocketPal.xcodeproj/project.pbxproj b/ios/PocketPal.xcodeproj/project.pbxproj index 9866b63..a56618b 100644 --- a/ios/PocketPal.xcodeproj/project.pbxproj +++ b/ios/PocketPal.xcodeproj/project.pbxproj @@ -425,7 +425,7 @@ baseConfigurationReference = 12009917F81D5194B51E7253 /* Pods-PocketPal-PocketPalTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - DEVELOPMENT_TEAM = "YOUR_TEAM_ID"; + DEVELOPMENT_TEAM = MYXGXY23Y6; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -454,7 +454,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; - DEVELOPMENT_TEAM = "YOUR_TEAM_ID"; + DEVELOPMENT_TEAM = MYXGXY23Y6; INFOPLIST_FILE = PocketPalTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -479,8 +479,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 10; - DEVELOPMENT_TEAM = "YOUR_TEAM_ID"; + CURRENT_PROJECT_VERSION = 11; + DEVELOPMENT_TEAM = MYXGXY23Y6; ENABLE_BITCODE = NO; INFOPLIST_FILE = PocketPal/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -488,7 +488,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.4.3; + MARKETING_VERSION = 1.4.4; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "-DFOLLY_NO_CONFIG", @@ -521,15 +521,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 10; - DEVELOPMENT_TEAM = "YOUR_TEAM_ID"; + CURRENT_PROJECT_VERSION = 11; + DEVELOPMENT_TEAM = MYXGXY23Y6; INFOPLIST_FILE = PocketPal/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.4.3; + MARKETING_VERSION = 1.4.4; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "-DFOLLY_NO_CONFIG", @@ -624,10 +624,7 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = true; @@ -695,10 +692,7 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = true; diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b8207b9..4ba02d1 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -74,7 +74,7 @@ PODS: - hermes-engine/Pre-built (= 0.73.7) - hermes-engine/Pre-built (0.73.7) - libevent (2.1.12) - - llama-rn (0.3.11): + - llama-rn (0.3.12): - React-Core - OpenSSL-Universal (1.1.1100) - RCT-Folly (2022.05.16.00): @@ -1211,7 +1211,7 @@ DEPENDENCIES: - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - libevent (~> 2.1.12) - - llama-rn (from `../node_modules/llama.rn`) + - "llama-rn (from `../node_modules/@pocketpalai/llama.rn`)" - OpenSSL-Universal (= 1.1.1100) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1310,7 +1310,7 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-02-20-RNv0.73.5-18f99ace4213052c5e7cdbcd39ee9766cd5df7e4 llama-rn: - :path: "../node_modules/llama.rn" + :path: "../node_modules/@pocketpalai/llama.rn" RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTRequired: @@ -1451,7 +1451,7 @@ SPEC CHECKSUMS: glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 39589e9c297d024e90fe68f6830ff86c4e01498a libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - llama-rn: 356a7de72150863dcb478224a898c5d0697cba50 + llama-rn: 79f49fb25fc92ecbda076e7cb7b56fb7db6e5ab9 OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0 RCTRequired: 77f73950d15b8c1a2b48ba5b79020c3003d1c9b5 diff --git a/jest.config.js b/jest.config.js index 853010a..e5c13e1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -31,7 +31,7 @@ module.exports = { moduleNameMapper: { '@react-native-async-storage/async-storage': '/__mocks__/external/@react-native-async-storage/async-storage.js', - 'llama.rn': '/__mocks__/external/llama.rn.ts', + '@pocketpalai/llama.rn': '/__mocks__/external/llama.rn.ts', 'react-dom': '/__mocks__/external/react-dom.js', 'react-native-device-info': '/__mocks__/external/react-native-device-info.js', diff --git a/jest/fixtures/models.ts b/jest/fixtures/models.ts index fe1b651..d23a928 100644 --- a/jest/fixtures/models.ts +++ b/jest/fixtures/models.ts @@ -1,4 +1,4 @@ -import {CompletionParams} from 'llama.rn'; +import {CompletionParams} from '@pocketpalai/llama.rn'; import {deviceInfo} from './device-info'; @@ -11,6 +11,9 @@ export const mockDefaultCompletionParams: CompletionParams = { top_k: 40, top_p: 0.95, tfs_z: 1.0, + min_p: 0.05, + xtc_threshold: 0.1, + xtc_probability: 0.01, typical_p: 1.0, penalty_last_n: 64, penalty_repeat: 1.0, diff --git a/package.json b/package.json index 43c6427..a91b684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PocketPal", - "version": "1.4.3", + "version": "1.4.4", "private": true, "scripts": { "prepare": "husky", @@ -24,6 +24,7 @@ }, "dependencies": { "@flyerhq/react-native-link-preview": "^1.6.0", + "@pocketpalai/llama.rn": "^0.3.12", "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-clipboard/clipboard": "^1.14.0", "@react-native-community/slider": "^4.5.2", @@ -36,7 +37,6 @@ "chat-formatter": "^0.3.4", "date-fns": "^3.6.0", "dayjs": "^1.11.11", - "llama.rn": "^0.3.11", "mobx": "^6.12.3", "mobx-persist-store": "^1.1.5", "mobx-react": "^9.1.1", diff --git a/patches/llama.rn+0.3.11.patch b/patches/llama.rn+0.3.11.patch deleted file mode 100644 index 7034c19..0000000 --- a/patches/llama.rn+0.3.11.patch +++ /dev/null @@ -1,10 +0,0 @@ -diff --git a/node_modules/llama.rn/src/index.ts b/node_modules/llama.rn/src/index.ts -index 151dd18..3ba4c2d 100644 ---- a/node_modules/llama.rn/src/index.ts -+++ b/node_modules/llama.rn/src/index.ts -@@ -211,3 +211,5 @@ export async function initLlama({ - export async function releaseAllLlama(): Promise { - return RNLlama.releaseAllContexts() - } -+ -+export default RNLlama; diff --git a/src/hooks/__tests__/useChatSession.test.ts b/src/hooks/__tests__/useChatSession.test.ts index 71eb2c5..45b6f87 100644 --- a/src/hooks/__tests__/useChatSession.test.ts +++ b/src/hooks/__tests__/useChatSession.test.ts @@ -1,4 +1,4 @@ -import {LlamaContext} from 'llama.rn'; +import {LlamaContext} from '@pocketpalai/llama.rn'; import {renderHook, act} from '@testing-library/react-native'; import {textMessage} from '../../../jest/fixtures'; @@ -48,7 +48,13 @@ describe('useChatSession', () => { it('should handle model not loaded scenario', async () => { const {result} = renderHook(() => - useChatSession(null, {current: null}, [], textMessage.author, assistant), + useChatSession( + undefined, + {current: null}, + [], + textMessage.author, + assistant, + ), ); await act(async () => { diff --git a/src/hooks/useChatSession.ts b/src/hooks/useChatSession.ts index f1210d7..86fb18e 100644 --- a/src/hooks/useChatSession.ts +++ b/src/hooks/useChatSession.ts @@ -1,22 +1,22 @@ import React, {useRef, useCallback, useState} from 'react'; import {toJS} from 'mobx'; +import {LlamaContext} from '@pocketpalai/llama.rn'; import throttle from 'lodash.throttle'; -import { - applyChatTemplate, - chatTemplates, - convertToChatMessages, -} from '../utils/chat'; - import {randId} from '../utils'; import {L10nContext} from '../utils'; import {chatSessionStore, modelStore} from '../store'; import {MessageType, User} from '../utils/types'; +import { + applyChatTemplate, + chatTemplates, + convertToChatMessages, +} from '../utils/chat'; export const useChatSession = ( - context: any, + context: LlamaContext | undefined, currentMessageInfo: React.MutableRefObject<{ createdAt: number; id: string; diff --git a/src/screens/ChatScreen/__tests__/ChatScreen.test.tsx b/src/screens/ChatScreen/__tests__/ChatScreen.test.tsx index 9236d99..29df178 100644 --- a/src/screens/ChatScreen/__tests__/ChatScreen.test.tsx +++ b/src/screens/ChatScreen/__tests__/ChatScreen.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {LlamaContext} from 'llama.rn'; +import {LlamaContext} from '@pocketpalai/llama.rn'; import {render, fireEvent, act, waitFor} from '../../../../jest/test-utils'; import {ChatScreen} from '../ChatScreen'; @@ -13,7 +13,7 @@ describe('ChatScreen', () => { beforeEach(() => { jest.clearAllMocks(); - llamaRN = require('llama.rn'); + llamaRN = require('@pocketpalai/llama.rn'); }); it('renders correctly when model is not loaded', () => { diff --git a/src/screens/ModelsScreen/CompletionSettings/CompletionSettings.tsx b/src/screens/ModelsScreen/CompletionSettings/CompletionSettings.tsx index 66efdfa..e604bbe 100644 --- a/src/screens/ModelsScreen/CompletionSettings/CompletionSettings.tsx +++ b/src/screens/ModelsScreen/CompletionSettings/CompletionSettings.tsx @@ -1,7 +1,7 @@ import React, {useState} from 'react'; import {ScrollView, View} from 'react-native'; -import {CompletionParams} from 'llama.rn'; +import {CompletionParams} from '@pocketpalai/llama.rn'; import Slider from '@react-native-community/slider'; import {Card, Text, Switch, TextInput, Divider, Chip} from 'react-native-paper'; @@ -97,6 +97,9 @@ export const CompletionSettings: React.FC = ({settings, onChange}) => { {renderSlider('top_k', 1, 128, 1)} {renderSlider('top_p', 0, 1)} {renderSlider('tfs_z', 0, 2)} + {renderSlider('min_p', 0, 1)} + {renderSlider('xtc_threshold', 0, 1)} + {renderSlider('xtc_probability', 0, 1)} {renderSlider('typical_p', 0, 2)} {renderSlider('penalty_last_n', 0, 256, 1)} {renderSlider('penalty_repeat', 0, 2)} diff --git a/src/screens/ModelsScreen/CompletionSettings/__tests__/CompletionSettings.test.tsx b/src/screens/ModelsScreen/CompletionSettings/__tests__/CompletionSettings.test.tsx index af1dc01..9e483bf 100644 --- a/src/screens/ModelsScreen/CompletionSettings/__tests__/CompletionSettings.test.tsx +++ b/src/screens/ModelsScreen/CompletionSettings/__tests__/CompletionSettings.test.tsx @@ -33,6 +33,18 @@ describe('CompletionSettings', () => { const tfsZSlider = getByTestId('tfs_z-slider'); expect(tfsZSlider.props.value).toBe(1); + expect(getByTestId('min_p-slider')).toBeTruthy(); + const minPSlider = getByTestId('min_p-slider'); + expect(minPSlider.props.value).toBe(0.05); + + expect(getByTestId('xtc_threshold-slider')).toBeTruthy(); + const xtcThresholdSlider = getByTestId('xtc_threshold-slider'); + expect(xtcThresholdSlider.props.value).toBe(0.1); + + expect(getByTestId('xtc_probability-slider')).toBeTruthy(); + const xtcProbabilitySlider = getByTestId('xtc_probability-slider'); + expect(xtcProbabilitySlider.props.value).toBe(0.01); + expect(getByTestId('typical_p-slider')).toBeTruthy(); const typicalPSlider = getByTestId('typical_p-slider'); expect(typicalPSlider.props.value).toBe(1); diff --git a/src/screens/ModelsScreen/ModelSettings/ModelSettings.tsx b/src/screens/ModelsScreen/ModelSettings/ModelSettings.tsx index fe541fb..96409ba 100644 --- a/src/screens/ModelsScreen/ModelSettings/ModelSettings.tsx +++ b/src/screens/ModelsScreen/ModelSettings/ModelSettings.tsx @@ -7,7 +7,7 @@ import { TouchableWithoutFeedback, } from 'react-native'; -import {CompletionParams} from 'llama.rn'; +import {CompletionParams} from '@pocketpalai/llama.rn'; import LinearGradient from 'react-native-linear-gradient'; import MaskedView from '@react-native-masked-view/masked-view'; import { diff --git a/src/store/ChatSessionStore.ts b/src/store/ChatSessionStore.ts index 37881b7..3c2f822 100644 --- a/src/store/ChatSessionStore.ts +++ b/src/store/ChatSessionStore.ts @@ -2,7 +2,7 @@ import {makeAutoObservable, runInAction} from 'mobx'; import RNFS from 'react-native-fs'; import {format, isToday, isYesterday} from 'date-fns'; import {MessageType} from '../utils/types'; -import {LlamaContext} from 'llama.rn'; +import {LlamaContext} from '@pocketpalai/llama.rn'; import {assistant} from '../utils/chat'; const NEW_SESSION_TITLE = 'New Session'; diff --git a/src/store/ModelStore.ts b/src/store/ModelStore.ts index b0a1ea9..fcdf001 100644 --- a/src/store/ModelStore.ts +++ b/src/store/ModelStore.ts @@ -6,7 +6,7 @@ import {v4 as uuidv4} from 'uuid'; import RNFS from 'react-native-fs'; import {makePersistable} from 'mobx-persist-store'; import {computed, makeAutoObservable, ObservableMap, runInAction} from 'mobx'; -import {CompletionParams, LlamaContext, initLlama} from 'llama.rn'; +import {CompletionParams, LlamaContext, initLlama} from '@pocketpalai/llama.rn'; import AsyncStorage from '@react-native-async-storage/async-storage'; import {bytesToGB, hasEnoughSpace} from '../utils'; diff --git a/src/store/defaultModels.ts b/src/store/defaultModels.ts index 64d5e86..45651c1 100644 --- a/src/store/defaultModels.ts +++ b/src/store/defaultModels.ts @@ -1,5 +1,6 @@ import {Model} from '../utils/types'; import {chatTemplates, defaultCompletionParams} from '../utils/chat'; +import {Platform} from 'react-native'; export const MODEL_LIST_VERSION = 5; @@ -332,6 +333,94 @@ export const defaultModels: Model[] = [ stop: ['<|im_end|>'], }, }, + ...(Platform.OS === 'android' + ? [ + { + id: 'default-llama-3.2-1b-instruct-q4_0_4_4.gguf', + name: 'llama-3.2-1b-instruct (Q4_0_4_4)', + type: 'Llama', + size: '0.77', + params: '1.23', + isDownloaded: false, + downloadUrl: + 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_0_4_4.gguf?download=true', + hfUrl: 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF', + progress: 0, + filename: 'default-llama-3.2-1b-instruct-q4_0_4_4.gguf', + isLocal: false, + defaultChatTemplate: {...chatTemplates.llama32}, + chatTemplate: chatTemplates.llama32, + defaultCompletionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + completionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + }, + { + id: 'default-llama-3.2-1b-instruct-q4_0_4_8.gguf', + name: 'llama-3.2-1b-instruct (Q4_0_4_8)', + type: 'Llama', + size: '0.77', + params: '1.23', + isDownloaded: false, + downloadUrl: + 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_0_4_8.gguf?download=true', + hfUrl: 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF', + progress: 0, + filename: 'default-llama-3.2-1b-instruct-q4_0_4_8.gguf', + isLocal: false, + defaultChatTemplate: {...chatTemplates.llama32}, + chatTemplate: chatTemplates.llama32, + defaultCompletionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + completionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + }, + { + id: 'default-llama-3.2-1b-instruct-q4_0_8_8.gguf', + name: 'llama-3.2-1b-instruct (Q4_0_8_8)', + type: 'Llama', + size: '0.77', + params: '1.23', + isDownloaded: false, + downloadUrl: + 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_0_8_8.gguf?download=true', + hfUrl: 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF', + progress: 0, + filename: 'default-llama-3.2-1b-instruct-q4_0_8_8.gguf', + isLocal: false, + defaultChatTemplate: {...chatTemplates.llama32}, + chatTemplate: chatTemplates.llama32, + defaultCompletionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + completionSettings: { + ...defaultCompletionParams, + n_predict: 500, + temperature: 0.5, + stop: ['<|eot_id|>'], + }, + }, + ] + : []), { id: 'default-llama-3.2-1b-instruct-q8_0.gguf', name: 'llama-3.2-1b-instruct (Q8_0)', diff --git a/src/utils/chat.ts b/src/utils/chat.ts index ca13119..f9148b0 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -1,7 +1,7 @@ import {applyTemplate, Templates} from 'chat-formatter'; import {ChatMessage, ChatTemplateConfig, MessageType} from './types'; //import {assistant} from '../store/ChatSessionStore'; -import {CompletionParams} from 'llama.rn'; +import {CompletionParams} from '@pocketpalai/llama.rn'; export const userId = 'y9d7f8pgn'; export const assistantId = 'h3o3lc5xj'; @@ -116,22 +116,25 @@ export const chatTemplates = { export const defaultCompletionParams: CompletionParams = { prompt: '', - n_predict: 400, - temperature: 0.7, - top_k: 40, - top_p: 0.95, - tfs_z: 1.0, - typical_p: 1.0, - penalty_last_n: 64, - penalty_repeat: 1.0, - penalty_freq: 0.0, - penalty_present: 0.0, - mirostat: 0, - mirostat_tau: 5, - mirostat_eta: 0.1, - penalize_nl: false, + n_predict: 400, // The maximum number of tokens to predict when generating text. + temperature: 0.7, // The randomness of the generated text. + top_k: 40, // Limit the next token selection to the K most probable tokens. + top_p: 0.95, // Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. + tfs_z: 1.0, //Enable tail free sampling with parameter z. Default: `1.0`, which is disabled. + min_p: 0.05, //The minimum probability for a token to be considered, relative to the probability of the most likely token. + xtc_threshold: 0.1, // Sets a minimum probability threshold for tokens to be removed. + xtc_probability: 0.0, // Sets the chance for token removal (checked once on sampler start) + typical_p: 1.0, // Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled. + penalty_last_n: 64, // Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size. + penalty_repeat: 1.0, // Control the repetition of token sequences in the generated text. + penalty_freq: 0.0, // Repeat alpha frequency penalty. Default: `0.0`, which is disabled. + penalty_present: 0.0, // Repeat alpha presence penalty. Default: `0.0`, which is disabled. + mirostat: 0, //Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0. + mirostat_tau: 5, // Set the Mirostat target entropy, parameter tau. Default: `5.0` + mirostat_eta: 0.1, // Set the Mirostat learning rate, parameter eta. Default: `0.1` + penalize_nl: false, //Penalize newline tokens when applying the repeat penalty. seed: 0, - n_probs: 0, + n_probs: 0, // If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings. stop: [''], // emit_partial_completion: true, // This is not used in the current version of llama.rn }; diff --git a/src/utils/types.ts b/src/utils/types.ts index a49edf9..04b0a85 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -3,7 +3,7 @@ import {ColorValue, ImageURISource, TextStyle} from 'react-native'; import {MD3Theme} from 'react-native-paper'; import {TemplateConfig} from 'chat-formatter'; -import {CompletionParams, TokenData} from 'llama.rn'; +import {CompletionParams, TokenData} from '@pocketpalai/llama.rn'; import {PreviewData} from '@flyerhq/react-native-link-preview'; import {MD3Colors, MD3Typescale} from 'react-native-paper/lib/typescript/types'; diff --git a/yarn.lock b/yarn.lock index c0077db..cd3342d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1723,6 +1723,11 @@ resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg== +"@pocketpalai/llama.rn@^0.3.12": + version "0.3.12" + resolved "https://registry.yarnpkg.com/@pocketpalai/llama.rn/-/llama.rn-0.3.12.tgz#378bdff95b87a49eccaac2bef368c5ed4c1511e8" + integrity sha512-1nEwiiXlfA5M1JOeokhtXe1jC2mxyNKD5l973Q8cnT67BwDJjsAPQtozqXC17CaxjLiuSfD42ypf1qYf4KMyCg== + "@react-native-async-storage/async-storage@^1.23.1": version "1.24.0" resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.24.0.tgz#888efbc62a26f7d9464b32f4d3027b7f2771999b" @@ -5644,11 +5649,6 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg== -llama.rn@^0.3.11: - version "0.3.11" - resolved "https://registry.yarnpkg.com/llama.rn/-/llama.rn-0.3.11.tgz#6b28cb1818476dac1e1f58c316ca38f531e8e56a" - integrity sha512-yg60pZMsPx7zkaCNryI52n8uHDGp7/T06YqpOq+VtaUgY16rbzSxm/YmdG1e/QlsDuh6B8akBr/4J7nKuEt8bQ== - locate-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"