Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to send user message as part of request body in assistant … #1322

Merged
merged 14 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ EXPOSE_API=true

ENABLE_ASSISTANTS=false #set to true to enable assistants feature
ENABLE_ASSISTANTS_RAG=false # /!\ This will let users specify arbitrary URLs that the server will then request. Make sure you have the proper firewall rules in place.
ENABLE_ASSISTANTS_POST=false #set to true to have assistants send query message in request body
REQUIRE_FEATURED_ASSISTANTS=false
ENABLE_LOCAL_FETCH=false #set to true to disable the blocklist for local fetches. Only enable this if you have the proper firewall rules to prevent SSRF attacks and understand the implications.
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
Expand All @@ -162,4 +163,4 @@ ALLOW_INSECURE_COOKIES=false # recommended to keep this to false but set to true
METRICS_ENABLED=false
METRICS_PORT=5565
LOG_LEVEL=info
BODY_SIZE_LIMIT=15728640
BODY_SIZE_LIMIT=15728640
19 changes: 15 additions & 4 deletions src/lib/server/textGeneration/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { collections } from "$lib/server/database";
import type { Assistant } from "$lib/types/Assistant";
import type { ObjectId } from "mongodb";

export async function processPreprompt(preprompt: string) {
export async function processPreprompt(preprompt: string, user_message: string | undefined) {
const urlRegex = /{{\s?url=(.*?)\s?}}/g;

for (const match of preprompt.matchAll(urlRegex)) {
Expand All @@ -13,8 +13,19 @@ export async function processPreprompt(preprompt: string) {
if ((await isURLLocal(url)) && env.ENABLE_LOCAL_FETCH !== "true") {
throw new Error("URL couldn't be fetched, it resolved to a local address.");
}

const res = await fetch(url.href);

let res;
if (env.ENABLE_ASSISTANTS_POST === "true") {
res = await fetch(url.href, {
method: 'POST',
body: user_message,
headers: {
'Content-Type': 'text/plain'
}
});
} else {
res = await fetch(url.href);
}

if (!res.ok) {
throw new Error("URL couldn't be fetched, error " + res.status);
Expand Down Expand Up @@ -50,4 +61,4 @@ export function assistantHasWebSearch(assistant?: Pick<Assistant, "rag"> | null)

export function assistantHasDynamicPrompt(assistant?: Pick<Assistant, "dynamicPrompt">) {
return env.ENABLE_ASSISTANTS_RAG === "true" && Boolean(assistant?.dynamicPrompt);
}
}
4 changes: 2 additions & 2 deletions src/lib/server/textGeneration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function* textGenerationWithoutTitle(

let preprompt = conv.preprompt;
if (assistantHasDynamicPrompt(assistant) && preprompt) {
preprompt = await processPreprompt(preprompt);
preprompt = await processPreprompt(preprompt, messages.at(-1)?.content);
if (messages[0].from === "system") messages[0].content = preprompt;
}

Expand All @@ -70,4 +70,4 @@ async function* textGenerationWithoutTitle(

const processedMessages = await preprocessMessages(messages, webSearchResult, convId);
yield* generate({ ...ctx, messages: processedMessages }, toolResults, preprompt);
}
}
Loading