feat: claude function call

This commit is contained in:
Hk-Gosuto 2024-08-11 09:55:13 +00:00
parent ad5d81d76a
commit 8583b536cf
3 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import axiosMod, { AxiosStatic } from "axios"; import axiosMod, { AxiosStatic } from "axios";
import { WebPDFLoader } from "langchain/document_loaders/web/pdf"; import { WebPDFLoader } from "@langchain/community/document_loaders/web/pdf";
import { MemoryVectorStore } from "langchain/vectorstores/memory"; import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { Tool } from "@langchain/core/tools"; import { Tool } from "@langchain/core/tools";
import { import {

View File

@ -8,6 +8,7 @@ import {
AgentExecutor, AgentExecutor,
AgentStep, AgentStep,
createToolCallingAgent, createToolCallingAgent,
createReactAgent,
} from "langchain/agents"; } from "langchain/agents";
import { ACCESS_CODE_PREFIX, ServiceProvider } from "@/app/constant"; import { ACCESS_CODE_PREFIX, ServiceProvider } from "@/app/constant";
@ -414,10 +415,10 @@ export class AgentApi {
]); ]);
const lastMessageContent = reqBody.messages.slice(-1)[0].content; const lastMessageContent = reqBody.messages.slice(-1)[0].content;
const lastHumanMessage = // const lastHumanMessage =
typeof lastMessageContent === "string" // typeof lastMessageContent === "string"
? new HumanMessage(lastMessageContent) // ? new HumanMessage(lastMessageContent)
: new HumanMessage({ content: lastMessageContent }); // : new HumanMessage({ content: lastMessageContent });
const agent = createToolCallingAgent({ const agent = createToolCallingAgent({
llm, llm,
tools, tools,
@ -432,7 +433,7 @@ export class AgentApi {
{ {
input: lastMessageContent, input: lastMessageContent,
chat_history: pastMessages, chat_history: pastMessages,
// signal: this.controller.signal, signal: this.controller.signal,
}, },
{ callbacks: [handler] }, { callbacks: [handler] },
) )

View File

@ -6,6 +6,8 @@ console.log("[Next] build mode", mode);
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export"; const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
console.log("[Next] build with chunk: ", !disableChunk); console.log("[Next] build with chunk: ", !disableChunk);
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = true;
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
webpack(config) { webpack(config) {