-
-
Notifications
You must be signed in to change notification settings - Fork 153
Fix issues encountered in the Android build #370
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
base: main
Are you sure you want to change the base?
Changes from all commits
4edf867
f38d0b0
f2827d9
1271ec1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,8 @@ public class LLMCharacter : LLMCaller | |
| protected SemaphoreSlim chatLock = new SemaphoreSlim(1, 1); | ||
| protected string chatTemplate; | ||
| protected ChatTemplate template = null; | ||
| protected Task grammarTask; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great implementation for grammar! This is not needed anymore in release v3.0.0 because I load the grammar from the file directly and just keep it as a serialized string |
||
|
|
||
| /// \endcond | ||
|
|
||
| /// <summary> | ||
|
|
@@ -157,7 +159,7 @@ public override void Awake() | |
| int slotFromServer = llm.Register(this); | ||
| if (slot == -1) slot = slotFromServer; | ||
| } | ||
| InitGrammar(); | ||
| grammarTask = InitGrammar(); | ||
| InitHistory(); | ||
| } | ||
|
|
||
|
|
@@ -273,19 +275,33 @@ protected virtual async Task<bool> InitNKeep() | |
| return true; | ||
| } | ||
|
|
||
| protected virtual void InitGrammar() | ||
| protected virtual async Task InitGrammar() | ||
| { | ||
| grammarString = ""; | ||
| grammarJSONString = ""; | ||
| if (!String.IsNullOrEmpty(grammar)) | ||
| { | ||
| grammarString = File.ReadAllText(LLMUnitySetup.GetAssetPath(grammar)); | ||
| if (!String.IsNullOrEmpty(grammarJSON)) | ||
| LLMUnitySetup.LogWarning("Both GBNF and JSON grammars are set, only the GBNF will be used"); | ||
| await LLMUnitySetup.AndroidExtractAsset(grammar, true); | ||
| string path = LLMUnitySetup.GetAssetPath(grammar); | ||
| if (File.Exists(path)) | ||
| { | ||
| grammarString = File.ReadAllText(path); | ||
| if (!String.IsNullOrEmpty(grammarJSON)) | ||
| LLMUnitySetup.LogWarning("Both GBNF and JSON grammars are set, only the GBNF will be used"); | ||
| } | ||
| else | ||
| { | ||
| LLMUnitySetup.LogError($"Grammar file {path} not found!"); | ||
| } | ||
| } | ||
| else if (!String.IsNullOrEmpty(grammarJSON)) | ||
| { | ||
| grammarJSONString = File.ReadAllText(LLMUnitySetup.GetAssetPath(grammarJSON)); | ||
| await LLMUnitySetup.AndroidExtractAsset(grammarJSON, true); | ||
| string path = LLMUnitySetup.GetAssetPath(grammarJSON); | ||
| if (File.Exists(path)) | ||
| grammarJSONString = File.ReadAllText(path); | ||
| else | ||
| LLMUnitySetup.LogError($"Grammar file {path} not found!"); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -327,10 +343,10 @@ public virtual async Task SetGrammarFile(string path, bool gnbf) | |
| #if UNITY_EDITOR | ||
| if (!EditorApplication.isPlaying) path = LLMUnitySetup.AddAsset(path); | ||
| #endif | ||
| await LLMUnitySetup.AndroidExtractAsset(path, true); | ||
| if (gnbf) grammar = path; | ||
| else grammarJSON = path; | ||
| InitGrammar(); | ||
| grammarTask = InitGrammar(); | ||
| await grammarTask; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -524,6 +540,7 @@ public virtual async Task<string> Chat(string query, Callback<string> callback = | |
| await LoadTemplate(); | ||
| if (!CheckTemplate()) return null; | ||
| if (!await InitNKeep()) return null; | ||
| if (grammarTask != null) await grammarTask; | ||
|
|
||
| ChatRequest request = await PromptWithQuery(query); | ||
| string result = await CompletionRequest(request, callback); | ||
|
|
@@ -562,6 +579,7 @@ public virtual async Task<string> Complete(string prompt, Callback<string> callb | |
| // call the callback function while the answer is received | ||
| // call the completionCallback function when the answer is fully received | ||
| await LoadTemplate(); | ||
| if (grammarTask != null) await grammarTask; | ||
|
|
||
| ChatRequest request = GenerateRequest(prompt); | ||
| string result = await CompletionRequest(request, callback); | ||
|
|
@@ -595,6 +613,7 @@ public virtual async Task Warmup(string query, EmptyCallback completionCallback | |
| await LoadTemplate(); | ||
| if (!CheckTemplate()) return; | ||
| if (!await InitNKeep()) return; | ||
| if (grammarTask != null) await grammarTask; | ||
|
|
||
| ChatRequest request; | ||
| if (String.IsNullOrEmpty(query)) | ||
|
|
@@ -608,6 +627,8 @@ public virtual async Task Warmup(string query, EmptyCallback completionCallback | |
| } | ||
|
|
||
| request.n_predict = 0; | ||
| request.grammar = null; | ||
| request.json_schema = null; | ||
| await CompletionRequest(request); | ||
| completionCallback?.Invoke(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -643,7 +643,7 @@ public static void SaveToDisk() | |
| List<ModelEntry> modelEntriesBuild = new List<ModelEntry>(); | ||
| foreach (ModelEntry modelEntry in modelEntries) | ||
| { | ||
| if (!modelEntry.includeInBuild) continue; | ||
| if (!modelEntry.includeInBuild && string.IsNullOrEmpty(modelEntry.url)) continue; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the model is not included in the build we shouldn't download it. |
||
| modelEntriesBuild.Add(modelEntry.OnlyRequiredFields()); | ||
| } | ||
| string json = JsonUtility.ToJson(new LLMManagerStore | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good error catching - this is now handled from LlamaLib internally.