chat compare: send use_adapter
This commit is contained in:
parent
b1258bed0d
commit
2ffdd59925
2 changed files with 21 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import type { ChatModelAdapter } from "@assistant-ui/react";
|
||||
import { streamChatCompletions } from "./chat-api";
|
||||
import { db } from "../db";
|
||||
import { useChatRuntimeStore } from "../stores/chat-runtime-store";
|
||||
import {
|
||||
hasClosedThinkTag,
|
||||
|
|
@ -81,6 +82,23 @@ function findLatestUserImageBase64(messages: RunMessages): string | undefined {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
async function resolveUseAdapter(
|
||||
threadId: string | undefined,
|
||||
): Promise<boolean | undefined> {
|
||||
if (!threadId) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const thread = await db.threads.get(threadId);
|
||||
if (!thread?.pairId) {
|
||||
return undefined;
|
||||
}
|
||||
return thread.modelType === "lora";
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function createOpenAIStreamAdapter(): ChatModelAdapter {
|
||||
return {
|
||||
async *run({ messages, abortSignal, unstable_threadId }) {
|
||||
|
|
@ -104,6 +122,7 @@ export function createOpenAIStreamAdapter(): ChatModelAdapter {
|
|||
});
|
||||
}
|
||||
const imageBase64 = findLatestUserImageBase64(messages);
|
||||
const useAdapter = await resolveUseAdapter(unstable_threadId);
|
||||
|
||||
const threadKey = unstable_threadId || "__default";
|
||||
let waitingFirstChunk = true;
|
||||
|
|
@ -124,6 +143,7 @@ export function createOpenAIStreamAdapter(): ChatModelAdapter {
|
|||
top_k: params.topK,
|
||||
repetition_penalty: params.repetitionPenalty,
|
||||
image_base64: imageBase64,
|
||||
...(useAdapter === undefined ? {} : { use_adapter: useAdapter }),
|
||||
},
|
||||
abortSignal,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export interface OpenAIChatCompletionsRequest {
|
|||
top_k: number;
|
||||
repetition_penalty: number;
|
||||
image_base64?: string;
|
||||
use_adapter?: boolean | string | null;
|
||||
}
|
||||
|
||||
export interface OpenAIChatDelta {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue