awaitload({ envPath: "./.env", export: true, }); const model = newChatOpenAI({ configuration: { baseURL: "https://ark.cn-beijing.volces.com/api/v3", }, model: "deepseek-v3-250324", }); const zodSchema = z.object({ answer: z.string().describe("answer to the user's question"), source: z .string() .describe( "source used to answer the user's question, should be a website." ), });
const chain = RunnableSequence.from([ ChatPromptTemplate.fromTemplate( "Answer the users question as best as possible.\n{format_instructions}\n{question}" ), model, parser, ]);
await chain.invoke({ question: "What is the capital of France?", format_instructions: parser.getFormatInstructions(), });
1
{ answer: "The capital of France is Paris.", source: "<https://www.britannica.com/place/Paris>" }
const template = `Return a JSON object with a single key named "answer" that answers the following question: {question}. Do not wrap the JSON output in markdown blocks.`;
{} { answer: "" } { answer: "The" } { answer: "The microscope" } { answer: "The microscope was" } { answer: "The microscope was invented" } { answer: "The microscope was invented by" } { answer: "The microscope was invented by Hans" } { answer: "The microscope was invented by Hans Li" } { answer: "The microscope was invented by Hans Lippers" } { answer: "The microscope was invented by Hans Lippershey" } { answer: "The microscope was invented by Hans Lippershey," } { answer: "The microscope was invented by Hans Lippershey, Hans" } { answer: "The microscope was invented by Hans Lippershey, Hans Jans" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen," } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zach" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Jans" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen," } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galile" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei who" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei who improved" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei who improved the" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei who improved the design" } { answer: "The microscope was invented by Hans Lippershey, Hans Janssen, and Zacharias Janssen, with contributions from Galileo Galilei who improved the design." }