Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync llama.rn #72

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
26 changes: 10 additions & 16 deletions ios/PocketPal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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 = (
Expand All @@ -479,16 +479,16 @@
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;
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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
moduleNameMapper: {
'@react-native-async-storage/async-storage':
'<rootDir>/__mocks__/external/@react-native-async-storage/async-storage.js',
'llama.rn': '<rootDir>/__mocks__/external/llama.rn.ts',
'@pocketpalai/llama.rn': '<rootDir>/__mocks__/external/llama.rn.ts',
'react-dom': '<rootDir>/__mocks__/external/react-dom.js',
'react-native-device-info':
'<rootDir>/__mocks__/external/react-native-device-info.js',
Expand Down
5 changes: 4 additions & 1 deletion jest/fixtures/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompletionParams} from 'llama.rn';
import {CompletionParams} from '@pocketpalai/llama.rn';

import {deviceInfo} from './device-info';

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "PocketPal",
"version": "1.4.3",
"version": "1.4.4",
"private": true,
"scripts": {
"prepare": "husky",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 0 additions & 10 deletions patches/llama.rn+0.3.11.patch

This file was deleted.

10 changes: 8 additions & 2 deletions src/hooks/__tests__/useChatSession.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down
14 changes: 7 additions & 7 deletions src/hooks/useChatSession.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/screens/ChatScreen/__tests__/ChatScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -97,6 +97,9 @@ export const CompletionSettings: React.FC<Props> = ({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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ModelsScreen/ModelSettings/ModelSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/store/ChatSessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/store/ModelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading
Loading