Skip to content

Improve building process #282

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 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 removed Resources/usearch/arm64/libusearch_c.dylib
Binary file not shown.
81 changes: 0 additions & 81 deletions Resources/usearch/arm64/libusearch_c.dylib.meta

This file was deleted.

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

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

Binary file not shown.
33 changes: 33 additions & 0 deletions Resources/usearch/macos/libusearch_c.dylib.meta

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

8 changes: 8 additions & 0 deletions Resources/usearch/windows.meta

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

81 changes: 0 additions & 81 deletions Resources/usearch/x86_64/libusearch_c.dylib.meta

This file was deleted.

15 changes: 14 additions & 1 deletion Runtime/LLMBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class LLMBuilder
{
static List<StringPair> movedPairs = new List<StringPair>();
public static string BuildTempDir = Path.Combine(Application.temporaryCachePath, "LLMUnityBuild");
public static string androidPluginDir = Path.Combine(Application.dataPath, "Plugins", "Android", "LLMUnity");
static string movedCache = Path.Combine(BuildTempDir, "moved.json");

[InitializeOnLoadMethod]
Expand Down Expand Up @@ -86,7 +87,10 @@ public static void MovePath(string source, string target)
/// <param name="path">path</param>
public static bool DeletePath(string path)
{
if (!LLMUnitySetup.IsSubPath(path, LLMUnitySetup.GetAssetPath()) && !LLMUnitySetup.IsSubPath(path, BuildTempDir))
string[] allowedDirs = new string[] { LLMUnitySetup.GetAssetPath(), BuildTempDir, androidPluginDir};
bool deleteOK = false;
foreach (string allowedDir in allowedDirs) deleteOK = deleteOK || LLMUnitySetup.IsSubPath(path, allowedDir);
if (!deleteOK)
{
LLMUnitySetup.LogError($"Safeguard: {path} will not be deleted because it may not be safe");
return false;
Expand Down Expand Up @@ -167,6 +171,15 @@ public static void HideLibraryPlatforms(string platform)
}
}
}

if (platform == "android")
{
string source = Path.Combine(LLMUnitySetup.libraryPath, "android");
string target = Path.Combine(androidPluginDir, LLMUnitySetup.libraryName);
MoveAction(source, target);
MoveAction(source + ".meta", target + ".meta");
AddActionAddMeta(androidPluginDir);
}
}

/// <summary>
Expand Down
32 changes: 11 additions & 21 deletions Runtime/LLMCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class LLMCharacter : LLMCaller
/// <summary> option to set the number of tokens to retain from the prompt (nKeep) based on the LLMCharacter system prompt </summary>
public bool setNKeepToPrompt = true;
/// <summary> the chat history as list of chat messages </summary>
public List<ChatMessage> chat;
public List<ChatMessage> chat = new List<ChatMessage>();
/// <summary> the grammar to use </summary>
public string grammarString;

Expand Down Expand Up @@ -161,7 +161,7 @@ public override bool IsValidLLM(LLM llmSet)

protected virtual void InitHistory()
{
InitPrompt();
ClearChat();
_ = LoadHistory();
}

Expand Down Expand Up @@ -204,25 +204,14 @@ public virtual string GetCacheSavePath(string filename)
return GetSavePath(filename + ".cache");
}

protected virtual void InitPrompt(bool clearChat = true)
/// <summary>
/// Clear the chat of the LLMCharacter.
/// </summary>
public virtual void ClearChat()
{
if (chat != null)
{
if (clearChat) chat.Clear();
}
else
{
chat = new List<ChatMessage>();
}
chat.Clear();
ChatMessage promptMessage = new ChatMessage { role = "system", content = prompt };
if (chat.Count == 0)
{
chat.Add(promptMessage);
}
else
{
chat[0] = promptMessage;
}
chat.Add(promptMessage);
}

/// <summary>
Expand All @@ -234,7 +223,8 @@ public virtual void SetPrompt(string newPrompt, bool clearChat = true)
{
prompt = newPrompt;
nKeep = -1;
InitPrompt(clearChat);
if (clearChat) ClearChat();
else chat[0] = new ChatMessage { role = "system", content = prompt };
}

protected virtual bool CheckTemplate()
Expand Down Expand Up @@ -585,7 +575,7 @@ public virtual async Task<string> Load(string filename)
}
string json = File.ReadAllText(filepath);
List<ChatMessage> chatHistory = JsonUtility.FromJson<ChatListWrapper>(json).chat;
InitPrompt(true);
ClearChat();
chat.AddRange(chatHistory);
LLMUnitySetup.Log($"Loaded {filepath}");

Expand Down
Loading
Loading