Spaces:
Sleeping
Sleeping
feat(models): Llama 3.1 support (#1355)
Browse files* feat(models): Add llama 3.1 405B and 70B
* feat(tools): improve tools support for llama 3.1 models
* feat(models): update mistral to latest
* feat(models): use llama 3.1 8B for tasks
* fix(tools): disable tools by default
* feat(models): update model descriptions in huggingchat
* fix(front): show branding for llama 3
* fix(config): fix encoding
* feat(migrations): reset tools for everyone
* feat(config): replace orgs with final org
* feat(config): update website for llama 3.1
- chart/env/prod.yaml +74 -42
- src/lib/components/ModelCardMetadata.svelte +2 -2
- src/lib/migrations/routines/07-reset-tools-in-settings.ts +19 -0
- src/lib/migrations/routines/index.ts +2 -0
- src/lib/server/models.ts +65 -25
- src/lib/server/textGeneration/tools.ts +11 -4
- src/lib/server/tools/calculator.ts +0 -1
- src/lib/server/tools/documentParser.ts +0 -1
- src/lib/server/tools/images/editing.ts +0 -1
- src/lib/server/tools/images/generation.ts +0 -1
- src/lib/server/tools/web/search.ts +0 -1
- src/lib/server/tools/web/url.ts +0 -1
- src/lib/types/Template.ts +1 -1
chart/env/prod.yaml
CHANGED
|
@@ -38,10 +38,68 @@ envVars:
|
|
| 38 |
METRICS_ENABLED: "true"
|
| 39 |
MODELS: >
|
| 40 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
{
|
| 42 |
"name" : "CohereForAI/c4ai-command-r-plus",
|
| 43 |
"tokenizer": {"tokenizerUrl": "https://huggingface.co/nsarrazin/c4ai-command-r-v01-tokenizer/resolve/main/tokenizer.json", "tokenizerConfigUrl": "https://huggingface.co/nsarrazin/c4ai-command-r-v01-tokenizer/raw/main/tokenizer_config.json"},
|
| 44 |
-
"description": "
|
| 45 |
"modelUrl": "https://huggingface.co/CohereForAI/c4ai-command-r-plus",
|
| 46 |
"websiteUrl": "https://docs.cohere.com/docs/command-r-plus",
|
| 47 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
|
|
@@ -65,36 +123,9 @@ envVars:
|
|
| 65 |
}
|
| 66 |
]
|
| 67 |
},
|
| 68 |
-
{
|
| 69 |
-
"name" : "meta-llama/Meta-Llama-3-70B-Instruct",
|
| 70 |
-
"description": "Meta Llama 3 delivers top performance on various benchmarks and introduces new features like better reasoning.",
|
| 71 |
-
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/meta-logo.png",
|
| 72 |
-
"modelUrl": "https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct",
|
| 73 |
-
"websiteUrl": "https://llama.meta.com/llama3/",
|
| 74 |
-
"tokenizer" : "philschmid/meta-llama-3-tokenizer",
|
| 75 |
-
"promptExamples" : [
|
| 76 |
-
{
|
| 77 |
-
"title": "Write an email from bullet list",
|
| 78 |
-
"prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
|
| 79 |
-
}, {
|
| 80 |
-
"title": "Code a snake game",
|
| 81 |
-
"prompt": "Code a basic snake game in python, give explanations for each step."
|
| 82 |
-
}, {
|
| 83 |
-
"title": "Assist in a task",
|
| 84 |
-
"prompt": "How do I make a delicious lemon cheesecake?"
|
| 85 |
-
}
|
| 86 |
-
],
|
| 87 |
-
"parameters": {
|
| 88 |
-
"stop": ["<|eot_id|>"],
|
| 89 |
-
"truncate": 6144,
|
| 90 |
-
"max_new_tokens": 2047,
|
| 91 |
-
"temperature": 0.6,
|
| 92 |
-
"top_p" : 0.9
|
| 93 |
-
}
|
| 94 |
-
},
|
| 95 |
{
|
| 96 |
"name" : "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 97 |
-
"description" : "
|
| 98 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/mistral-logo.png",
|
| 99 |
"websiteUrl" : "https://mistral.ai/news/mixtral-of-experts/",
|
| 100 |
"modelUrl": "https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
@@ -125,7 +156,7 @@ envVars:
|
|
| 125 |
},
|
| 126 |
{
|
| 127 |
"name" : "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 128 |
-
"description" : "Nous Hermes
|
| 129 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/nous-logo.png",
|
| 130 |
"websiteUrl" : "https://nousresearch.com/",
|
| 131 |
"modelUrl": "https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
|
@@ -156,7 +187,7 @@ envVars:
|
|
| 156 |
{
|
| 157 |
"name": "01-ai/Yi-1.5-34B-Chat",
|
| 158 |
"tokenizer": "01-ai/Yi-1.5-34B-Chat",
|
| 159 |
-
"description" : "
|
| 160 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/01-ai-logo.png",
|
| 161 |
"modelUrl": "https://huggingface.co/01-ai/Yi-1.5-34B-Chat",
|
| 162 |
"websiteUrl": "https://www.01.ai",
|
|
@@ -182,13 +213,13 @@ envVars:
|
|
| 182 |
]
|
| 183 |
},
|
| 184 |
{
|
| 185 |
-
"name": "mistralai/Mistral-7B-Instruct-v0.
|
| 186 |
-
"displayName": "mistralai/Mistral-7B-Instruct-v0.
|
| 187 |
-
"description": "
|
| 188 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/mistral-logo.png",
|
| 189 |
"websiteUrl": "https://mistral.ai/news/announcing-mistral-7b/",
|
| 190 |
-
"modelUrl": "https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.
|
| 191 |
-
"tokenizer": "mistralai/Mistral-7B-Instruct-v0.
|
| 192 |
"preprompt": "",
|
| 193 |
"chatPromptTemplate" : "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s>{{/ifAssistant}}{{/each}}",
|
| 194 |
"parameters": {
|
|
@@ -216,7 +247,7 @@ envVars:
|
|
| 216 |
{
|
| 217 |
"name": "microsoft/Phi-3-mini-4k-instruct",
|
| 218 |
"tokenizer": "microsoft/Phi-3-mini-4k-instruct",
|
| 219 |
-
"description" : "
|
| 220 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/microsoft-logo.png",
|
| 221 |
"modelUrl": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct",
|
| 222 |
"websiteUrl": "https://azure.microsoft.com/en-us/blog/introducing-phi-3-redefining-whats-possible-with-slms/",
|
|
@@ -242,11 +273,11 @@ envVars:
|
|
| 242 |
]
|
| 243 |
},
|
| 244 |
{
|
| 245 |
-
"name": "
|
| 246 |
-
|
| 247 |
"parameters": {
|
| 248 |
"temperature": 0.1,
|
| 249 |
-
"stop": ["<|eot_id|>"],
|
| 250 |
},
|
| 251 |
"unlisted": true
|
| 252 |
}
|
|
@@ -265,7 +296,8 @@ envVars:
|
|
| 265 |
{ "name": "google/gemma-7b-it" },
|
| 266 |
{ "name": "meta-llama/Llama-2-70b-chat-hf" },
|
| 267 |
{ "name": "codellama/CodeLlama-70b-Instruct-hf" },
|
| 268 |
-
{ "name": "openchat/openchat-3.5-0106" }
|
|
|
|
| 269 |
]
|
| 270 |
PUBLIC_ORIGIN: "https://huggingface.co"
|
| 271 |
PUBLIC_SHARE_PREFIX: "https://hf.co/chat"
|
|
@@ -280,7 +312,7 @@ envVars:
|
|
| 280 |
PUBLIC_PLAUSIBLE_SCRIPT_URL: "/js/script.js"
|
| 281 |
PUBLIC_APPLE_APP_ID: "6476778843"
|
| 282 |
REQUIRE_FEATURED_ASSISTANTS: "true"
|
| 283 |
-
TASK_MODEL: "
|
| 284 |
TEXT_EMBEDDING_MODELS: >
|
| 285 |
[{
|
| 286 |
"name": "bge-base-en-v1-5-sxa",
|
|
|
|
| 38 |
METRICS_ENABLED: "true"
|
| 39 |
MODELS: >
|
| 40 |
[
|
| 41 |
+
{
|
| 42 |
+
"name" : "meta-llama/Meta-Llama-3.1-70B-Instruct",
|
| 43 |
+
"id": "meta-llama/Meta-Llama-3.1-70B-Instruct",
|
| 44 |
+
"tokenizer": {"tokenizerUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/resolve/main/tokenizer.json", "tokenizerConfigUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/raw/main/tokenizer_config.json"},
|
| 45 |
+
"description": "Ideal for everyday use. A fast and extremely capable model matching closed source models' capabilities.",
|
| 46 |
+
"modelUrl": "https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct",
|
| 47 |
+
"websiteUrl": "https://llama.meta.com/",
|
| 48 |
+
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/meta-logo.png",
|
| 49 |
+
"tools": true,
|
| 50 |
+
"preprompt" : "You are a helpful assistant with tool calling capabilities. The user has access to the tool's outputs that you as a model cannot see. This could include text, images and more.",
|
| 51 |
+
"parameters": {
|
| 52 |
+
"temperature": 0.1,
|
| 53 |
+
"stop": ["<|endoftext|>", "<|eot_id|>"],
|
| 54 |
+
"max_new_tokens": 1024,
|
| 55 |
+
"truncate": 7167
|
| 56 |
+
},
|
| 57 |
+
"promptExamples": [
|
| 58 |
+
{
|
| 59 |
+
"title": "Write an email from bullet list",
|
| 60 |
+
"prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
|
| 61 |
+
}, {
|
| 62 |
+
"title": "Code a snake game",
|
| 63 |
+
"prompt": "Code a basic snake game in python, give explanations for each step."
|
| 64 |
+
}, {
|
| 65 |
+
"title": "Assist in a task",
|
| 66 |
+
"prompt": "How do I make a delicious lemon cheesecake?"
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"name" : "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
|
| 72 |
+
"id": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
|
| 73 |
+
"tokenizer": {"tokenizerUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/resolve/main/tokenizer.json", "tokenizerConfigUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/raw/main/tokenizer_config.json"},
|
| 74 |
+
"description": "The most intelligent open-source model, showing exceptional capabilities for complex tasks.",
|
| 75 |
+
"modelUrl": "https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
|
| 76 |
+
"websiteUrl": "https://llama.meta.com/",
|
| 77 |
+
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/meta-logo.png",
|
| 78 |
+
"tools": true,
|
| 79 |
+
"preprompt" : "You are a helpful assistant with tool calling capabilities. The user has access to the tool's outputs that you as a model cannot see. This could include text, images and more.",
|
| 80 |
+
"parameters": {
|
| 81 |
+
"temperature": 0.1,
|
| 82 |
+
"stop": ["<|endoftext|>", "<|eot_id|>"],
|
| 83 |
+
"max_new_tokens": 2048,
|
| 84 |
+
"truncate": 14337
|
| 85 |
+
},
|
| 86 |
+
"promptExamples": [
|
| 87 |
+
{
|
| 88 |
+
"title": "Write an email from bullet list",
|
| 89 |
+
"prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
|
| 90 |
+
}, {
|
| 91 |
+
"title": "Code a snake game",
|
| 92 |
+
"prompt": "Code a basic snake game in python, give explanations for each step."
|
| 93 |
+
}, {
|
| 94 |
+
"title": "Assist in a task",
|
| 95 |
+
"prompt": "How do I make a delicious lemon cheesecake?"
|
| 96 |
+
}
|
| 97 |
+
]
|
| 98 |
+
},
|
| 99 |
{
|
| 100 |
"name" : "CohereForAI/c4ai-command-r-plus",
|
| 101 |
"tokenizer": {"tokenizerUrl": "https://huggingface.co/nsarrazin/c4ai-command-r-v01-tokenizer/resolve/main/tokenizer.json", "tokenizerConfigUrl": "https://huggingface.co/nsarrazin/c4ai-command-r-v01-tokenizer/raw/main/tokenizer_config.json"},
|
| 102 |
+
"description": "Cohere's largest language model, optimized for conversational interaction and tool use.",
|
| 103 |
"modelUrl": "https://huggingface.co/CohereForAI/c4ai-command-r-plus",
|
| 104 |
"websiteUrl": "https://docs.cohere.com/docs/command-r-plus",
|
| 105 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
|
|
|
|
| 123 |
}
|
| 124 |
]
|
| 125 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
{
|
| 127 |
"name" : "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 128 |
+
"description" : "A high-quality sparse mixture of experts model with open weights.",
|
| 129 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/mistral-logo.png",
|
| 130 |
"websiteUrl" : "https://mistral.ai/news/mixtral-of-experts/",
|
| 131 |
"modelUrl": "https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
|
|
| 156 |
},
|
| 157 |
{
|
| 158 |
"name" : "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 159 |
+
"description" : "Nous Hermes' strong flagship model trained on the Mixtral 8x7B.",
|
| 160 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/nous-logo.png",
|
| 161 |
"websiteUrl" : "https://nousresearch.com/",
|
| 162 |
"modelUrl": "https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
|
|
|
| 187 |
{
|
| 188 |
"name": "01-ai/Yi-1.5-34B-Chat",
|
| 189 |
"tokenizer": "01-ai/Yi-1.5-34B-Chat",
|
| 190 |
+
"description" : "Strong performance in reasoning while maintaining excellent capabilities in language understanding.",
|
| 191 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/01-ai-logo.png",
|
| 192 |
"modelUrl": "https://huggingface.co/01-ai/Yi-1.5-34B-Chat",
|
| 193 |
"websiteUrl": "https://www.01.ai",
|
|
|
|
| 213 |
]
|
| 214 |
},
|
| 215 |
{
|
| 216 |
+
"name": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 217 |
+
"displayName": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 218 |
+
"description": "A small model with good capabilities in language understanding and commonsense reasoning.",
|
| 219 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/mistral-logo.png",
|
| 220 |
"websiteUrl": "https://mistral.ai/news/announcing-mistral-7b/",
|
| 221 |
+
"modelUrl": "https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3",
|
| 222 |
+
"tokenizer": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 223 |
"preprompt": "",
|
| 224 |
"chatPromptTemplate" : "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s>{{/ifAssistant}}{{/each}}",
|
| 225 |
"parameters": {
|
|
|
|
| 247 |
{
|
| 248 |
"name": "microsoft/Phi-3-mini-4k-instruct",
|
| 249 |
"tokenizer": "microsoft/Phi-3-mini-4k-instruct",
|
| 250 |
+
"description" : "One of the best small models (3.8B parameters), super fast for simple tasks.",
|
| 251 |
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/microsoft-logo.png",
|
| 252 |
"modelUrl": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct",
|
| 253 |
"websiteUrl": "https://azure.microsoft.com/en-us/blog/introducing-phi-3-redefining-whats-possible-with-slms/",
|
|
|
|
| 273 |
]
|
| 274 |
},
|
| 275 |
{
|
| 276 |
+
"name" : "llhf/Meta-Llama-3.1-8B-Instruct",
|
| 277 |
+
"tokenizer": {"tokenizerUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/resolve/main/tokenizer.json", "tokenizerConfigUrl": "https://huggingface.co/nsarrazin/llama3.1-tokenizer/raw/main/tokenizer_config.json"},
|
| 278 |
"parameters": {
|
| 279 |
"temperature": 0.1,
|
| 280 |
+
"stop": ["<|endoftext|>", "<|eot_id|>"],
|
| 281 |
},
|
| 282 |
"unlisted": true
|
| 283 |
}
|
|
|
|
| 296 |
{ "name": "google/gemma-7b-it" },
|
| 297 |
{ "name": "meta-llama/Llama-2-70b-chat-hf" },
|
| 298 |
{ "name": "codellama/CodeLlama-70b-Instruct-hf" },
|
| 299 |
+
{ "name": "openchat/openchat-3.5-0106" },
|
| 300 |
+
{ "name": "meta-llama/Meta-Llama-3-70B-Instruct"}
|
| 301 |
]
|
| 302 |
PUBLIC_ORIGIN: "https://huggingface.co"
|
| 303 |
PUBLIC_SHARE_PREFIX: "https://hf.co/chat"
|
|
|
|
| 312 |
PUBLIC_PLAUSIBLE_SCRIPT_URL: "/js/script.js"
|
| 313 |
PUBLIC_APPLE_APP_ID: "6476778843"
|
| 314 |
REQUIRE_FEATURED_ASSISTANTS: "true"
|
| 315 |
+
TASK_MODEL: "llhf/Meta-Llama-3.1-8B-Instruct"
|
| 316 |
TEXT_EMBEDDING_MODELS: >
|
| 317 |
[{
|
| 318 |
"name": "bge-base-en-v1-5-sxa",
|
src/lib/components/ModelCardMetadata.svelte
CHANGED
|
@@ -42,9 +42,9 @@
|
|
| 42 |
class="ml-auto flex items-center hover:underline"
|
| 43 |
rel="noreferrer"
|
| 44 |
>
|
| 45 |
-
{#if model.name
|
| 46 |
<BIMeta class="mr-1.5 shrink-0 text-xs text-gray-400" />
|
| 47 |
-
Built with
|
| 48 |
{:else}
|
| 49 |
<CarbonEarth class="mr-1.5 shrink-0 text-xs text-gray-400" />
|
| 50 |
Website
|
|
|
|
| 42 |
class="ml-auto flex items-center hover:underline"
|
| 43 |
rel="noreferrer"
|
| 44 |
>
|
| 45 |
+
{#if model.name.startsWith("meta-llama/Meta-Llama")}
|
| 46 |
<BIMeta class="mr-1.5 shrink-0 text-xs text-gray-400" />
|
| 47 |
+
Built with Llama
|
| 48 |
{:else}
|
| 49 |
<CarbonEarth class="mr-1.5 shrink-0 text-xs text-gray-400" />
|
| 50 |
Website
|
src/lib/migrations/routines/07-reset-tools-in-settings.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Migration } from ".";
|
| 2 |
+
import { collections } from "$lib/server/database";
|
| 3 |
+
import { ObjectId } from "mongodb";
|
| 4 |
+
|
| 5 |
+
const resetTools: Migration = {
|
| 6 |
+
_id: new ObjectId("000000000007"),
|
| 7 |
+
name: "Reset tools to empty",
|
| 8 |
+
up: async () => {
|
| 9 |
+
const { settings } = collections;
|
| 10 |
+
|
| 11 |
+
await settings.updateMany({}, { $set: { tools: {} } });
|
| 12 |
+
|
| 13 |
+
return true;
|
| 14 |
+
},
|
| 15 |
+
runEveryTime: false,
|
| 16 |
+
runForHuggingChat: "only",
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
export default resetTools;
|
src/lib/migrations/routines/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import addToolsToSettings from "./03-add-tools-in-settings";
|
|
| 7 |
import updateMessageUpdates from "./04-update-message-updates";
|
| 8 |
import updateMessageFiles from "./05-update-message-files";
|
| 9 |
import trimMessageUpdates from "./06-trim-message-updates";
|
|
|
|
| 10 |
|
| 11 |
export interface Migration {
|
| 12 |
_id: ObjectId;
|
|
@@ -25,4 +26,5 @@ export const migrations: Migration[] = [
|
|
| 25 |
updateMessageUpdates,
|
| 26 |
updateMessageFiles,
|
| 27 |
trimMessageUpdates,
|
|
|
|
| 28 |
];
|
|
|
|
| 7 |
import updateMessageUpdates from "./04-update-message-updates";
|
| 8 |
import updateMessageFiles from "./05-update-message-files";
|
| 9 |
import trimMessageUpdates from "./06-trim-message-updates";
|
| 10 |
+
import resetTools from "./07-reset-tools-in-settings";
|
| 11 |
|
| 12 |
export interface Migration {
|
| 13 |
_id: ObjectId;
|
|
|
|
| 26 |
updateMessageUpdates,
|
| 27 |
updateMessageFiles,
|
| 28 |
trimMessageUpdates,
|
| 29 |
+
resetTools,
|
| 30 |
];
|
src/lib/server/models.ts
CHANGED
|
@@ -96,7 +96,10 @@ async function getChatPromptRender(
|
|
| 96 |
|
| 97 |
const renderTemplate = ({ messages, preprompt, tools, toolResults }: ChatTemplateInput) => {
|
| 98 |
let formattedMessages: { role: string; content: string }[] = messages.map((message) => ({
|
| 99 |
-
content:
|
|
|
|
|
|
|
|
|
|
| 100 |
role: message.from,
|
| 101 |
}));
|
| 102 |
|
|
@@ -113,32 +116,69 @@ async function getChatPromptRender(
|
|
| 113 |
if (toolResults?.length) {
|
| 114 |
// todo: should update the command r+ tokenizer to support system messages at any location
|
| 115 |
// or use the `rag` mode without the citations
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
return (
|
| 125 |
-
`Document: ${idx}\n` +
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
);
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
tools = [];
|
| 143 |
}
|
| 144 |
|
|
|
|
| 96 |
|
| 97 |
const renderTemplate = ({ messages, preprompt, tools, toolResults }: ChatTemplateInput) => {
|
| 98 |
let formattedMessages: { role: string; content: string }[] = messages.map((message) => ({
|
| 99 |
+
content:
|
| 100 |
+
message.files?.length && !tools?.length
|
| 101 |
+
? message.content + `\n This message has ${message.files.length} files attached`
|
| 102 |
+
: message.content,
|
| 103 |
role: message.from,
|
| 104 |
}));
|
| 105 |
|
|
|
|
| 116 |
if (toolResults?.length) {
|
| 117 |
// todo: should update the command r+ tokenizer to support system messages at any location
|
| 118 |
// or use the `rag` mode without the citations
|
| 119 |
+
const id = m.id ?? m.name;
|
| 120 |
+
|
| 121 |
+
if (id.startsWith("CohereForAI")) {
|
| 122 |
+
formattedMessages = [
|
| 123 |
+
{
|
| 124 |
+
role: "system",
|
| 125 |
+
content:
|
| 126 |
+
"\n\n<results>\n" +
|
| 127 |
+
toolResults
|
| 128 |
+
.flatMap((result, idx) => {
|
| 129 |
+
if (result.status === ToolResultStatus.Error) {
|
| 130 |
+
return (
|
| 131 |
+
`Document: ${idx}\n` + `Tool "${result.call.name}" error\n` + result.message
|
| 132 |
+
);
|
| 133 |
+
}
|
| 134 |
return (
|
| 135 |
+
`Document: ${idx}\n` +
|
| 136 |
+
result.outputs
|
| 137 |
+
.flatMap((output) =>
|
| 138 |
+
Object.entries(output).map(([title, text]) => `${title}\n${text}`)
|
| 139 |
+
)
|
| 140 |
+
.join("\n")
|
| 141 |
);
|
| 142 |
+
})
|
| 143 |
+
.join("\n\n") +
|
| 144 |
+
"\n</results>",
|
| 145 |
+
},
|
| 146 |
+
...formattedMessages,
|
| 147 |
+
];
|
| 148 |
+
} else if (id.startsWith("meta-llama")) {
|
| 149 |
+
const results = toolResults.flatMap((result) => {
|
| 150 |
+
if (result.status === ToolResultStatus.Error) {
|
| 151 |
+
return [
|
| 152 |
+
{
|
| 153 |
+
tool_call_id: result.call.name,
|
| 154 |
+
output: "Error: " + result.message,
|
| 155 |
+
},
|
| 156 |
+
];
|
| 157 |
+
} else {
|
| 158 |
+
logger.info(result.outputs);
|
| 159 |
+
return result.outputs.map((output) => ({
|
| 160 |
+
tool_call_id: result.call.name,
|
| 161 |
+
output: JSON.stringify(output),
|
| 162 |
+
}));
|
| 163 |
+
}
|
| 164 |
+
});
|
| 165 |
+
|
| 166 |
+
formattedMessages = [
|
| 167 |
+
...formattedMessages,
|
| 168 |
+
{
|
| 169 |
+
role: "python",
|
| 170 |
+
content: JSON.stringify(results),
|
| 171 |
+
},
|
| 172 |
+
];
|
| 173 |
+
} else {
|
| 174 |
+
formattedMessages = [
|
| 175 |
+
...formattedMessages,
|
| 176 |
+
{
|
| 177 |
+
role: "system",
|
| 178 |
+
content: JSON.stringify(toolResults),
|
| 179 |
+
},
|
| 180 |
+
];
|
| 181 |
+
}
|
| 182 |
tools = [];
|
| 183 |
}
|
| 184 |
|
src/lib/server/textGeneration/tools.ts
CHANGED
|
@@ -143,19 +143,26 @@ export async function* runTools(
|
|
| 143 |
// look for a code blocks of ```json and parse them
|
| 144 |
// if they're valid json, add them to the calls array
|
| 145 |
if (output.generated_text) {
|
|
|
|
|
|
|
|
|
|
| 146 |
const codeBlocks = Array.from(output.generated_text.matchAll(/```json\n(.*?)```/gs))
|
| 147 |
.map(([, block]) => block)
|
| 148 |
// remove trailing comma
|
| 149 |
.map((block) => block.trim().replace(/,$/, ""));
|
| 150 |
if (codeBlocks.length === 0) continue;
|
| 151 |
-
|
| 152 |
// grab only the capture group from the regex match
|
| 153 |
for (const block of codeBlocks) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
try {
|
| 155 |
-
calls.push(
|
| 156 |
-
...JSON5.parse(block).filter(isExternalToolCall).map(externalToToolCall).filter(Boolean)
|
| 157 |
-
);
|
| 158 |
} catch (e) {
|
|
|
|
| 159 |
// error parsing the calls
|
| 160 |
yield {
|
| 161 |
type: MessageUpdateType.Status,
|
|
|
|
| 143 |
// look for a code blocks of ```json and parse them
|
| 144 |
// if they're valid json, add them to the calls array
|
| 145 |
if (output.generated_text) {
|
| 146 |
+
if (!output.generated_text.endsWith("```")) {
|
| 147 |
+
output.generated_text = output.generated_text + "```";
|
| 148 |
+
}
|
| 149 |
const codeBlocks = Array.from(output.generated_text.matchAll(/```json\n(.*?)```/gs))
|
| 150 |
.map(([, block]) => block)
|
| 151 |
// remove trailing comma
|
| 152 |
.map((block) => block.trim().replace(/,$/, ""));
|
| 153 |
if (codeBlocks.length === 0) continue;
|
|
|
|
| 154 |
// grab only the capture group from the regex match
|
| 155 |
for (const block of codeBlocks) {
|
| 156 |
+
// make it an array if it's not already
|
| 157 |
+
let call = JSON5.parse(block);
|
| 158 |
+
if (!Array.isArray(call)) {
|
| 159 |
+
call = [call];
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
try {
|
| 163 |
+
calls.push(...call.filter(isExternalToolCall).map(externalToToolCall).filter(Boolean));
|
|
|
|
|
|
|
| 164 |
} catch (e) {
|
| 165 |
+
logger.error(e, "Error while parsing tool calls, please retry");
|
| 166 |
// error parsing the calls
|
| 167 |
yield {
|
| 168 |
type: MessageUpdateType.Status,
|
src/lib/server/tools/calculator.ts
CHANGED
|
@@ -6,7 +6,6 @@ const calculator: BackendTool = {
|
|
| 6 |
displayName: "Calculator",
|
| 7 |
description:
|
| 8 |
"A simple calculator, takes a string containing a mathematical expression and returns the answer. Only supports +, -, *, ** (power) and /, as well as parenthesis ().",
|
| 9 |
-
isOnByDefault: true,
|
| 10 |
parameterDefinitions: {
|
| 11 |
equation: {
|
| 12 |
description:
|
|
|
|
| 6 |
displayName: "Calculator",
|
| 7 |
description:
|
| 8 |
"A simple calculator, takes a string containing a mathematical expression and returns the answer. Only supports +, -, *, ** (power) and /, as well as parenthesis ().",
|
|
|
|
| 9 |
parameterDefinitions: {
|
| 10 |
equation: {
|
| 11 |
description:
|
src/lib/server/tools/documentParser.ts
CHANGED
|
@@ -9,7 +9,6 @@ const documentParser: BackendTool = {
|
|
| 9 |
name: "document_parser",
|
| 10 |
displayName: "Document Parser",
|
| 11 |
description: "Use this tool to parse any document and get its content in markdown format.",
|
| 12 |
-
isOnByDefault: true,
|
| 13 |
mimeTypes: ["application/*", "text/*"],
|
| 14 |
parameterDefinitions: {
|
| 15 |
fileMessageIndex: {
|
|
|
|
| 9 |
name: "document_parser",
|
| 10 |
displayName: "Document Parser",
|
| 11 |
description: "Use this tool to parse any document and get its content in markdown format.",
|
|
|
|
| 12 |
mimeTypes: ["application/*", "text/*"],
|
| 13 |
parameterDefinitions: {
|
| 14 |
fileMessageIndex: {
|
src/lib/server/tools/images/editing.ts
CHANGED
|
@@ -17,7 +17,6 @@ const imageEditing: BackendTool = {
|
|
| 17 |
name: "image_editing",
|
| 18 |
displayName: "Image Editing",
|
| 19 |
description: "Use this tool to edit an image from a prompt.",
|
| 20 |
-
isOnByDefault: true,
|
| 21 |
mimeTypes: ["image/*"],
|
| 22 |
parameterDefinitions: {
|
| 23 |
prompt: {
|
|
|
|
| 17 |
name: "image_editing",
|
| 18 |
displayName: "Image Editing",
|
| 19 |
description: "Use this tool to edit an image from a prompt.",
|
|
|
|
| 20 |
mimeTypes: ["image/*"],
|
| 21 |
parameterDefinitions: {
|
| 22 |
prompt: {
|
src/lib/server/tools/images/generation.ts
CHANGED
|
@@ -10,7 +10,6 @@ const imageGeneration: BackendTool = {
|
|
| 10 |
name: "image_generation",
|
| 11 |
displayName: "Image Generation",
|
| 12 |
description: "Use this tool to generate an image from a prompt.",
|
| 13 |
-
isOnByDefault: true,
|
| 14 |
parameterDefinitions: {
|
| 15 |
prompt: {
|
| 16 |
description:
|
|
|
|
| 10 |
name: "image_generation",
|
| 11 |
displayName: "Image Generation",
|
| 12 |
description: "Use this tool to generate an image from a prompt.",
|
|
|
|
| 13 |
parameterDefinitions: {
|
| 14 |
prompt: {
|
| 15 |
description:
|
src/lib/server/tools/web/search.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { runWebSearch } from "../../websearch/runWebSearch";
|
|
| 4 |
const websearch: BackendTool = {
|
| 5 |
name: "websearch",
|
| 6 |
displayName: "Web Search",
|
| 7 |
-
isOnByDefault: true,
|
| 8 |
description:
|
| 9 |
"Use this tool to search web pages for answers that will help answer the user's query. Only use this tool if you need specific resources from the internet.",
|
| 10 |
parameterDefinitions: {
|
|
|
|
| 4 |
const websearch: BackendTool = {
|
| 5 |
name: "websearch",
|
| 6 |
displayName: "Web Search",
|
|
|
|
| 7 |
description:
|
| 8 |
"Use this tool to search web pages for answers that will help answer the user's query. Only use this tool if you need specific resources from the internet.",
|
| 9 |
parameterDefinitions: {
|
src/lib/server/tools/web/url.ts
CHANGED
|
@@ -6,7 +6,6 @@ const fetchUrl: BackendTool = {
|
|
| 6 |
name: "fetch_url",
|
| 7 |
displayName: "URL Fetcher",
|
| 8 |
description: "A tool that can be used to fetch an URL and return the content directly.",
|
| 9 |
-
isOnByDefault: true,
|
| 10 |
parameterDefinitions: {
|
| 11 |
url: {
|
| 12 |
description: "The url that should be fetched.",
|
|
|
|
| 6 |
name: "fetch_url",
|
| 7 |
displayName: "URL Fetcher",
|
| 8 |
description: "A tool that can be used to fetch an URL and return the content directly.",
|
|
|
|
| 9 |
parameterDefinitions: {
|
| 10 |
url: {
|
| 11 |
description: "The url that should be fetched.",
|
src/lib/types/Template.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Message } from "./Message";
|
|
| 2 |
import type { Tool, ToolResult } from "./Tool";
|
| 3 |
|
| 4 |
export type ChatTemplateInput = {
|
| 5 |
-
messages: Pick<Message, "from" | "content">[];
|
| 6 |
preprompt?: string;
|
| 7 |
tools?: Tool[];
|
| 8 |
toolResults?: ToolResult[];
|
|
|
|
| 2 |
import type { Tool, ToolResult } from "./Tool";
|
| 3 |
|
| 4 |
export type ChatTemplateInput = {
|
| 5 |
+
messages: Pick<Message, "from" | "content" | "files">[];
|
| 6 |
preprompt?: string;
|
| 7 |
tools?: Tool[];
|
| 8 |
toolResults?: ToolResult[];
|