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