Skip to content

Commit

Permalink
models: Revert Llamafile model to gemma 2 2b; Simplify system prompt,…
Browse files Browse the repository at this point in the history
… small models are less capable of following instructions, larger models will get it anyway (#5)
  • Loading branch information
kaspermarstal committed Sep 21, 2024
1 parent 6f99c52 commit 701d2af
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
14 changes: 5 additions & 9 deletions src/Cellm/AddIn/Prompts/CellmPrompts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ internal static class CellmPrompts
{
public const string SystemMessage = @"
<input>
The user has called you via the ""Prompt"" Excel function in a cell formula.
The argument to the formula is the range of cells the user selected, e.g. ""=Prompt(A1)"" or ""=Prompt(A1:D10)"".
The cells are rendered as a table where each cell conist of its coordinate and value.
The user has called you via an Excel formula.
The Excel sheet is rendered as a table where each cell conist of its coordinate and value.
The table is your context and you must use it when following the user's instructions.
<input>
<constraints>
You can only solve tasks that return data suitable for a single cell in a spreadsheet and in a format that is plain text or a numeric value.
If you cannot find any instructions, or you cannot follow user's instructions in a cell-appropriate format, reply with ""#INSTRUCTION_ERROR?"" and nothing else.
</constraints>
<output>
Return ONLY the result of following the user's instructions.
The result must be one of the following:
Return ONLY the result of following the user's instructions as plain text without formatting.
Your response MUST be EITHER:
- A single word or number
- A comma-separated list of words or numbers
- A brief sentence
- A sentence
Be concise. Cells have limited visible space.
Do not provide explanations, steps, or engage in conversation.
Ensure the output is directly usable in a spreadsheet cell.
</output>
";

Expand Down
5 changes: 0 additions & 5 deletions src/Cellm/AddIn/Prompts/PromptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public PromptBuilder(Prompt prompt)

public PromptBuilder SetSystemMessage(string systemMessage)
{
if (_messages.Any(x => x.Role.Equals(Role.System)))
{
throw new CellmException("Cannot set system message when messages already has one");
}

_systemMessage = systemMessage;
return this;
}
Expand Down
13 changes: 7 additions & 6 deletions src/Cellm/Models/Llamafile/LlamafileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LlamafileClient(IOptions<CellmConfiguration> cellmConfiguration,

_llamafileModelPath = new AsyncLazy<string>(async () =>
{
return await DownloadFile(_llamafileConfiguration.Models[_llamafileConfiguration.DefaultModel], $"Llamafile-{_llamafileConfiguration.DefaultModel}", httpClient);
return await DownloadFile(_llamafileConfiguration.Models[_llamafileConfiguration.DefaultModel], $"Llamafile-model-weights-{_llamafileConfiguration.DefaultModel}", httpClient);
});

_llamafileProcess = new AsyncLazy<Process>(async () =>
Expand Down Expand Up @@ -79,7 +79,8 @@ private async Task<Process> StartProcess()

try
{
await WaitForLlamafile(process);
Thread.Sleep(5000);
// await WaitForLlamafile(process);
_llamafileProcessManager.AssignProcessToCellm(process);
return process;
}
Expand Down Expand Up @@ -127,7 +128,7 @@ private async Task WaitForLlamafile(Process process)
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1));
var startTime = DateTime.UtcNow;

// 30 seconds timeout
// Max 30 seconds timeout
while ((DateTime.UtcNow - startTime).TotalSeconds < 30)
{
if (process.HasExited)
Expand All @@ -144,14 +145,14 @@ private async Task WaitForLlamafile(Process process)
return;
}
}
catch (TaskCanceledException)
catch (HttpRequestException)
{
}
catch (HttpRequestException)
catch (TaskCanceledException)
{
}

// Wait for before next attempt
// Wait before next attempt
await Task.Delay(500);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Cellm/appsettings.Local.Llamafile.GPU.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"LlamafileConfiguration": {
"LlamafileUrl": "https://github.com/Mozilla-Ocho/llamafile/releases/download/0.8.13/llamafile-0.8.13",
"DefaultModel": "qwen-2.5-3b-instruct-q6-k-l",
"DefaultModel": "gemma-2-2b-instruct-q6-k",
"Models": {
"qwen-2.5-3b-instruct-q6-k-l": "https://huggingface.co/bartowski/Qwen2.5-3B-Instruct-GGUF/resolve/main/Qwen2.5-3B-Instruct-Q6_K_L.gguf?download=true",
"qwen-2.5-0.5b-instruct-q6-k-l": "https://huggingface.co/bartowski/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/Qwen2.5-0.5B-Instruct-Q6_K_L.gguf?download=true"
"gemma-2-2b-instruct-q6-k": "https://huggingface.co/bartowski/gemma-2-2b-it-GGUF/resolve/main/gemma-2-2b-it-Q6_K.gguf"
},
"Port": 22195,
"GPU": true,
Expand Down
5 changes: 2 additions & 3 deletions src/Cellm/appsettings.Local.Llamafile.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"LlamafileConfiguration": {
"LlamafileUrl": "https://github.com/Mozilla-Ocho/llamafile/releases/download/0.8.13/llamafile-0.8.13",
"DefaultModel": "qwen-2.5-3b-instruct-q6-k-l",
"DefaultModel": "gemma-2-2b-instruct-q6-k",
"Models": {
"qwen-2.5-3b-instruct-q6-k-l": "https://huggingface.co/bartowski/Qwen2.5-3B-Instruct-GGUF/resolve/main/Qwen2.5-3B-Instruct-Q6_K_L.gguf?download=true",
"qwen-2.5-0.5b-instruct-q6-k-l": "https://huggingface.co/bartowski/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/Qwen2.5-0.5B-Instruct-Q6_K_L.gguf?download=true"
"gemma-2-2b-instruct-q6-k": "https://huggingface.co/bartowski/gemma-2-2b-it-GGUF/resolve/main/gemma-2-2b-it-Q6_K.gguf"
},
"Port": 22195
},
Expand Down

0 comments on commit 701d2af

Please sign in to comment.