Skip to content

Commit 7652355

Browse files
committed
Merge branch 'main' into feature/assistants
2 parents 003cd30 + ee47ff3 commit 7652355

File tree

10 files changed

+130
-7
lines changed

10 files changed

+130
-7
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ PUBLIC_APP_DATA_SHARING=#set to 1 to enable options & text regarding data sharin
121121
PUBLIC_APP_DISCLAIMER=#set to 1 to show a disclaimer on login page
122122
LLM_SUMMERIZATION=true
123123

124+
EXPOSE_API=true
124125
# PUBLIC_APP_NAME=HuggingChat
125126
# PUBLIC_APP_ASSETS=huggingchat
126127
# PUBLIC_APP_COLOR=yellow

.env.template

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ MODELS=`[
6060
"max_new_tokens": 1024
6161
}
6262
},
63+
{
64+
"name" : "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
65+
"description" : "Nous Hermes 2 Mixtral 8x7B DPO is the new flagship Nous Research model trained over the Mixtral 8x7B MoE LLM.",
66+
"websiteUrl" : "https://nousresearch.com/",
67+
"chatPromptTemplate" : "<|im_start|>system\n{{#if @root.preprompt}}{{@root.preprompt}}<|im_end|>\n{{/if}}{{#each messages}}{{#ifUser}}<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n{{/ifUser}}{{#ifAssistant}}{{content}}<|im_end|>\n{{/ifAssistant}}{{/each}}",
68+
"promptExamples": [
69+
{
70+
"title": "Write an email from bullet list",
71+
"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)"
72+
}, {
73+
"title": "Code a snake game",
74+
"prompt": "Code a basic snake game in python, give explanations for each step."
75+
}, {
76+
"title": "Assist in a task",
77+
"prompt": "How do I make a delicious lemon cheesecake?"
78+
}
79+
],
80+
"parameters": {
81+
"temperature": 0.7,
82+
"top_p": 0.95,
83+
"repetition_penalty": 1,
84+
"top_k": 50,
85+
"truncate": 24576,
86+
"max_new_tokens": 2048,
87+
"stop": ["<|im_end|>"]
88+
}
89+
},
6390
{
6491
"name": "codellama/CodeLlama-34b-Instruct-hf",
6592
"displayName": "codellama/CodeLlama-34b-Instruct-hf",
@@ -226,4 +253,5 @@ PUBLIC_GOOGLE_ANALYTICS_ID=G-8Q63TH4CSL
226253
# ADDRESS_HEADER=X-Forwarded-For
227254
# XFF_DEPTH=2
228255

229-
ENABLE_ASSISTANTS=true
256+
ENABLE_ASSISTANTS=true
257+
EXPOSE_API=false

PROMPTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ System: {{preprompt}}\nUser:{{#each messages}}{{#ifUser}}{{content}}\nFalcon:{{/
4949
```env
5050
<s> {{#each messages}}{{#ifUser}}[INST]{{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}} {{content}}</s> {{/ifAssistant}}{{/each}}
5151
```
52+
53+
## ChatML
54+
55+
```env
56+
<|im_start|>system\n{{#if @root.preprompt}}{{@root.preprompt}}<|im_end|>\n{{/if}}{{#each messages}}{{#ifUser}}<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n{{/ifUser}}{{#ifAssistant}}{{content}}<|im_end|>\n{{/ifAssistant}}{{/each}}
57+
```

src/hooks.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { COOKIE_NAME, MESSAGES_BEFORE_LOGIN } from "$env/static/private";
1+
import { COOKIE_NAME, EXPOSE_API, MESSAGES_BEFORE_LOGIN } from "$env/static/private";
22
import type { Handle } from "@sveltejs/kit";
33
import {
44
PUBLIC_GOOGLE_ANALYTICS_ID,
@@ -13,6 +13,10 @@ import { sha256 } from "$lib/utils/sha256";
1313
import { addWeeks } from "date-fns";
1414

1515
export const handle: Handle = async ({ event, resolve }) => {
16+
if (event.url.pathname.startsWith(`${base}/api/`) && EXPOSE_API !== "true") {
17+
return new Response("API is disabled", { status: 403 });
18+
}
19+
1620
function errorResponse(status: number, message: string) {
1721
const sendJson =
1822
event.request.headers.get("accept")?.includes("application/json") ||

src/lib/server/generateFromDefaultEndpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function generateFromDefaultEndpoint({
2121
generated_text = generated_text.slice(0, -stop.length).trimEnd();
2222
}
2323
}
24+
tokenStream.return();
2425
return generated_text;
2526
}
2627
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { collections } from "$lib/server/database";
2+
import { authCondition } from "$lib/server/auth";
3+
import { z } from "zod";
4+
import { ObjectId } from "mongodb";
5+
6+
export async function GET({ locals, params }) {
7+
const id = z.string().parse(params.id);
8+
const convId = new ObjectId(id);
9+
10+
if (locals.user?._id || locals.sessionId) {
11+
const conv = await collections.conversations.findOne({
12+
_id: convId,
13+
...authCondition(locals),
14+
});
15+
16+
if (conv) {
17+
const res = {
18+
id: conv._id,
19+
title: conv.title,
20+
updatedAt: conv.updatedAt,
21+
modelId: conv.model,
22+
messages: conv.messages.map((message) => ({
23+
content: message.content,
24+
from: message.from,
25+
id: message.id,
26+
createdAt: message.createdAt,
27+
updatedAt: message.updatedAt,
28+
webSearch: message.webSearch,
29+
})),
30+
};
31+
return Response.json(res);
32+
} else {
33+
return Response.json({ message: "Conversation not found" }, { status: 404 });
34+
}
35+
} else {
36+
return Response.json({ message: "Must have session cookie" }, { status: 401 });
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { collections } from "$lib/server/database";
2+
import { authCondition } from "$lib/server/auth";
3+
import type { Conversation } from "$lib/types/Conversation";
4+
5+
export async function GET({ locals }) {
6+
if (locals.user?._id || locals.sessionId) {
7+
const convs = await collections.conversations
8+
.find({
9+
...authCondition(locals),
10+
})
11+
.project<Pick<Conversation, "_id" | "title" | "updatedAt" | "model">>({
12+
title: 1,
13+
updatedAt: 1,
14+
model: 1,
15+
})
16+
.sort({ updatedAt: -1 })
17+
.toArray();
18+
19+
const res = convs.map((conv) => ({
20+
id: conv._id,
21+
title: conv.title,
22+
updatedAt: conv.updatedAt,
23+
modelId: conv.model,
24+
}));
25+
26+
return Response.json(res);
27+
} else {
28+
return Response.json({ message: "Must have session cookie" }, { status: 401 });
29+
}
30+
}

src/routes/api/models/+server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { models } from "$lib/server/models";
2+
3+
export async function GET() {
4+
const res = models.map((model) => ({
5+
id: model.id,
6+
name: model.name,
7+
websiteUrl: model.websiteUrl,
8+
modelUrl: model.modelUrl,
9+
datasetName: model.datasetName,
10+
datasetUrl: model.datasetUrl,
11+
displayName: model.displayName,
12+
description: model.description,
13+
promptExamples: model.promptExamples,
14+
preprompt: model.preprompt,
15+
multimodal: model.multimodal,
16+
unlisted: model.unlisted,
17+
}));
18+
return Response.json(res);
19+
}

src/routes/conversation/[id]/+page.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,12 @@
111111
112112
files = [];
113113
114-
const responseId = randomUUID();
115114
const response = await fetch(`${base}/conversation/${$page.params.id}`, {
116115
method: "POST",
117116
headers: { "Content-Type": "application/json" },
118117
body: JSON.stringify({
119118
inputs: message,
120119
id: messageId,
121-
response_id: responseId,
122120
is_retry: isRetry,
123121
web_search: $webSearchParameters.useSearch,
124122
files: isRetry ? undefined : resizedImages,

src/routes/conversation/[id]/+server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export async function POST({ request, locals, params, getClientAddress }) {
9090

9191
const {
9292
inputs: newPrompt,
93-
response_id: responseId,
9493
id: messageId,
9594
is_retry,
9695
web_search: webSearch,
@@ -99,7 +98,6 @@ export async function POST({ request, locals, params, getClientAddress }) {
9998
.object({
10099
inputs: z.string().trim().min(1),
101100
id: z.optional(z.string().uuid()),
102-
response_id: z.optional(z.string().uuid()),
103101
is_retry: z.optional(z.boolean()),
104102
web_search: z.optional(z.boolean()),
105103
files: z.optional(z.array(z.string())),
@@ -268,7 +266,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
268266
content: output.token.text.trimStart(),
269267
webSearch: webSearchResults,
270268
updates: updates,
271-
id: (responseId as Message["id"]) || crypto.randomUUID(),
269+
id: crypto.randomUUID(),
272270
createdAt: new Date(),
273271
updatedAt: new Date(),
274272
},

0 commit comments

Comments
 (0)