Forum Discussion

sureshnurish's avatar
sureshnurish
Copper Contributor
Apr 09, 2024

Migrating from OpenAI to Azure OpenAI (Javascript)

Hi, 

 

I've been using OpenAI with javascript for an app for a few months now without any issues. My use case involves using the function calling parameters to specify a schema for a specific JSON output. I've now migrated to using an Azure OpenAI Endpoint with the v1.0.0-beta.12 version of the javascript SDK, and I can't seem to figure out the correct way to specify my desired schema for my json output. I've tried using functions/function_calls, also tools/tool_calls. I also noticed that for some versions of the api it expects a parameter named responseFormat. All have not worked. Any help would be appreciated. 

 

Here is a snippet of my code using openAI: 

var raw = JSON.stringify({
model: 'gpt-4',

messages: [
{
role: 'system',
content: advanced_context,
},
{
role: 'user',
content: user_text,
},
],
functions: [
{
name: 'food_items',
parameters: schema,
},
],
function_call: {
name: 'food_items',
},
temperature: 0,
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow',
};
var response = await fetch(
'https://api.openai.com/v1/chat/completions',
requestOptions,
);
 
And this is with Azure OpenAI: 
const completion = await client.getChatCompletions(deploymentId, [
{
role: "system",
content: advanced_context
},
{
role: "user",
content: input
},
],
response_format={ "type": "json_object" },
temperature=0,
responseFormat= schema,
functions=[
{
"name": "food_items",
"parameters": schema,
}
],
functionCall={
"name": "food_items"
},
tools=[
{
"name": "food_items",
"parameters": schema,
}
],
toolChoice={
"name": "food_items"
},
);

 

No RepliesBe the first to reply

Resources