Skip to content

Commit bb974c6

Browse files
authored
Merge pull request #13 from undreamai/release/v1.0.1
v1.0.1
2 parents 4499041 + 9949e1a commit bb974c6

File tree

16 files changed

+115
-70
lines changed

16 files changed

+115
-70
lines changed

.github/GameObject.png

-15.4 KB
Loading

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## v1.0.1
2+
- Fix running commands for projects with space in path
3+
- closes #8
4+
- closes #9
5+
- Fix sample scenes for different screen resolutions
6+
- closes #10
7+
- Allow parallel prompts

CHANGELOG.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/LLMEditor.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public override void OnInspectorGUI()
6363
ShowProgress(llmScript.modelCopyProgress, "Model Copying");
6464
if (llmScript.model != ""){
6565
AddModelSettings(llmScriptSO, false);
66-
AddChatSettings(llmScriptSO);
66+
} else {
67+
EditorGUILayout.Space();
6768
}
69+
AddChatSettings(llmScriptSO);
6870
GUI.enabled = true;
6971

7072
EditorGUI.EndChangeCheck();

README.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ The server can be either a LLMUnity server or a standard [llama.cpp server](http
168168

169169
## Options
170170

171+
- `Show/Hide Advanced Options` Toggle to show/hide advanced options from below
172+
171173
#### :computer: Server Settings
172174

173175
<div>
@@ -178,24 +180,27 @@ The server can be either a LLMUnity server or a standard [llama.cpp server](http
178180
- `Num GPU Layers` number of model layers to offload to the GPU.
179181
If set to 0 the GPU is not used. Use a large number i.e. >30 to utilise the GPU as much as possible.<br>
180182
If the user's GPU is not supported, the LLM will fall back to the CPU
181-
- `Debug` select to log the output of the model in the Unity Editor
182-
- `Port` port to run the server
183183
- `Stream` select to receive the reply from the model as it is produced (recommended!).<br>
184184
If it is not selected, the full reply from the model is received in one go
185+
- Advanced options:
186+
- `Parallel Prompts` number of prompts that can happen in parallel (default: -1 = number of LLM/LLMClient objects)
187+
- `Debug` select to log the output of the model in the Unity Editor
188+
- `Port` port to run the server
185189

186190
#### :hugs: Model Settings
187191
- `Download model` click to download the default model (Mistral 7B Instruct)
188192
- `Load model` click to load your own model in .gguf format
189193
- `Load lora` click to load a LORA model in .bin format
190194
- `Model` the model being used (inside the Assets/StreamingAssets folder)
191195
- `Lora` the LORA model being used (inside the Assets/StreamingAssets folder)
192-
- `Context Size` Size of the prompt context (0 = context size of the model)
193-
- `Batch Size` Batch size for prompt processing (default: 512)
194-
- `Seed` seed for reproducibility. For random results every time select -1
195-
- `Temperature` LLM temperature, lower values give more deterministic answers
196-
- `Top K` top-k sampling (default: 40, 0 = disabled)
197-
- `Top P` top-p sampling (default: 0.9, 1.0 = disabled)
198-
- `Num Predict` number of tokens to predict (default: 256, -1 = infinity, -2 = until context filled)
196+
- Advanced options:
197+
- `Context Size` Size of the prompt context (0 = context size of the model)
198+
- `Batch Size` Batch size for prompt processing (default: 512)
199+
- `Seed` seed for reproducibility. For random results every time select -1
200+
- `Temperature` LLM temperature, lower values give more deterministic answers
201+
- `Top K` top-k sampling (default: 40, 0 = disabled)
202+
- `Top P` top-p sampling (default: 0.9, 1.0 = disabled)
203+
- `Num Predict` number of tokens to predict (default: 256, -1 = infinity, -2 = until context filled)
199204

200205
#### :left_speech_bubble: Chat Settings
201206
- `Player Name` the name of the player

Runtime/LLM.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
namespace LLMUnity
1111
{
12+
[DefaultExecutionOrder(-2)]
1213
public class LLM : LLMClient
1314
{
1415
[HideInInspector] public bool modelHide = true;
1516

1617
[Server] public int numThreads = -1;
1718
[Server] public int numGPULayers = 0;
19+
[ServerAdvanced] public int parallelPrompts = -1;
1820
[ServerAdvanced] public bool debug = false;
1921

2022
[Model] public string model = "";
@@ -36,7 +38,7 @@ public class LLM : LLMClient
3638
private static float binariesDone = 0;
3739
private Process process;
3840
private bool serverListening = false;
39-
private static ManualResetEvent serverStarted = new ManualResetEvent(false);
41+
public ManualResetEvent serverStarted = new ManualResetEvent(false);
4042

4143
private static string GetAssetPath(string relPath=""){
4244
// Path to store llm server binaries and models
@@ -95,7 +97,7 @@ public async void SetLora(string path){
9597
}
9698
#endif
9799

98-
new void OnEnable()
100+
new public void OnEnable()
99101
{
100102
// start the llm server and run the OnEnable of the client
101103
StartLLMServer();
@@ -156,16 +158,17 @@ private void StartLLMServer()
156158
if (!File.Exists(loraPath)) throw new System.Exception($"File {loraPath} not found!");
157159
}
158160

161+
int slots = parallelPrompts == -1? FindObjectsOfType<LLMClient>().Length: parallelPrompts;
159162
string binary = server;
160-
string arguments = $" --port {port} -m {modelPath} -c {contextSize} -b {batchSize} --log-disable --nobrowser";
163+
string arguments = $" --port {port} -m \"{modelPath}\" -c {contextSize} -b {batchSize} --log-disable --nobrowser -np {slots}";
161164
if (numThreads > 0) arguments += $" -t {numThreads}";
162165
if (numGPULayers > 0) arguments += $" -ngl {numGPULayers}";
163-
if (loraPath != "") arguments += $" --lora {loraPath}";
166+
if (loraPath != "") arguments += $" --lora \"{loraPath}\"";
164167
List<(string, string)> environment = null;
165168

166169
if (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer){
167170
// use APE binary directly if not on Windows
168-
arguments = $"{binary} {arguments}";
171+
arguments = $"\"{binary}\" {arguments}";
169172
binary = SelectApeBinary();
170173
if (numGPULayers <= 0){
171174
// prevent nvcc building if not using GPU
@@ -175,7 +178,7 @@ private void StartLLMServer()
175178
Debug.Log($"Server command: {binary} {arguments}");
176179
process = LLMUnitySetup.CreateProcess(binary, arguments, CheckIfListening, DebugLogError, environment);
177180
// wait for at most 2'
178-
serverStarted.WaitOne(120000);
181+
serverStarted.WaitOne(60000);
179182
}
180183

181184
public void StopProcess()

Runtime/LLMClient.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public class ClientAdvancedAttribute : PropertyAttribute {}
1313
public class ServerAdvancedAttribute : PropertyAttribute {}
1414
public class ModelAdvancedAttribute : PropertyAttribute {}
1515

16+
[DefaultExecutionOrder(-1)]
1617
public class LLMClient : MonoBehaviour
17-
{
18+
{
1819
[HideInInspector] public bool advancedOptions = false;
1920

2021
[ClientAdvanced] public string host = "localhost";

Runtime/LLMUnitySetup.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ public static async Task DownloadFile(
110110

111111
if (executable && Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer){
112112
// macOS/Linux: Set executable permissions using chmod
113-
RunProcess("chmod", "+x " + savePath);
113+
RunProcess("chmod", $"+x \"{savePath}\"");
114114
}
115115
AssetDatabase.StopAssetEditing();
116+
Debug.Log($"Download complete!");
116117
}
117118
progresscallback(1f);
118119
callback?.Invoke(savePath);

Samples~/ChatBot/Bubble.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ void SetBubblePosition(RectTransform bubbleRectTransform, RectTransform imageRec
7878
bubbleRectTransform.pivot = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
7979
bubbleRectTransform.anchorMin = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
8080
bubbleRectTransform.anchorMax = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
81+
bubbleRectTransform.localScale = Vector3.one;
8182
Vector2 anchoredPosition = new Vector2(bubbleUI.bubbleOffset + bubbleUI.textPadding, bubbleUI.bubbleOffset + bubbleUI.textPadding);
8283
if (bubbleUI.leftPosition == 1) anchoredPosition.x *= -1;
8384
if (bubbleUI.bottomPosition == 1) anchoredPosition.y *= -1;
8485
bubbleRectTransform.anchoredPosition = anchoredPosition;
8586

86-
bubbleRectTransform.sizeDelta = new Vector2(600 - 2*bubbleUI.textPadding, bubbleRectTransform.sizeDelta.y - 2*bubbleUI.textPadding);
87+
float width = bubbleUI.bubbleWidth == -1? bubbleRectTransform.sizeDelta.x: bubbleUI.bubbleWidth;
88+
float height = bubbleUI.bubbleHeight == -1? bubbleRectTransform.sizeDelta.y: bubbleUI.bubbleHeight;
89+
bubbleRectTransform.sizeDelta = new Vector2(width-2*bubbleUI.textPadding, height-2*bubbleUI.textPadding);
8790
SyncParentRectTransform(imageRectTransform);
8891
imageRectTransform.offsetMin = new Vector2(-bubbleUI.textPadding, -bubbleUI.textPadding);
8992
imageRectTransform.offsetMax = new Vector2(bubbleUI.textPadding, bubbleUI.textPadding);
@@ -154,6 +157,7 @@ GameObject CreatePlaceholderObject(Transform parent, RectTransform textRectTrans
154157
RectTransform placeholderRectTransform = placeholderObject.GetComponent<RectTransform>();
155158
placeholderRectTransform.sizeDelta = textRectTransform.sizeDelta;
156159
placeholderRectTransform.anchoredPosition = textRectTransform.anchoredPosition;
160+
placeholderRectTransform.localScale = Vector3.one;
157161
SyncParentRectTransform(placeholderRectTransform);
158162
return placeholderObject;
159163
}
@@ -168,7 +172,9 @@ GameObject CreateInputFieldObject(Transform parent, Text textObject, Text placeh
168172
inputField.lineType = InputField.LineType.MultiLineSubmit;
169173
inputField.shouldHideMobileInput = false;
170174
inputField.shouldActivateOnSelect = true;
171-
SyncParentRectTransform(inputFieldObject.GetComponent<RectTransform>());
175+
RectTransform inputFieldRect = inputFieldObject.GetComponent<RectTransform>();
176+
inputFieldRect.localScale = Vector3.one;
177+
SyncParentRectTransform(inputFieldRect);
172178
return inputFieldObject;
173179
}
174180

Samples~/ChatBot/ChatBot.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using LLMUnity;
5-
using TMPro;
65

76
namespace LLMUnitySamples
87
{
@@ -117,7 +116,7 @@ public void UpdateBubblePositions()
117116
for (int i = chatBubbles.Count - 1; i >= 0; i--) {
118117
Bubble bubble = chatBubbles[i];
119118
RectTransform childRect = bubble.GetRectTransform();
120-
childRect.position = new Vector2(childRect.position.x, y);
119+
childRect.anchoredPosition = new Vector2(childRect.anchoredPosition.x, y);
121120

122121
// last bubble outside the container
123122
if (y > containerHeight && lastBubbleOutsideFOV == -1){

Samples~/ChatBot/Scene.unity

+4-2
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ MonoBehaviour:
444444
m_Script: {fileID: 11500000, guid: a50e3140c3ecaaf1c848dbf141cc2074, type: 3}
445445
m_Name:
446446
m_EditorClassIdentifier:
447+
advancedOptions: 0
447448
host: localhost
448449
port: 13333
449450
stream: 1
@@ -459,6 +460,7 @@ MonoBehaviour:
459460
modelHide: 1
460461
numThreads: -1
461462
numGPULayers: 0
463+
parallelPrompts: -1
462464
debug: 0
463465
model:
464466
lora:
@@ -834,10 +836,10 @@ MonoBehaviour:
834836
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
835837
m_Name:
836838
m_EditorClassIdentifier:
837-
m_UiScaleMode: 0
839+
m_UiScaleMode: 1
838840
m_ReferencePixelsPerUnit: 100
839841
m_ScaleFactor: 1
840-
m_ReferenceResolution: {x: 1550, y: 600}
842+
m_ReferenceResolution: {x: 1280, y: 720}
841843
m_ScreenMatchMode: 0
842844
m_MatchWidthOrHeight: 1
843845
m_PhysicalUnit: 3

0 commit comments

Comments
 (0)