feat: claude function call
This commit is contained in:
parent
8583b536cf
commit
0a643dc71d
|
@ -105,7 +105,6 @@ export class AgentApi {
|
||||||
var controller = this.controller;
|
var controller = this.controller;
|
||||||
return BaseCallbackHandler.fromMethods({
|
return BaseCallbackHandler.fromMethods({
|
||||||
async handleLLMNewToken(token: string) {
|
async handleLLMNewToken(token: string) {
|
||||||
console.log(token);
|
|
||||||
if (token && !controller.signal.aborted) {
|
if (token && !controller.signal.aborted) {
|
||||||
var response = new ResponseBody();
|
var response = new ResponseBody();
|
||||||
response.message = token;
|
response.message = token;
|
||||||
|
@ -276,6 +275,15 @@ export class AgentApi {
|
||||||
throw new Error("Unsupported model providers");
|
throw new Error("Unsupported model providers");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAuthHeader(reqBody: RequestBody): string {
|
||||||
|
const serverConfig = getServerSideConfig();
|
||||||
|
return reqBody.isAzure || serverConfig.isAzure
|
||||||
|
? "api-key"
|
||||||
|
: reqBody.provider === ServiceProvider.Anthropic
|
||||||
|
? "x-api-key"
|
||||||
|
: "Authorization";
|
||||||
|
}
|
||||||
|
|
||||||
async getApiHandler(
|
async getApiHandler(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
reqBody: RequestBody,
|
reqBody: RequestBody,
|
||||||
|
@ -288,7 +296,7 @@ export class AgentApi {
|
||||||
// const reqBody: RequestBody = await req.json();
|
// const reqBody: RequestBody = await req.json();
|
||||||
// ui set azure model provider
|
// ui set azure model provider
|
||||||
const isAzure = reqBody.isAzure;
|
const isAzure = reqBody.isAzure;
|
||||||
const authHeaderName = isAzure ? "api-key" : "Authorization";
|
const authHeaderName = this.getAuthHeader(reqBody);
|
||||||
const authToken = req.headers.get(authHeaderName) ?? "";
|
const authToken = req.headers.get(authHeaderName) ?? "";
|
||||||
const token = authToken.trim().replaceAll("Bearer ", "").trim();
|
const token = authToken.trim().replaceAll("Bearer ", "").trim();
|
||||||
|
|
||||||
|
@ -427,6 +435,7 @@ export class AgentApi {
|
||||||
const agentExecutor = new AgentExecutor({
|
const agentExecutor = new AgentExecutor({
|
||||||
agent,
|
agent,
|
||||||
tools,
|
tools,
|
||||||
|
maxIterations: reqBody.maxIterations,
|
||||||
});
|
});
|
||||||
await agentExecutor
|
await agentExecutor
|
||||||
.invoke(
|
.invoke(
|
||||||
|
|
|
@ -227,7 +227,7 @@ export class ClientApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHeaders(ignoreHeaders?: boolean, isFunctionCall?: boolean) {
|
export function getHeaders(ignoreHeaders?: boolean) {
|
||||||
const accessStore = useAccessStore.getState();
|
const accessStore = useAccessStore.getState();
|
||||||
const chatStore = useChatStore.getState();
|
const chatStore = useChatStore.getState();
|
||||||
let headers: Record<string, string> = {};
|
let headers: Record<string, string> = {};
|
||||||
|
@ -285,7 +285,6 @@ export function getHeaders(ignoreHeaders?: boolean, isFunctionCall?: boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAuthHeader(): string {
|
function getAuthHeader(): string {
|
||||||
if (isFunctionCall) return "Authorization";
|
|
||||||
return isAzure ? "api-key" : isAnthropic ? "x-api-key" : "Authorization";
|
return isAzure ? "api-key" : isAnthropic ? "x-api-key" : "Authorization";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ export class ClaudeApi implements LLMApi {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(requestPayload),
|
body: JSON.stringify(requestPayload),
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
headers: getHeaders(false, true),
|
headers: getHeaders(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// make a fetch request
|
// make a fetch request
|
||||||
|
|
Loading…
Reference in New Issue