fix: pass chat_id to internal task calls for consistent function context (#20585)
Ensure chat_id is reliably passed to function pipelines/manifolds during internal task invocations (web search query generation, RAG query generation, image prompt generation). This allows stateful functions to maintain per-chat state without fragmentation, as they will now receive a consistent chat_id for all chat-scoped invocations including internal tasks. Backend changes: - Pass chat_id in generate_queries call for web search - Pass chat_id in generate_queries call for RAG/retrieval - Pass chat_id in generate_image_prompt call Frontend changes: - Add optional chat_id parameter to generateQueries API function - Add optional chat_id parameter to generateAutoCompletion API function Fixes #20563
This commit is contained in:
@@ -1255,6 +1255,7 @@ async def chat_web_search_handler(
|
||||
"messages": messages,
|
||||
"prompt": user_message,
|
||||
"type": "web_search",
|
||||
"chat_id": extra_params.get("__chat_id__"),
|
||||
},
|
||||
user,
|
||||
)
|
||||
@@ -1585,6 +1586,7 @@ async def chat_image_generation_handler(
|
||||
{
|
||||
"model": form_data["model"],
|
||||
"messages": form_data["messages"],
|
||||
"chat_id": metadata.get("chat_id"),
|
||||
},
|
||||
user,
|
||||
)
|
||||
@@ -1691,6 +1693,7 @@ async def chat_completion_files_handler(
|
||||
"model": body["model"],
|
||||
"messages": body["messages"],
|
||||
"type": "retrieval",
|
||||
"chat_id": body.get("metadata", {}).get("chat_id"),
|
||||
},
|
||||
user,
|
||||
)
|
||||
|
||||
@@ -864,7 +864,8 @@ export const generateQueries = async (
|
||||
model: string,
|
||||
messages: object[],
|
||||
prompt: string,
|
||||
type: string = 'web_search'
|
||||
type: string = 'web_search',
|
||||
chat_id?: string
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
@@ -879,7 +880,8 @@ export const generateQueries = async (
|
||||
model: model,
|
||||
messages: messages,
|
||||
prompt: prompt,
|
||||
type: type
|
||||
type: type,
|
||||
...(chat_id && { chat_id: chat_id })
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
@@ -933,7 +935,8 @@ export const generateAutoCompletion = async (
|
||||
model: string,
|
||||
prompt: string,
|
||||
messages?: object[],
|
||||
type: string = 'search query'
|
||||
type: string = 'search query',
|
||||
chat_id?: string
|
||||
) => {
|
||||
const controller = new AbortController();
|
||||
let error = null;
|
||||
@@ -951,7 +954,8 @@ export const generateAutoCompletion = async (
|
||||
prompt: prompt,
|
||||
...(messages && { messages: messages }),
|
||||
type: type,
|
||||
stream: false
|
||||
stream: false,
|
||||
...(chat_id && { chat_id: chat_id })
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
@@ -1675,7 +1679,7 @@ export interface ModelMeta {
|
||||
profile_image_url?: string;
|
||||
}
|
||||
|
||||
export interface ModelParams {}
|
||||
export interface ModelParams { }
|
||||
|
||||
export type GlobalModelConfig = ModelConfig[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user