diff --git a/Editor/LLMCharacterEditor.cs b/Editor/LLMCharacterEditor.cs index 4bf0b945..34de32a5 100644 --- a/Editor/LLMCharacterEditor.cs +++ b/Editor/LLMCharacterEditor.cs @@ -13,18 +13,6 @@ protected override Type[] GetPropertyTypes() return new Type[] { typeof(LLMCharacter) }; } - public void AddClientSettings(SerializedObject llmScriptSO) - { - List attributeClasses = new List(){typeof(LocalRemoteAttribute)}; - attributeClasses.Add(llmScriptSO.FindProperty("remote").boolValue ? typeof(RemoteAttribute) : typeof(LocalAttribute)); - attributeClasses.Add(typeof(LLMAttribute)); - if (llmScriptSO.FindProperty("advancedOptions").boolValue) - { - attributeClasses.Add(typeof(LLMAdvancedAttribute)); - } - ShowPropertiesOfClass("Setup Settings", llmScriptSO, attributeClasses, true); - } - public void AddModelSettings(SerializedObject llmScriptSO, LLMCharacter llmCharacterScript) { EditorGUILayout.LabelField("Model Settings", EditorStyles.boldLabel); @@ -51,11 +39,6 @@ public void AddModelSettings(SerializedObject llmScriptSO, LLMCharacter llmChara } } - public void AddChatSettings(SerializedObject llmScriptSO) - { - ShowPropertiesOfClass("Chat Settings", llmScriptSO, new List { typeof(ChatAttribute) }, true); - } - public override void OnInspectorGUI() { LLMCharacter llmScript = (LLMCharacter)target; @@ -64,8 +47,9 @@ public override void OnInspectorGUI() OnInspectorGUIStart(llmScriptSO); AddOptionsToggles(llmScriptSO); - AddClientSettings(llmScriptSO); + AddSetupSettings(llmScriptSO); AddChatSettings(llmScriptSO); + Space(); AddModelSettings(llmScriptSO, llmScript); OnInspectorGUIEnd(llmScriptSO); diff --git a/Editor/LLMEditor.cs b/Editor/LLMEditor.cs index 99f42997..39e30dc9 100644 --- a/Editor/LLMEditor.cs +++ b/Editor/LLMEditor.cs @@ -14,12 +14,6 @@ protected override Type[] GetPropertyTypes() return new Type[] { typeof(LLM) }; } - public void AddServerLoadersSettings(SerializedObject llmScriptSO, LLM llmScript) - { - EditorGUILayout.LabelField("Setup Settings", EditorStyles.boldLabel); - AddServerSettings(llmScriptSO); - } - public void AddModelLoadersSettings(SerializedObject llmScriptSO, LLM llmScript) { EditorGUILayout.LabelField("Model Settings", EditorStyles.boldLabel); @@ -100,24 +94,6 @@ public void AddModelSettings(SerializedObject llmScriptSO) Space(); } - public void AddServerSettings(SerializedObject llmScriptSO) - { - List attributeClasses = new List(){typeof(LocalRemoteAttribute)}; - attributeClasses.Add(llmScriptSO.FindProperty("remote").boolValue ? typeof(RemoteAttribute) : typeof(LocalAttribute)); - attributeClasses.Add(typeof(LLMAttribute)); - if (llmScriptSO.FindProperty("advancedOptions").boolValue) - { - attributeClasses.Add(typeof(LLMAdvancedAttribute)); - } - ShowPropertiesOfClass("", llmScriptSO, attributeClasses, true); - Space(); - } - - public void AddChatSettings(SerializedObject llmScriptSO) - { - ShowPropertiesOfClass("Chat Settings", llmScriptSO, new List { typeof(ChatAttribute) }, false); - } - void ShowProgress(float progress, string progressText) { if (progress != 1) EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), progress, progressText); @@ -136,7 +112,7 @@ public override void OnInspectorGUI() GUI.enabled = LLMUnitySetup.libraryProgress == 1 && llmScript.modelProgress == 1 && llmScript.modelCopyProgress == 1; AddOptionsToggles(llmScriptSO); - AddServerLoadersSettings(llmScriptSO, llmScript); + AddSetupSettings(llmScriptSO); AddModelLoadersSettings(llmScriptSO, llmScript); GUI.enabled = true; AddChatSettings(llmScriptSO); diff --git a/Editor/PropertyEditor.cs b/Editor/PropertyEditor.cs index ceca258b..7229804a 100644 --- a/Editor/PropertyEditor.cs +++ b/Editor/PropertyEditor.cs @@ -29,6 +29,28 @@ public void AddOptionsToggle(SerializedObject llmScriptSO, string propertyName, } } + public void AddSetupSettings(SerializedObject llmScriptSO) + { + List attributeClasses = new List(){typeof(LocalRemoteAttribute)}; + attributeClasses.Add(llmScriptSO.FindProperty("remote").boolValue ? typeof(RemoteAttribute) : typeof(LocalAttribute)); + attributeClasses.Add(typeof(LLMAttribute)); + if (llmScriptSO.FindProperty("advancedOptions").boolValue) + { + attributeClasses.Add(typeof(LLMAdvancedAttribute)); + } + ShowPropertiesOfClass("Setup Settings", llmScriptSO, attributeClasses, true); + } + + public void AddChatSettings(SerializedObject llmScriptSO) + { + List attributeClasses = new List(){typeof(ChatAttribute)}; + if (llmScriptSO.FindProperty("advancedOptions").boolValue) + { + attributeClasses.Add(typeof(ChatAdvancedAttribute)); + } + ShowPropertiesOfClass("Chat Settings", llmScriptSO, attributeClasses, false); + } + public void AddOptionsToggles(SerializedObject llmScriptSO) { LLMUnitySetup.SetDebugMode((LLMUnitySetup.DebugModeType)EditorGUILayout.EnumPopup("Log Level", LLMUnitySetup.DebugMode)); diff --git a/README.md b/README.md index 70206057..9a99dc96 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ HuggingFace models can be converted to gguf with this [online converter](https:/ ### LLM Settings - `Show/Hide Advanced Options` Toggle to show/hide advanced options from below +- `Log Level` select how verbose the log messages are #### 💻 Setup Settings @@ -345,10 +346,17 @@ If the user's GPU is not supported, the LLM will fall back to the CPU +#### 🗨️ Chat Settings +-
Advanced options + +- `Base Prompt` a common base prompt to use across all LLMCharacter objects using the LLM + +
### LLMCharacter Settings - `Show/Hide Advanced Options` Toggle to show/hide advanced options from below +- `Log Level` select how verbose the log messages are #### 💻 Setup Settings
diff --git a/Runtime/LLM.cs b/Runtime/LLM.cs index 9e4eb9b3..74e51e33 100644 --- a/Runtime/LLM.cs +++ b/Runtime/LLM.cs @@ -79,6 +79,9 @@ public class LLM : MonoBehaviour [ModelAdvanced] public int contextSize = 0; /// Batch size for prompt processing. [ModelAdvanced] public int batchSize = 512; + /// a base prompt to use as a base for all LLMCharacter objects + [TextArea(5, 10), ChatAdvanced] public string basePrompt = ""; + /// Boolean set to true if the server has started and is ready to receive requests, false otherwise. public bool started { get; protected set; } = false; /// Boolean set to true if the server has failed to start. @@ -212,6 +215,7 @@ public async void Awake() if (asynchronousStartup) await Task.Run(() => StartLLMServer()); else StartLLMServer(); if (dontDestroyOnLoad) DontDestroyOnLoad(transform.root.gameObject); + if (basePrompt != "") await SetBasePrompt(basePrompt); } private void SetupLogging() @@ -429,6 +433,7 @@ public async Task Slot(string json) public async Task Completion(string json, Callback streamCallback = null) { AssertStarted(); + if (streamCallback == null) streamCallback = (string s) => {}; StreamWrapper streamWrapper = ConstructStreamWrapper(streamCallback); await Task.Run(() => llmlib.LLM_Completion(LLMObject, json, streamWrapper.GetStringWrapper())); if (!started) return null; @@ -439,6 +444,13 @@ public async Task Completion(string json, Callback streamCallbac return result; } + public async Task SetBasePrompt(string base_prompt) + { + AssertStarted(); + SystemPromptRequest request = new SystemPromptRequest(){system_prompt = base_prompt, prompt = " ", n_predict = 0}; + await Completion(JsonUtility.ToJson(request)); + } + /// /// Allows to cancel the requests in a specific slot of the LLM /// diff --git a/Runtime/LLMInterface.cs b/Runtime/LLMInterface.cs index 76c245cf..f5086595 100644 --- a/Runtime/LLMInterface.cs +++ b/Runtime/LLMInterface.cs @@ -39,6 +39,14 @@ public struct ChatRequest public List messages; } + [Serializable] + public struct SystemPromptRequest + { + public string prompt; + public string system_prompt; + public int n_predict; + } + [Serializable] public struct ChatResult { diff --git a/Runtime/LLMUnitySetup.cs b/Runtime/LLMUnitySetup.cs index e3040a1e..c83d42d0 100644 --- a/Runtime/LLMUnitySetup.cs +++ b/Runtime/LLMUnitySetup.cs @@ -46,6 +46,7 @@ public class LocalAttribute : PropertyAttribute {} public class ModelAttribute : PropertyAttribute {} public class ModelAdvancedAttribute : PropertyAttribute {} public class ChatAttribute : PropertyAttribute {} + public class ChatAdvancedAttribute : PropertyAttribute {} public class LLMUnityAttribute : PropertyAttribute {} public class NotImplementedException : Exception