Add langsmith:nostream to avoid emitting an empty AI message

This commit is contained in:
Tat Dat Duong
2025-03-03 14:50:43 +01:00
parent ca8bc7d107
commit cd410259ff

View File

@@ -6,7 +6,7 @@ import { stockbrokerGraph } from "./stockbroker";
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
async function router( async function router(
state: GenerativeUIState, state: GenerativeUIState
): Promise<Partial<GenerativeUIState>> { ): Promise<Partial<GenerativeUIState>> {
const routerDescription = `The route to take based on the user's input. const routerDescription = `The route to take based on the user's input.
- stockbroker: can fetch the price of a ticker, purchase/sell a ticker, or get the user's portfolio - stockbroker: can fetch the price of a ticker, purchase/sell a ticker, or get the user's portfolio
@@ -27,7 +27,9 @@ async function router(
const llm = new ChatGoogleGenerativeAI({ const llm = new ChatGoogleGenerativeAI({
model: "gemini-2.0-flash", model: "gemini-2.0-flash",
temperature: 0, temperature: 0,
}).bindTools([routerTool], { tool_choice: "router" }); })
.bindTools([routerTool], { tool_choice: "router" })
.withConfig({ tags: ["langsmith:nostream"] });
const prompt = `You're a highly helpful AI assistant, tasked with routing the user's query to the appropriate tool. const prompt = `You're a highly helpful AI assistant, tasked with routing the user's query to the appropriate tool.
You should analyze the user's input, and choose the appropriate tool to use.`; You should analyze the user's input, and choose the appropriate tool to use.`;
@@ -58,7 +60,7 @@ You should analyze the user's input, and choose the appropriate tool to use.`;
} }
function handleRoute( function handleRoute(
state: GenerativeUIState, state: GenerativeUIState
): "stockbroker" | "weather" | "generalInput" { ): "stockbroker" | "weather" | "generalInput" {
return state.next; return state.next;
} }