Commit c7a9b5cc authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac: chat completion middleware

parent b62d2a9b
...@@ -294,14 +294,16 @@ def get_rag_context( ...@@ -294,14 +294,16 @@ def get_rag_context(
extracted_collections.extend(collection_names) extracted_collections.extend(collection_names)
context_string = "" contexts = []
citations = [] citations = []
for context in relevant_contexts: for context in relevant_contexts:
try: try:
if "documents" in context: if "documents" in context:
context_string += "\n\n".join( contexts.append(
[text for text in context["documents"][0] if text is not None] "\n\n".join(
[text for text in context["documents"][0] if text is not None]
)
) )
if "metadatas" in context: if "metadatas" in context:
...@@ -315,9 +317,7 @@ def get_rag_context( ...@@ -315,9 +317,7 @@ def get_rag_context(
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
context_string = context_string.strip() return contexts, citations
return context_string, citations
def get_model_path(model: str, update_model: bool = False): def get_model_path(model: str, update_model: bool = False):
......
This diff is collapsed.
...@@ -665,6 +665,7 @@ ...@@ -665,6 +665,7 @@
await tick(); await tick();
const [res, controller] = await generateChatCompletion(localStorage.token, { const [res, controller] = await generateChatCompletion(localStorage.token, {
stream: true,
model: model.id, model: model.id,
messages: messagesBody, messages: messagesBody,
options: { options: {
...@@ -682,8 +683,8 @@ ...@@ -682,8 +683,8 @@
keep_alive: $settings.keepAlive ?? undefined, keep_alive: $settings.keepAlive ?? undefined,
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined, tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
files: files.length > 0 ? files : undefined, files: files.length > 0 ? files : undefined,
citations: files.length > 0 ? true : undefined, chat_id: $chatId,
chat_id: $chatId id: responseMessageId
}); });
if (res && res.ok) { if (res && res.ok) {
...@@ -912,8 +913,8 @@ ...@@ -912,8 +913,8 @@
const [res, controller] = await generateOpenAIChatCompletion( const [res, controller] = await generateOpenAIChatCompletion(
localStorage.token, localStorage.token,
{ {
model: model.id,
stream: true, stream: true,
model: model.id,
stream_options: stream_options:
model.info?.meta?.capabilities?.usage ?? false model.info?.meta?.capabilities?.usage ?? false
? { ? {
...@@ -983,9 +984,8 @@ ...@@ -983,9 +984,8 @@
max_tokens: $settings?.params?.max_tokens ?? undefined, max_tokens: $settings?.params?.max_tokens ?? undefined,
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined, tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
files: files.length > 0 ? files : undefined, files: files.length > 0 ? files : undefined,
citations: files.length > 0 ? true : undefined, chat_id: $chatId,
id: responseMessageId
chat_id: $chatId
}, },
`${WEBUI_BASE_URL}/api` `${WEBUI_BASE_URL}/api`
); );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment