Skip to content

Commit

Permalink
Java linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisMik committed Apr 16, 2024
1 parent 1f11168 commit 71dfb8e
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 10 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/java-codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Java CodeStyle

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '**/*.java'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '**/*.java'

jobs:
check-java-codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Check Java CodeStyle
run: java -Dconfig_loc=resources/.lint/java/ -jar resources/.lint/java/checkstyle-10.5.0-all.jar -c resources/.lint/java/checkstyle.xml binding/android/ demo/android/
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
express or implied. See the License for the specific language governing permissions and
limitations under the License.
*/

package ai.picovoice.picollm;

import java.io.File;
Expand Down Expand Up @@ -43,13 +44,19 @@ private PicoLLM(
handle = PicoLLMNative.init(accessKey, modelPath, device);
}

/**
* Function.
*/
public void delete() {
if (handle != 0) {
PicoLLMNative.delete(handle);
handle = 0;
}
}

/**
* Function.
*/
public PicoLLMCompletion generate(
String prompt,
int completionTokenLimit,
Expand All @@ -75,6 +82,9 @@ public PicoLLMCompletion generate(
streamCallback);
}

/**
* Function.
*/
public int[] tokenize(
String text,
boolean bos,
Expand All @@ -86,22 +96,37 @@ public int[] tokenize(
eos);
}

/**
* Function.
*/
public float[] forward(int token) throws PicoLLMException {
return PicoLLMNative.forward(handle, token);
}

/**
* Function.
*/
public void reset() throws PicoLLMException {
PicoLLMNative.reset(handle);
}

/**
* Function.
*/
public String getModel() throws PicoLLMException {
return PicoLLMNative.getModel(handle);
}

/**
* Function.
*/
public int getContextLength() throws PicoLLMException {
return PicoLLMNative.getContextLength(handle);
}

/**
* Class.
*/
public static class Builder {

private String accessKey = null;
Expand All @@ -123,6 +148,9 @@ public Builder setDevice(String device) {
return this;
}

/**
* Function.
*/
public PicoLLM build() throws PicoLLMException {
if (accessKey == null || accessKey.equals("")) {
throw new PicoLLMInvalidArgumentException("No accessKey provided to PicoLLM.");
Expand All @@ -140,6 +168,9 @@ public PicoLLM build() throws PicoLLMException {
}
}

/**
* Class.
*/
public static class GenerateBuilder {

private int completionTokenLimit = -1;
Expand Down Expand Up @@ -197,6 +228,9 @@ public GenerateBuilder setStreamCallback(PicoLLMStreamCallback streamCallback) {
return this;
}

/**
* Function.
*/
public PicoLLMCompletion generate(PicoLLM object, String prompt) throws PicoLLMException {
return object.generate(
prompt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

package ai.picovoice.picollm;

/**
* Class.
*/
public class PicoLLMCompletion {

private final Usage usage;
Expand All @@ -22,8 +25,6 @@ public class PicoLLMCompletion {
/**
* Constructor.
*
* @param transcriptString Inferred transcription.
* @param wordArray Transcribed words and their associated metadata.
*/
public PicoLLMCompletion(
Usage usage,
Expand Down Expand Up @@ -72,15 +73,16 @@ public String getCompletion() {
return completion;
}

/**
* Class.
*/
public static class Usage {
private final int promptTokens;
private final int completionTokens;

/**
* Constructor.
*
* @param endSec End of word in seconds.
* @param speakerTag Speaker tag. It is set to `-1` if speaker diarization is not enabled during initialization.
*/
public Usage(int promptTokens, int completionTokens) {
this.promptTokens = promptTokens;
Expand Down Expand Up @@ -112,15 +114,16 @@ enum Endpoint {
STOP_PHRASE_ENCOUNTERED
}

/**
* Class.
*/
public static class Token {
private final String token;
private final float logProb;

/**
* Constructor.
*
* @param endSec End of word in seconds.
* @param speakerTag Speaker tag. It is set to `-1` if speaker diarization is not enabled during initialization.
*/
public Token(String token, float logProb) {
this.token = token;
Expand All @@ -146,15 +149,16 @@ public float getLogProb() {
}
}

/**
* Class.
*/
public static class CompletionToken {
private final Token token;
private final Token[] topChoices;

/**
* Constructor.
*
* @param endSec End of word in seconds.
* @param speakerTag Speaker tag. It is set to `-1` if speaker diarization is not enabled during initialization.
*/
public CompletionToken(Token token, Token[] topChoices) {
this.token = token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void Setup() throws IOException {

extractExternalAssestsRecursively("test_resources");
testResourcesPath = new File(appContext.getFilesDir(), "test_resources").getAbsolutePath();
defaultModelPath = new File(testResourcesPath, appContext.getString(R.string.pvTestingModelName)).getAbsolutePath();
defaultModelPath = new File(testResourcesPath, appContext.getString(R.string.pvTestingModelName))
.getAbsolutePath();

accessKey = appContext.getString(R.string.pvTestingAccessKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void onClick(View view) {
});
}

ActivityResultLauncher<String[]> modelSelection = registerForActivityResult(new ActivityResultContracts.OpenDocument(),
ActivityResultLauncher<String[]> modelSelection = registerForActivityResult(
new ActivityResultContracts.OpenDocument(),
new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
Expand Down
Binary file added resources/.lint/java/checkstyle-10.5.0-all.jar
Binary file not shown.
Loading

0 comments on commit 71dfb8e

Please sign in to comment.