Skip to content

Commit

Permalink
v1.1 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Oct 1, 2024
1 parent 9baa4dc commit 5f9d0ae
Show file tree
Hide file tree
Showing 206 changed files with 17,128 additions and 943 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: ~/Android/Sdk/platform-tools/adb shell pm uninstall ai.picovoice.picollm.testapp.test || true

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Make Android dir
run: ~/Android/Sdk/platform-tools/adb shell mkdir -p /sdcard/Android/data/ai.picovoice.picollm.testapp/files/external
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
run: ~/Android/Sdk/platform-tools/adb shell pm uninstall ai.picovoice.picollm.testapp.test || true

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Make Android dir
run: ~/Android/Sdk/platform-tools/adb shell mkdir -p /sdcard/Android/data/ai.picovoice.picollm.testapp/files/external
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/c-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
echo PATH=$PATH >> $GITHUB_ENV
- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Create build directory
run: cmake -G "${{ matrix.make_file }}" -B ./build
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ios-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ on:
push:
branches: [ main ]
paths:
- 'demo/ios/**'
- '.github/workflows/ios-demos.yml'
- 'demo/ios/**'
- '!demo/ios/README.md'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'demo/ios/**'
- '.github/workflows/ios-demos.yml'
- 'demo/ios/**'
- '!demo/ios/README.md'

jobs:
build-completion-demo:
Expand All @@ -28,7 +30,7 @@ jobs:
run: gem install cocoapods

- name: Run Cocoapods
run: pod install
run: pod install --repo-update

- name: Build
run: xcrun xcodebuild build
Expand All @@ -53,7 +55,7 @@ jobs:
run: gem install cocoapods

- name: Run Cocoapods
run: pod install
run: pod install --repo-update

- name: Build
run: xcrun xcodebuild build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ios-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
push:
branches: [ main ]
paths:
- '.github/workflows/ios-local.yml'
- '.github/workflows/ios-tests.yml'
- 'binding/ios/PicoLLMAppTest/**'
- 'resources/.test/**'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/ios-local.yml'
- '.github/workflows/ios-tests.yml'
- 'binding/ios/PicoLLMAppTest/**'
- 'resources/.test/**'

Expand All @@ -29,14 +29,14 @@ jobs:
uses: actions/checkout@v3

- name: Run Cocoapods
run: pod install
run: pod install --repo-update

- name: Inject AccessKey
run: sed -i '.bak' 's:{TESTING_ACCESS_KEY_HERE}:${{secrets.PV_VALID_ACCESS_KEY}}:'
PicoLLMAppTestUITests/BaseTest.swift

- name: Inject Resource URL
run: sed -i '.bak' 's?{TESTING_MODEL_URL_HERE}?http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm?'
run: sed -i '.bak' 's?{TESTING_MODEL_URL_HERE}?http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm?'
PicoLLMAppTestUITests/BaseTest.swift

- name: XCode Build
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/nodejs-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,11 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

#### Remove after release ####

- name: Build Node.js binding
run: yarn install && yarn build
working-directory: binding/nodejs

####

- name: Install dependencies
run: yarn install

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Test
run: yarn completion --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --model_path phi2-290.pllm --completion_token_limit 10 --prompt "Hello my name is" --device ${{matrix.xpu}}
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
xpu: [ "cpu" ]
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows ]
include:
- xpu: gpu
Expand All @@ -46,7 +46,7 @@ jobs:
run: yarn install

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o test/phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o test/phi2-290.pllm

- name: Test
run: yarn test test/index.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --device=${{matrix.xpu}}
2 changes: 1 addition & 1 deletion .github/workflows/python-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: python3 -m pip install -r requirements.txt

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Test
run: python3 picollm_demo_completion.py --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --model_path phi2-290.pllm --completion_token_limit 10 --prompt "Hello my name is" --device ${{matrix.xpu}}
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
xpu: [ "cpu" ]
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows ]
include:
- xpu: gpu
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
run: python3 -m pip install -r binding/python/requirements.txt

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm -o phi2-290.pllm

- name: Test
run: python3 -m binding.python.test_picollm ${{secrets.PV_VALID_ACCESS_KEY}} ./phi2-290.pllm ${{matrix.xpu}}
2 changes: 2 additions & 0 deletions .github/workflows/web-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
steps:
- uses: actions/checkout@v3

#### REMOVE AFTER RELEASE ####

- name: Install dependencies
run: yarn install

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: yarn build

- name: Prepare Test
run: yarn setup-test http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm phi2-290.pllm
run: yarn setup-test http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/03-280e68c/phi2-290.pllm phi2-290.pllm

- name: Test Web Worker
run: yarn test --env ACCESS_KEY=${{secrets.PV_VALID_ACCESS_KEY}}
2 changes: 1 addition & 1 deletion binding/android/PicoLLM/picollm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_GROUP_ID = 'ai.picovoice'
PUBLISH_VERSION = '1.0.0'
PUBLISH_VERSION = '1.1.0'
PUBLISH_ARTIFACT_ID = 'picollm-android'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.HashMap;
import java.util.Map;

import android.text.TextUtils;

/**
* Android binding for picoLLM.
*/
Expand Down Expand Up @@ -45,6 +47,7 @@ public class PicoLLM {
phi2Map.put("qa", Phi2QADialog.class);
phi2Map.put("chat", Phi2ChatDialog.class);
DIALOGS.put("phi2", phi2Map);
DIALOGS.put("phi3", Phi3ChatDialog.class);
}

public static void setSdk(String sdk) {
Expand Down Expand Up @@ -149,6 +152,15 @@ public PicoLLMCompletion generate(
generateParams.getStreamCallback());
}

/**
* Interrupts `.generate()` if generation is in progress. Otherwise, it has no effect.
*
* @throws PicoLLMException if interrupt fails.
*/
public void interrupt() throws PicoLLMException {
PicoLLMNative.interrupt(handle);
}

/**
* Tokenizes a given text using the model's tokenizer. This is a low-level function meant for
* benchmarking and advanced usage. `.generate()` should be used when possible.
Expand Down Expand Up @@ -306,7 +318,7 @@ public PicoLLMDialog build() throws PicoLLMException {
String.format(
"`%s` requires a mode. Available modes are: %s",
model,
String.join(", ", dialogModeMap.keySet())));
TextUtils.join(", ", dialogModeMap.keySet())));
}
return instantiateDialog(dialogModeMap.get("default"), history, system);
} else {
Expand All @@ -316,7 +328,7 @@ public PicoLLMDialog build() throws PicoLLMException {
"`%s` doesn't have a `%s` mode. Available modes are: %s",
model,
mode,
String.join(", ", dialogModeMap.keySet())));
TextUtils.join(", ", dialogModeMap.keySet())));
}
return instantiateDialog(dialogModeMap.get(mode), history, system);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public int getCompletionTokens() {
public enum Endpoint {
END_OF_SENTENCE,
COMPLETION_TOKEN_LIMIT_REACHED,
STOP_PHRASE_ENCOUNTERED
STOP_PHRASE_ENCOUNTERED,
INTERRUPTED
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ static native PicoLLMCompletion generate(
int numTopChoices,
PicoLLMStreamCallback streamCallback) throws PicoLLMException;

static native void interrupt(long object) throws PicoLLMException;

static native int[] tokenize(
long object,
String text,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2024 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
limitations under the License.
*/

package ai.picovoice.picollm;

import java.util.ArrayList;
import java.util.List;

import ai.picovoice.picollm.PicoLLMDialog;
import ai.picovoice.picollm.PicoLLMException;
import ai.picovoice.picollm.PicoLLMInvalidStateException;

/**
* Represents a dialog helper specific for the `phi3` model.
*/
public class Phi3ChatDialog extends PicoLLMDialog {

/**
* Builder class for constructing Phi3ChatDialog instances.
*/
public static class Builder extends PicoLLMDialog.Builder {
/**
* Builds a new instance of Phi3ChatDialog based on the configured settings.
*
* @return A new instance of Phi3ChatDialog.
*/
public Phi3ChatDialog build() {
return new Phi3ChatDialog(this.history, this.system);
}
}

/**
* Constructs a Phi3ChatDialog instance with the specified history and system settings.
*
* @param history The history length for the dialog.
* @param system The system instruction for configuring the model's responses.
*/
Phi3ChatDialog(Integer history, String system) {
super(history, system);
}

/**
* Generates a formatted prompt string based on the dialog's content and configured settings.
*
* @return A formatted prompt string.
* @throws PicoLLMException If there's an issue generating the prompt.
*/
@Override
public String getPrompt() throws PicoLLMException {
if (this.humanRequests.size() == this.llmResponses.size()) {
throw new PicoLLMInvalidStateException(
"Cannot create a prompt without an outstanding human request"
);
}

List<String> human = (this.history == null) ? this.humanRequests :
this.humanRequests.subList(
this.humanRequests.size() - (this.history + 1),
this.humanRequests.size());
List<String> llm = (this.history == null) ? this.llmResponses :
(this.history == 0) ? new ArrayList<>() :
this.llmResponses.subList(
this.llmResponses.size() - this.history,
this.llmResponses.size());

StringBuilder res = new StringBuilder();
if (system != null) {
res.append(String.format("<|system|>\n%s<|end|>\n", system));
}

for (int i = 0; i < llm.size(); i++) {
res.append(String.format(
"<|user|>\n%s<|end|>\n",
human.get(i).trim()));
res.append(String.format("<|assistant|>\n%s<|end|>\n",
llm.get(i).trim()));
}

res.append(String.format(
"<|user|>\n%s<|end|>\n",
human.get(human.size() - 1).trim()));
res.append("<|assistant|>\n");

return res.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.10'

implementation 'ai.picovoice:picollm-android:1.0.0'
implementation 'ai.picovoice:picollm-android:1.1.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
Loading

0 comments on commit 5f9d0ae

Please sign in to comment.