4using System.Collections.Generic;
14 public int ErrorCode {
get;
private set; }
16 public LLMException(
string message,
int errorCode) : base(message)
18 ErrorCode = errorCode;
34 public string assetPath;
35 public string fullPath;
38 public LoraAsset(
string path,
float weight = 1)
40 assetPath =
LLM.GetLLMManagerAsset(path);
41 fullPath = RuntimePath(path);
45 public static string RuntimePath(
string path)
57 List<LoraAsset> loras =
new List<LoraAsset>();
58 public string delimiter =
",";
75 string fullPath =
LoraAsset.RuntimePath(path);
76 for (
int i = 0; i < loras.Count; i++)
79 if (lora.assetPath == path || lora.fullPath == fullPath)
return i;
99 public void Add(
string path,
float weight = 1)
112 if (index != -1) loras.RemoveAt(index);
125 LLMUnitySetup.LogError($
"LoRA {path} not loaded with the LLM");
128 loras[index].weight = weight;
136 public void FromStrings(
string loraString,
string loraWeightsString)
138 if (
string.IsNullOrEmpty(loraString) &&
string.IsNullOrEmpty(loraWeightsString))
146 List<string> loraStringArr =
new List<string>(loraString.Split(delimiter));
147 List<string> loraWeightsStringArr =
new List<string>(loraWeightsString.Split(delimiter));
148 if (loraStringArr.Count != loraWeightsStringArr.Count)
throw new Exception($
"LoRAs number ({loraString}) doesn't match the number of weights ({loraWeightsString})");
150 List<LoraAsset> lorasNew =
new List<LoraAsset>();
151 for (
int i = 0; i < loraStringArr.Count; i++) lorasNew.Add(
new LoraAsset(loraStringArr[i].Trim(),
float.Parse(loraWeightsStringArr[i])));
166 string loraString =
"";
167 string loraWeightsString =
"";
168 for (
int i = 0; i < loras.Count; i++)
172 loraString += delimiter;
173 loraWeightsString += delimiter;
175 loraString += loras[i].assetPath;
176 loraWeightsString += loras[i].weight;
178 return (loraString, loraWeightsString);
187 float[] weights =
new float[loras.Count];
188 for (
int i = 0; i < loras.Count; i++) weights[i] = loras[i].weight;
198 string[] loraPaths =
new string[loras.Count];
199 for (
int i = 0; i < loras.Count; i++) loraPaths[i] = loras[i].assetPath;
Class implementing a basic LLM Destroy Exception.
Class implementing a basic LLM Exception.
Class implementing helper functions for setup and process management.
Class implementing the LLM server.
Class representing a LORA asset.
Class representing the LORA manager allowing to convert and retrieve LORA assets to string (for seria...
float[] GetWeights()
Gets the weights of the LORAs in the manager.
void Add(string path, float weight=1)
Adds a LORA with the defined weight.
void Remove(string path)
Removes a LORA based on its path.
int IndexOf(string path)
Searches for a LORA based on the path.
void SetWeight(string path, float weight)
Modifies the weight of a LORA.
void FromStrings(string loraString, string loraWeightsString)
Converts strings with the lora paths and weights to entries in the LORA manager.
string
Converts the entries of the LORA manager to strings with the lora paths and weights.
bool Contains(string path)
Checks if the provided LORA based on a path exists already in the LORA manager.
string[] GetLoras()
Gets the paths of the LORAs in the manager.
void Clear()
Clears the LORA assets.