增加模型选择功能,支持不同 Agent 模型
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { abortAgentChat, forkAgentChat, streamAgentChat } from "@/lib/chatStream";
|
||||
import type { StreamEvent } from "@/lib/chatStream";
|
||||
import type { AgentModel, StreamEvent } from "@/lib/chatStream";
|
||||
import type {
|
||||
AgentArtifact,
|
||||
BranchGroup,
|
||||
@@ -37,6 +37,7 @@ type UseAgentChatSessionOptions = {
|
||||
},
|
||||
) => void;
|
||||
onBeforeSend?: () => void;
|
||||
getModel?: () => AgentModel;
|
||||
};
|
||||
|
||||
type PromptRunOptions = {
|
||||
@@ -137,6 +138,7 @@ const messagesEqual = (left: Message[], right: Message[]) =>
|
||||
export const useAgentChatSession = ({
|
||||
onToolCall,
|
||||
onBeforeSend,
|
||||
getModel,
|
||||
}: UseAgentChatSessionOptions) => {
|
||||
const storageSessionIdRef = useRef<string | undefined>(undefined);
|
||||
const hydrationCompletedRef = useRef(false);
|
||||
@@ -317,6 +319,7 @@ export const useAgentChatSession = ({
|
||||
await streamAgentChat({
|
||||
message: prompt,
|
||||
sessionId: sessionIdOverride ?? sessionIdRef.current,
|
||||
model: getModel?.(),
|
||||
signal: controller.signal,
|
||||
onEvent: (event) => {
|
||||
if ("sessionId" in event && event.sessionId && event.sessionId !== sessionIdRef.current) {
|
||||
@@ -448,7 +451,7 @@ export const useAgentChatSession = ({
|
||||
setIsStreaming(false);
|
||||
}
|
||||
},
|
||||
[appendArtifact, isHydrating, isStreaming, messages, onBeforeSend, onToolCall],
|
||||
[appendArtifact, getModel, isHydrating, isStreaming, messages, onBeforeSend, onToolCall],
|
||||
);
|
||||
|
||||
const abort = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user