Skip to content

v1.0.1 #13

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

Merged
merged 25 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a8e543f
escape spaces in chmod, show download complete
amakropoulos Jan 11, 2024
851cbaf
escape spaces in llama.cpp server start
amakropoulos Jan 11, 2024
b096f46
Merge pull request #12 from undreamai/fix/space_in_path
amakropoulos Jan 11, 2024
3cf9e70
fix scaling issues in Samples
amakropoulos Jan 12, 2024
a0e7fec
Merge pull request #14 from undreamai/fix/scaling_scenes_in_samples
amakropoulos Jan 12, 2024
3c4d3ee
bump version to 1.0.1
amakropoulos Jan 12, 2024
438b87f
Merge pull request #15 from undreamai/auto/update_version
amakropoulos Jan 12, 2024
c2053e8
fix scale to 1 in elements
amakropoulos Jan 12, 2024
a3a9191
modify anchoredPosition instead of position
amakropoulos Jan 12, 2024
e224d37
increase bubble width and font size
amakropoulos Jan 12, 2024
28fc36f
Merge pull request #16 from undreamai/fix/scaling_in_chatbot_sample
amakropoulos Jan 12, 2024
a2cec08
add meta file for VERSION
amakropoulos Jan 12, 2024
3726e38
set font size to 16
amakropoulos Jan 12, 2024
dc45e64
change name of assistants in ServerClient sample
amakropoulos Jan 12, 2024
4b2fc24
show chat settings independent of model
amakropoulos Jan 12, 2024
8914cc3
Allow multiple slots for parallel processing based on number of LLMCl…
amakropoulos Jan 12, 2024
69f3d77
add parallelPrompts to Sample Scenes
amakropoulos Jan 12, 2024
38d53ee
add parallelPrompts option to Readme, updte advanced options
amakropoulos Jan 12, 2024
e378383
Merge pull request #17 from undreamai/fix/server_client_ais
amakropoulos Jan 12, 2024
db88508
add changelog
amakropoulos Jan 12, 2024
d9154d0
reduce waiting time to 1 min
amakropoulos Jan 12, 2024
1323b20
start server on enable, counter on awake, LLMClient before LLM execut…
amakropoulos Jan 12, 2024
5b18a5a
Merge pull request #18 from undreamai/fix/running_order_LLM_LLMClient
amakropoulos Jan 12, 2024
5e2ed97
use FindObjectsOfType, run LLM objects before LLMClient
amakropoulos Jan 12, 2024
9949e1a
Merge pull request #19 from undreamai/fix/running_order_LLM_LLMClient
amakropoulos Jan 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/GameObject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## v1.0.1
- Fix running commands for projects with space in path
- closes #8
- closes #9
- Fix sample scenes for different screen resolutions
- closes #10
- Allow parallel prompts
7 changes: 7 additions & 0 deletions CHANGELOG.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Editor/LLMEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public override void OnInspectorGUI()
ShowProgress(llmScript.modelCopyProgress, "Model Copying");
if (llmScript.model != ""){
AddModelSettings(llmScriptSO, false);
AddChatSettings(llmScriptSO);
} else {
EditorGUILayout.Space();
}
AddChatSettings(llmScriptSO);
GUI.enabled = true;

