From f7ed4a47669a45d548d8bc1f1db7646168882055 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Tue, 10 Sep 2024 17:38:10 +0200
Subject: [PATCH 01/33] feat(models): add transferTo property on old models
(#1453)
* feat(models): add transferTo property on old models
used to transfer assistants to new models if specified
* make sure transferTo is an existing model
---
.../routines/02-update-assistants-models.ts | 33 +++++++++++++++----
src/lib/server/models.ts | 4 +++
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/lib/migrations/routines/02-update-assistants-models.ts b/src/lib/migrations/routines/02-update-assistants-models.ts
index f7f0c9dd454..35cef0c69d9 100644
--- a/src/lib/migrations/routines/02-update-assistants-models.ts
+++ b/src/lib/migrations/routines/02-update-assistants-models.ts
@@ -7,17 +7,36 @@ const updateAssistantsModels: Migration = {
name: "Update deprecated models in assistants with the default model",
up: async () => {
const models = (await import("$lib/server/models")).models;
-
+ const oldModels = (await import("$lib/server/models")).oldModels;
const { assistants } = collections;
- const modelIds = models.map((el) => el.id); // string[]
+ const modelIds = models.map((el) => el.id);
const defaultModelId = models[0].id;
- // Find all assistants whose modelId is not in modelIds, and update it to use defaultModelId
- await assistants.updateMany(
- { modelId: { $nin: modelIds } },
- { $set: { modelId: defaultModelId } }
- );
+ // Find all assistants whose modelId is not in modelIds, and update it
+ const bulkOps = await assistants
+ .find({ modelId: { $nin: modelIds } })
+ .map((assistant) => {
+ // has an old model
+ let newModelId = defaultModelId;
+
+ const oldModel = oldModels.find((m) => m.id === assistant.modelId);
+ if (oldModel && oldModel.transferTo && !!models.find((m) => m.id === oldModel.transferTo)) {
+ newModelId = oldModel.transferTo;
+ }
+
+ return {
+ updateOne: {
+ filter: { _id: assistant._id },
+ update: { $set: { modelId: newModelId } },
+ },
+ };
+ })
+ .toArray();
+
+ if (bulkOps.length > 0) {
+ await assistants.bulkWrite(bulkOps);
+ }
return true;
},
diff --git a/src/lib/server/models.ts b/src/lib/server/models.ts
index 937453228ca..cfa152bff37 100644
--- a/src/lib/server/models.ts
+++ b/src/lib/server/models.ts
@@ -320,6 +320,9 @@ export const models: ProcessedModel[] = await Promise.all(
modelsRaw.map((e) => processModel(e).then(addEndpoint))
);
+// super ugly but not sure how to make typescript happier
+const validModelIdSchema = z.enum(models.map((m) => m.id) as [string, ...string[]]);
+
export const defaultModel = models[0];
// Models that have been deprecated
@@ -330,6 +333,7 @@ export const oldModels = env.OLD_MODELS
id: z.string().optional(),
name: z.string().min(1),
displayName: z.string().min(1).optional(),
+ transferTo: validModelIdSchema.optional(),
})
)
.parse(JSON5.parse(env.OLD_MODELS))
From 438dfb9ddb37af968d02283cb2ed5968b2bde005 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Tue, 10 Sep 2024 17:39:48 +0200
Subject: [PATCH 02/33] chores(hchat): update cohere command R+ to latest
version (#1454)
---
chart/env/prod.yaml | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/chart/env/prod.yaml b/chart/env/prod.yaml
index 4b87d6decd0..575c5c220a7 100644
--- a/chart/env/prod.yaml
+++ b/chart/env/prod.yaml
@@ -69,10 +69,10 @@ envVars:
]
},
{
- "name" : "CohereForAI/c4ai-command-r-plus",
+ "name" : "CohereForAI/c4ai-command-r-plus-08-2024",
"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"},
- "description": "Cohere's largest language model, optimized for conversational interaction and tool use.",
- "modelUrl": "https://huggingface.co/CohereForAI/c4ai-command-r-plus",
+ "description": "Cohere's largest language model, optimized for conversational interaction and tool use. Now with the 2024 update!",
+ "modelUrl": "https://huggingface.co/CohereForAI/c4ai-command-r-plus-08-2024",
"websiteUrl": "https://docs.cohere.com/docs/command-r-plus",
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
"tools": true,
@@ -267,7 +267,8 @@ envVars:
{ "name": "codellama/CodeLlama-70b-Instruct-hf" },
{ "name": "openchat/openchat-3.5-0106" },
{ "name": "meta-llama/Meta-Llama-3-70B-Instruct"},
- { "name": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8"}
+ { "name": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8"},
+ { "name": "CohereForAI/c4ai-command-r-plus", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"}
]
PUBLIC_ORIGIN: "https://huggingface.co"
PUBLIC_SHARE_PREFIX: "https://hf.co/chat"
From 5420c270a7f2e337be2ea35cf4eb28f65dc7c4a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Victor=20Mu=C5=A1tar?=
Date: Tue, 10 Sep 2024 22:56:13 +0200
Subject: [PATCH 03/33] Update prod.yaml (#1460)
---
chart/env/prod.yaml | 29 +----------------------------
1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/chart/env/prod.yaml b/chart/env/prod.yaml
index 575c5c220a7..c49c4f157e1 100644
--- a/chart/env/prod.yaml
+++ b/chart/env/prod.yaml
@@ -154,34 +154,6 @@ envVars:
"stop": ["<|im_end|>"]
}
},
- {
- "name": "01-ai/Yi-1.5-34B-Chat",
- "tokenizer": "01-ai/Yi-1.5-34B-Chat",
- "description" : "Strong performance in reasoning while maintaining excellent capabilities in language understanding.",
- "logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/01-ai-logo.png",
- "modelUrl": "https://huggingface.co/01-ai/Yi-1.5-34B-Chat",
- "websiteUrl": "https://www.01.ai",
- "preprompt": "",
- "parameters": {
- "stop": ["<|im_end|>"],
- "temperature": 0.3,
- "max_new_tokens": 1024,
- "truncate": 1000,
- "top_p": 0.8,
- },
- "promptExamples": [
- {
- "title": "我的名字用中文怎么写?",
- "prompt": "请扮演一个起名大师,我将会给你一个我的英文名字,教我如何用中文写我的名字。"
- }, {
- "title": "写一首诗",
- "prompt": "请写一首讲 AI 的诗"
- }, {
- "title": "工作汇报",
- "prompt": "写一份工作汇报"
- }
- ]
- },
{
"name": "mistralai/Mistral-7B-Instruct-v0.3",
"displayName": "mistralai/Mistral-7B-Instruct-v0.3",
@@ -269,6 +241,7 @@ envVars:
{ "name": "meta-llama/Meta-Llama-3-70B-Instruct"},
{ "name": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8"},
{ "name": "CohereForAI/c4ai-command-r-plus", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"}
+ { "name": "01-ai/Yi-1.5-34B-Chat", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"}
]
PUBLIC_ORIGIN: "https://huggingface.co"
PUBLIC_SHARE_PREFIX: "https://hf.co/chat"
From 208f7a77181f32a4b2547bcf42ddb0203b21e4ac Mon Sep 17 00:00:00 2001
From: Victor Mustar
Date: Tue, 10 Sep 2024 23:04:39 +0200
Subject: [PATCH 04/33] typo
---
chart/env/prod.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/chart/env/prod.yaml b/chart/env/prod.yaml
index c49c4f157e1..d9ca6b5edd4 100644
--- a/chart/env/prod.yaml
+++ b/chart/env/prod.yaml
@@ -240,7 +240,7 @@ envVars:
{ "name": "openchat/openchat-3.5-0106" },
{ "name": "meta-llama/Meta-Llama-3-70B-Instruct"},
{ "name": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8"},
- { "name": "CohereForAI/c4ai-command-r-plus", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"}
+ { "name": "CohereForAI/c4ai-command-r-plus", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"},
{ "name": "01-ai/Yi-1.5-34B-Chat", "transferTo": "CohereForAI/c4ai-command-r-plus-08-2024"}
]
PUBLIC_ORIGIN: "https://huggingface.co"
From 111fb669168aa6cf6122032e072502b530a369e9 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Wed, 11 Sep 2024 14:02:47 +0000
Subject: [PATCH 05/33] feat(tools): show tool name creator in suggestion for
assistants
---
src/lib/components/AssistantToolPicker.svelte | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/lib/components/AssistantToolPicker.svelte b/src/lib/components/AssistantToolPicker.svelte
index c7909ef32f3..2cf6011d4cf 100644
--- a/src/lib/components/AssistantToolPicker.svelte
+++ b/src/lib/components/AssistantToolPicker.svelte
@@ -116,6 +116,9 @@
class="w-full cursor-pointer px-3 py-2 text-left hover:bg-blue-500 hover:text-white"
>
{suggestion.displayName}
+ {#if suggestion.createdByName}
+ by {suggestion.createdByName}
+ {/if}
{/each}
From 09b703876140c27f4f5ffecc6bf6f03f414c2d7c Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Thu, 12 Sep 2024 00:14:45 +0200
Subject: [PATCH 06/33] feat(conv): let user switch models on conversations
with deprecated models (#1462)
* feat(conv): let user switch models on conversations with deprecated models
* lint
* fix checks
---
src/lib/components/chat/ChatWindow.svelte | 8 +--
src/lib/components/chat/ModelSwitch.svelte | 60 ++++++++++++++++++++++
src/lib/server/models.ts | 2 +-
src/routes/conversation/[id]/+server.ts | 13 ++---
4 files changed, 73 insertions(+), 10 deletions(-)
create mode 100644 src/lib/components/chat/ModelSwitch.svelte
diff --git a/src/lib/components/chat/ChatWindow.svelte b/src/lib/components/chat/ChatWindow.svelte
index 3abbed81b9a..7ce3ef950b1 100644
--- a/src/lib/components/chat/ChatWindow.svelte
+++ b/src/lib/components/chat/ChatWindow.svelte
@@ -35,6 +35,7 @@
import UploadedFile from "./UploadedFile.svelte";
import { useSettingsStore } from "$lib/stores/settings";
import type { ToolFront } from "$lib/types/Tool";
+ import ModelSwitch from "./ModelSwitch.svelte";
export let messages: Message[] = [];
export let loading = false;
@@ -279,6 +280,9 @@
on:vote
on:continue
/>
+ {#if isReadOnly}
+
+ {/if}
{:else if pending}
{:else}
{
diff --git a/src/lib/components/chat/ModelSwitch.svelte b/src/lib/components/chat/ModelSwitch.svelte
new file mode 100644
index 00000000000..ba1153ed7ce
--- /dev/null
+++ b/src/lib/components/chat/ModelSwitch.svelte
@@ -0,0 +1,60 @@
+
+
+
+
+ This model is no longer available. Switch to a new one to continue this conversation:
+
+
+
+
+
+
diff --git a/src/lib/server/models.ts b/src/lib/server/models.ts
index cfa152bff37..eda1139f829 100644
--- a/src/lib/server/models.ts
+++ b/src/lib/server/models.ts
@@ -321,7 +321,7 @@ export const models: ProcessedModel[] = await Promise.all(
);
// super ugly but not sure how to make typescript happier
-const validModelIdSchema = z.enum(models.map((m) => m.id) as [string, ...string[]]);
+export const validModelIdSchema = z.enum(models.map((m) => m.id) as [string, ...string[]]);
export const defaultModel = models[0];
diff --git a/src/routes/conversation/[id]/+server.ts b/src/routes/conversation/[id]/+server.ts
index 822c34100d9..50fe126a468 100644
--- a/src/routes/conversation/[id]/+server.ts
+++ b/src/routes/conversation/[id]/+server.ts
@@ -2,7 +2,7 @@ import { env } from "$env/dynamic/private";
import { startOfHour } from "date-fns";
import { authCondition, requiresUser } from "$lib/server/auth";
import { collections } from "$lib/server/database";
-import { models } from "$lib/server/models";
+import { models, validModelIdSchema } from "$lib/server/models";
import { ERROR_MESSAGES } from "$lib/stores/errors";
import type { Message } from "$lib/types/Message";
import { error } from "@sveltejs/kit";
@@ -513,8 +513,11 @@ export async function DELETE({ locals, params }) {
}
export async function PATCH({ request, locals, params }) {
- const { title } = z
- .object({ title: z.string().trim().min(1).max(100) })
+ const values = z
+ .object({
+ title: z.string().trim().min(1).max(100).optional(),
+ model: validModelIdSchema.optional(),
+ })
.parse(await request.json());
const convId = new ObjectId(params.id);
@@ -533,9 +536,7 @@ export async function PATCH({ request, locals, params }) {
_id: convId,
},
{
- $set: {
- title,
- },
+ $set: values,
}
);
From 423902cc0c2776e9c8f7b6e334c82126388fa0f4 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Thu, 12 Sep 2024 08:56:21 +0000
Subject: [PATCH 07/33] fix(tools): dropzone properly support */* mimetype
---
src/lib/components/chat/FileDropzone.svelte | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/lib/components/chat/FileDropzone.svelte b/src/lib/components/chat/FileDropzone.svelte
index 263ee032d20..932a283eed7 100644
--- a/src/lib/components/chat/FileDropzone.svelte
+++ b/src/lib/components/chat/FileDropzone.svelte
@@ -26,7 +26,10 @@
!mimeTypes.some((mimeType: string) => {
const [type, subtype] = mimeType.split("/");
const [fileType, fileSubtype] = file.type.split("/");
- return type === fileType && (subtype === "*" || fileSubtype === subtype);
+ return (
+ (type === "*" || type === fileType) &&
+ (subtype === "*" || subtype === fileSubtype)
+ );
})
) {
setErrorMsg(`Some file type not supported. Only allowed: ${mimeTypes.join(", ")}`);
From 0bd9dd31643cfbd4adfd68dd9bd46f8ed36a55cd Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Fri, 13 Sep 2024 09:27:38 +0200
Subject: [PATCH 08/33] fix(assistants): remove websearch from assistant tool
options, add websearch in backend logic (#1465)
closes #1464
---
src/lib/server/textGeneration/tools.ts | 9 +++++++--
src/routes/api/tools/search/+server.ts | 1 +
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/lib/server/textGeneration/tools.ts b/src/lib/server/textGeneration/tools.ts
index 132bd87b8eb..52c2e450df2 100644
--- a/src/lib/server/textGeneration/tools.ts
+++ b/src/lib/server/textGeneration/tools.ts
@@ -32,9 +32,14 @@ export async function getTools(
if (assistant) {
if (assistant?.tools?.length) {
preferences = assistant.tools;
- } else if (assistantHasWebSearch(assistant)) {
- return [directlyAnswer, websearch];
+
+ if (assistantHasWebSearch(assistant)) {
+ preferences.push(websearch._id.toString());
+ }
} else {
+ if (assistantHasWebSearch(assistant)) {
+ return [websearch, directlyAnswer];
+ }
return [directlyAnswer];
}
}
diff --git a/src/routes/api/tools/search/+server.ts b/src/routes/api/tools/search/+server.ts
index 6a2c9ca3024..3a61c0593e3 100644
--- a/src/routes/api/tools/search/+server.ts
+++ b/src/routes/api/tools/search/+server.ts
@@ -33,6 +33,7 @@ export async function GET({ url, locals }) {
const matchingConfigTools = toolFromConfigs
.filter((tool) => !tool?.isHidden)
+ .filter((tool) => tool.name !== "websearch") // filter out websearch tool from config tools since its added separately
.filter((tool) => {
if (queryTokens) {
return generateSearchTokens(tool.displayName).some((token) =>
From b85e6e3a34911a5ddac87db4aa650119eeede8f1 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Fri, 13 Sep 2024 09:40:11 +0200
Subject: [PATCH 09/33] fix(tools): tool call name must be a valid python
variable name (#1466)
---
src/lib/server/tools/index.ts | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/lib/server/tools/index.ts b/src/lib/server/tools/index.ts
index 3454b974e74..2cb06903586 100644
--- a/src/lib/server/tools/index.ts
+++ b/src/lib/server/tools/index.ts
@@ -69,7 +69,11 @@ const toolInputSchema = toolInputBaseSchema.and(
export const editableToolSchema = z
.object({
- name: z.string().min(1).max(40),
+ name: z
+ .string()
+ .regex(/^[a-zA-Z_][a-zA-Z0-9_]*$/) // only allow letters, numbers, and underscores, and start with a letter or underscore
+ .min(1)
+ .max(40),
// only allow huggingface spaces either through namespace or direct URLs
baseUrl: z.union([
z.string().regex(/^[^/]+\/[^/]+$/),
From 0ddf2311af5c5697bdafd6d95f8b065a96c47675 Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Fri, 13 Sep 2024 10:08:44 +0200
Subject: [PATCH 10/33] fix(endpoints): make bedrock import optional (#1468)
---
src/lib/server/endpoints/aws/endpointBedrock.ts | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/lib/server/endpoints/aws/endpointBedrock.ts b/src/lib/server/endpoints/aws/endpointBedrock.ts
index d98fc074b82..826379cdc7f 100644
--- a/src/lib/server/endpoints/aws/endpointBedrock.ts
+++ b/src/lib/server/endpoints/aws/endpointBedrock.ts
@@ -1,10 +1,6 @@
import { z } from "zod";
import type { Endpoint } from "../endpoints";
import type { TextGenerationStreamOutput } from "@huggingface/inference";
-import {
- BedrockRuntimeClient,
- InvokeModelWithResponseStreamCommand,
-} from "@aws-sdk/client-bedrock-runtime";
import { createImageProcessorOptionsValidator, makeImageProcessor } from "../images";
import type { EndpointMessage } from "../endpoints";
import type { MessageFile } from "$lib/types/Message";
@@ -40,6 +36,16 @@ export async function endpointBedrock(
): Promise {
const { region, model, anthropicVersion, multimodal } =
endpointBedrockParametersSchema.parse(input);
+
+ let BedrockRuntimeClient, InvokeModelWithResponseStreamCommand;
+ try {
+ ({ BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } = await import(
+ "@aws-sdk/client-bedrock-runtime"
+ ));
+ } catch (error) {
+ throw new Error("Failed to import @aws-sdk/client-bedrock-runtime. Make sure it's installed.");
+ }
+
const client = new BedrockRuntimeClient({
region,
});
From fceae3592c038b7ac2e2924d9e3cf14a10ae6880 Mon Sep 17 00:00:00 2001
From: Julien Chaumond
Date: Fri, 13 Sep 2024 13:21:01 +0200
Subject: [PATCH 11/33] pluralize (#1469)
---
src/routes/tools/+page.svelte | 6 +++++-
src/routes/tools/[toolId]/+page.svelte | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/routes/tools/+page.svelte b/src/routes/tools/+page.svelte
index 78bd8ee4095..a1c0823c85d 100644
--- a/src/routes/tools/+page.svelte
+++ b/src/routes/tools/+page.svelte
@@ -262,7 +262,11 @@
{tool.createdByName}
•
- {tool.useCount} runs
+ {#if tool.useCount === 1}
+ 1 run
+ {:else}
+ {tool.useCount} runs
+ {/if}
{:else}
diff --git a/src/routes/tools/[toolId]/+page.svelte b/src/routes/tools/[toolId]/+page.svelte
index 254b161c6a2..120f5889ed2 100644
--- a/src/routes/tools/[toolId]/+page.svelte
+++ b/src/routes/tools/[toolId]/+page.svelte
@@ -82,7 +82,11 @@
{data.tool?.createdByName}
•
- {data.tool.useCount} runs
+ {#if data.tool.useCount === 1}
+ 1 run
+ {:else}
+ {data.tool.useCount} runs
+ {/if}
{/if}
From ce8e8cc916d04c7021dcc0d00f43d7a5446a929c Mon Sep 17 00:00:00 2001
From: Nathan Sarrazin
Date: Fri, 13 Sep 2024 13:21:12 +0200
Subject: [PATCH 12/33] feat(tools): add thumbnail (#1470)
feat(tools): add thumbnail file
---
src/routes/+layout.svelte | 2 +-
src/routes/tools/+layout.svelte | 22 ++++++++++++++++++++++
src/routes/tools/+page.svelte | 16 ----------------
static/huggingchat/tools-thumbnail.png | Bin 0 -> 439594 bytes
4 files changed, 23 insertions(+), 17 deletions(-)
create mode 100644 static/huggingchat/tools-thumbnail.png
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 16e630ca959..17259c17e5f 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -158,7 +158,7 @@
- {#if !$page.url.pathname.includes("/assistant/") && $page.route.id !== "/assistants" && !$page.url.pathname.includes("/models/")}
+ {#if !$page.url.pathname.includes("/assistant/") && $page.route.id !== "/assistants" && !$page.url.pathname.includes("/models/") && !$page.url.pathname.includes("/tools")}
diff --git a/src/routes/tools/+layout.svelte b/src/routes/tools/+layout.svelte
index 4fa864ce7aa..55062c9b041 100644
--- a/src/routes/tools/+layout.svelte
+++ b/src/routes/tools/+layout.svelte
@@ -1 +1,23 @@
+
+
+
+ {#if isHuggingChat}
+ HuggingChat - Tools
+
+
+
+
+
+ {/if}
+
+
diff --git a/src/routes/tools/+page.svelte b/src/routes/tools/+page.svelte
index a1c0823c85d..87424e779c6 100644
--- a/src/routes/tools/+page.svelte
+++ b/src/routes/tools/+page.svelte
@@ -1,7 +1,6 @@
-
- {#if isHuggingChat}
- HuggingChat - Tools
-
-
-
-
-
- {/if}
-
-