I was changing the function calls to tools ( im getting error ) #1497
Unanswered
thareekanvarm
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
I was planning to change the vercel ai function call to tools . but ai perfectly working on function calls ,when im changing to tools its showing this error . but the ai giving reply this is ur please check .i have a buckend call on that function.
error : 'Authentication Failed: The token is missing in request header'
export const aiConfig = { apiKey: process.env.AZURE_OPENAI_API_KEY, baseURL:
${endpoint}/openai/deployments/${process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME}`,defaultQuery: { "api-version": process.env.AZURE_OPENAI_API_VERSION },
defaultHeaders: { "api-key": process.env.AZURE_OPENAI_API_KEY },
};
const openai = new OpenAI(aiConfig);
export const config = {
runtime: "edge",
};
export const dynamic = "force-dynamic";
export default async function POST(req) {
const { messages }: { messages: any[] } = await req.json();
// Set the number of messages to send const maxNumMessagesToSend = 20;
// Get the last
numMessagesToSend
messages const lastMessages = messages.slice(-maxNumMessagesToSend);console.log(messages);
const response = await openai.chat.completions.create({
model: process.env.AZURE_OPENAI_API_MODEL_NAME,
stream: true,
//@ts-ignore
messages: [...messages],
temperature: 0.3,
n: 1,
// max_tokens: 1000,
// function_call: "auto",
// functions,
tools: functions,
tool_choice: "auto",
});
const data = new StreamData();
const stream = OpenAIStream(response, {
experimental_onToolCall: async (
call: ToolCallPayload,
appendToolCallMessage
) => {
for (const toolCall of call.tools) {
// Note: this is a very simple example of a tool call handler
// that only supports a single tool call function.
console.log(toolCall);
});
data.append({
text: "Hello, how are you?",
});
return new StreamingTextResponse(stream);
}`
Beta Was this translation helpful? Give feedback.
All reactions