EditorGUI.EndChangeCheck();
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ The server can be either a LLMUnity server or a standard [llama.cpp server](http

## Options

- `Show/Hide Advanced Options` Toggle to show/hide advanced options from below

#### :computer: Server Settings

<div>
Expand All @@ -178,24 +180,27 @@ The server can be either a LLMUnity server or a standard [llama.cpp server](http
- `Num GPU Layers` number of model layers to offload to the GPU.
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>
If the user's GPU is not supported, the LLM will fall back to the CPU
- `Debug` select to log the output of the model in the Unity Editor
- `Port` port to run the server
- `Stream` select to receive the reply from the model as it is produced (recommended!).<br>
If it is not selected, the full reply from the model is received in one go
- Advanced options:
- `Parallel Prompts` number of prompts that can happen in parallel (default: -1 = number of LLM/LLMClient objects)
- `Debug` select to log the output of the model in the Unity Editor
- `Port` port to run the server

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

#### :left_speech_bubble: Chat Settings
- `Player Name` the name of the player
Expand Down
15 changes: 9 additions & 6 deletions Runtime/LLM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

namespace LLMUnity
{
[DefaultExecutionOrder(-2)]
public class LLM : LLMClient
{
[HideInInspector] public bool modelHide = true;

[Server] public int numThreads = -1;
[Server] public int numGPULayers = 0;
[ServerAdvanced] public int parallelPrompts = -1;
[ServerAdvanced] public bool debug = false;

[Model] public string model = "";
Expand All @@ -36,7 +38,7 @@ public class LLM : LLMClient
private static float binariesDone = 0;
private Process process;
private bool serverListening = false;
private static ManualResetEvent serverStarted = new ManualResetEvent(false);
public ManualResetEvent serverStarted = new ManualResetEvent(false);

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

new void OnEnable()
new public void OnEnable()
{
// start the llm server and run the OnEnable of the client
StartLLMServer();
Expand Down Expand Up @@ -156,16 +158,17 @@ private void StartLLMServer()
if (!File.Exists(loraPath)) throw new System.Exception($"File {loraPath} not found!");
}

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

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

public void StopProcess()
Expand Down
3 changes: 2 additions & 1 deletion Runtime/LLMClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class ClientAdvancedAttribute : PropertyAttribute {}
public class ServerAdvancedAttribute : PropertyAttribute {}
public class ModelAdvancedAttribute : PropertyAttribute {}

[DefaultExecutionOrder(-1)]
public class LLMClient : MonoBehaviour
{
{
[HideInInspector] public bool advancedOptions = false;

[ClientAdvanced] public string host = "localhost";
Expand Down
3 changes: 2 additions & 1 deletion Runtime/LLMUnitySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ public static async Task DownloadFile(

if (executable && Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer){
// macOS/Linux: Set executable permissions using chmod
RunProcess("chmod", "+x " + savePath);
RunProcess("chmod", $"+x \"{savePath}\"");
}
AssetDatabase.StopAssetEditing();
Debug.Log($"Download complete!");
}
progresscallback(1f);
callback?.Invoke(savePath);
Expand Down
10 changes: 8 additions & 2 deletions Samples~/ChatBot/Bubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ void SetBubblePosition(RectTransform bubbleRectTransform, RectTransform imageRec
bubbleRectTransform.pivot = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
bubbleRectTransform.anchorMin = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
bubbleRectTransform.anchorMax = new Vector2(bubbleUI.leftPosition, bubbleUI.bottomPosition);
bubbleRectTransform.localScale = Vector3.one;
Vector2 anchoredPosition = new Vector2(bubbleUI.bubbleOffset + bubbleUI.textPadding, bubbleUI.bubbleOffset + bubbleUI.textPadding);
if (bubbleUI.leftPosition == 1) anchoredPosition.x *= -1;
if (bubbleUI.bottomPosition == 1) anchoredPosition.y *= -1;
bubbleRectTransform.anchoredPosition = anchoredPosition;

bubbleRectTransform.sizeDelta = new Vector2(600 - 2*bubbleUI.textPadding, bubbleRectTransform.sizeDelta.y - 2*bubbleUI.textPadding);
float width = bubbleUI.bubbleWidth == -1? bubbleRectTransform.sizeDelta.x: bubbleUI.bubbleWidth;
float height = bubbleUI.bubbleHeight == -1? bubbleRectTransform.sizeDelta.y: bubbleUI.bubbleHeight;
bubbleRectTransform.sizeDelta = new Vector2(width-2*bubbleUI.textPadding, height-2*bubbleUI.textPadding);
SyncParentRectTransform(imageRectTransform);
imageRectTransform.offsetMin = new Vector2(-bubbleUI.textPadding, -bubbleUI.textPadding);
imageRectTransform.offsetMax = new Vector2(bubbleUI.textPadding, bubbleUI.textPadding);
Expand Down Expand Up @@ -154,6 +157,7 @@ GameObject CreatePlaceholderObject(Transform parent, RectTransform textRectTrans
RectTransform placeholderRectTransform = placeholderObject.GetComponent<RectTransform>();
placeholderRectTransform.sizeDelta = textRectTransform.sizeDelta;
placeholderRectTransform.anchoredPosition = textRectTransform.anchoredPosition;
placeholderRectTransform.localScale = Vector3.one;
SyncParentRectTransform(placeholderRectTransform);
return placeholderObject;
}
Expand All @@ -168,7 +172,9 @@ GameObject CreateInputFieldObject(Transform parent, Text textObject, Text placeh
inputField.lineType = InputField.LineType.MultiLineSubmit;
inputField.shouldHideMobileInput = false;
inputField.shouldActivateOnSelect = true;
SyncParentRectTransform(inputFieldObject.GetComponent<RectTransform>());
RectTransform inputFieldRect = inputFieldObject.GetComponent<RectTransform>();
inputFieldRect.localScale = Vector3.one;
SyncParentRectTransform(inputFieldRect);
return inputFieldObject;
}

Expand Down
3 changes: 1 addition & 2 deletions Samples~/ChatBot/ChatBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LLMUnity;
using TMPro;

namespace LLMUnitySamples
{
Expand Down Expand Up @@ -117,7 +116,7 @@ public void UpdateBubblePositions()
for (int i = chatBubbles.Count - 1; i >= 0; i--) {
Bubble bubble = chatBubbles[i];
RectTransform childRect = bubble.GetRectTransform();
childRect.position = new Vector2(childRect.position.x, y);
childRect.anchoredPosition = new Vector2(childRect.anchoredPosition.x, y);

// last bubble outside the container
if (y > containerHeight && lastBubbleOutsideFOV == -1){
Expand Down
6 changes: 4 additions & 2 deletions Samples~/ChatBot/Scene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a50e3140c3ecaaf1c848dbf141cc2074, type: 3}
m_Name:
m_EditorClassIdentifier:
advancedOptions: 0
host: localhost
port: 13333
stream: 1
Expand All @@ -459,6 +460,7 @@ MonoBehaviour:
modelHide: 1
numThreads: -1
numGPULayers: 0
parallelPrompts: -1
debug: 0
model:
lora:
Expand Down Expand Up @@ -834,10 +836,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 1550, y: 600}
m_ReferenceResolution: {x: 1280, y: 720}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 1
m_PhysicalUnit: 3
Expand Down
Loading