-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenAI] Prepare beta.5 release (#26941)
- Loading branch information
1 parent
d8b0c68
commit 703cd1f
Showing
19 changed files
with
471 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
sdk/openai/openai/samples/v1-beta/javascript/bringYourOwnData.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Demonstrates how to use Azure's Bring Your Own Data with Azure OpenAI Chat Completions. | ||
* | ||
* @summary chat completions with your own data. | ||
*/ | ||
|
||
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai"); | ||
|
||
// Load the .env file if it exists | ||
require("dotenv").config(); | ||
|
||
// You will need to set these environment variables or edit the following values | ||
// The endpoint you will use to access your Azure OpenAI instance | ||
const endpoint = process.env["ENDPOINT"] || "<endpoint>"; | ||
// Your Azure OpenAI API key | ||
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>"; | ||
// Your Azure Cognitive Search endpoint, admin key, and index name | ||
const azureSearchEndpoint = process.env["AZURE_SEARCH_ENDPOINT"] || "<search endpoint>"; | ||
const azureSearchAdminKey = process.env["AZURE_SEARCH_KEY"] || "<search key>"; | ||
const azureSearchIndexName = process.env["AZURE_SEARCH_INDEX"] || "<search index>"; | ||
|
||
const messages = [ | ||
{ | ||
role: "user", | ||
content: "What's the most common feedback we received from our customers about the product?", | ||
}, | ||
]; | ||
|
||
async function main() { | ||
console.log("== Bring Your Own Data Sample =="); | ||
|
||
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); | ||
const deploymentId = "gpt-35-turbo"; | ||
const events = client.listChatCompletions(deploymentId, messages, { | ||
maxTokens: 128, | ||
/** | ||
* The `azureExtensionOptions` property is used to configure the | ||
* Azure-specific extensions. In this case, we are using the | ||
* Azure Cognitive Search extension with a vector index to provide | ||
* the model with additional context. | ||
*/ | ||
azureExtensionOptions: { | ||
extensions: [ | ||
{ | ||
type: "AzureCognitiveSearch", | ||
parameters: { | ||
endpoint: azureSearchEndpoint, | ||
key: azureSearchAdminKey, | ||
indexName: azureSearchIndexName, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
for await (const event of events) { | ||
for (const choice of event.choices) { | ||
console.log(choice.delta?.content); | ||
} | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); | ||
|
||
module.exports = { main }; |
45 changes: 45 additions & 0 deletions
45
sdk/openai/openai/samples/v1-beta/javascript/completionsRest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Demonstrates how to get completions for the provided prompt. | ||
* | ||
* @summary get completions. | ||
*/ | ||
|
||
const { AzureKeyCredential } = require("@azure/core-auth"); | ||
const OpenAIClient = require("@azure/openai/rest").default, | ||
{ isUnexpected } = require("@azure/openai/rest"); | ||
|
||
// Load the .env file if it exists | ||
require("dotenv").config(); | ||
|
||
// You will need to set these environment variables or edit the following values | ||
const endpoint = process.env["ENDPOINT"] || "<endpoint>"; | ||
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>"; | ||
|
||
const prompt = ["What is Azure OpenAI?"]; | ||
|
||
async function main() { | ||
console.log("== Get completions Sample =="); | ||
|
||
const client = OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); | ||
const deploymentId = "text-davinci-003"; | ||
const result = await client.path("/deployments/{deploymentId}/completions", deploymentId).post({ | ||
body: { prompt, max_tokens: 128 }, | ||
}); | ||
|
||
if (isUnexpected(result)) { | ||
throw result; | ||
} | ||
|
||
for (const choice of result.body.choices) { | ||
console.log(choice.text); | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); | ||
|
||
module.exports = { main }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Demonstrates how to define and call functions with chat completions. | ||
* | ||
* @summary get chat completions with functions. | ||
*/ | ||
|
||
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai"); | ||
|
||
// Load the .env file if it exists | ||
require("dotenv").config(); | ||
|
||
// You will need to set these environment variables or edit the following values | ||
const endpoint = process.env["ENDPOINT"] || "<endpoint>"; | ||
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>"; | ||
|
||
const messages = [{ role: "user", content: "What's the weather like in Boston?" }]; | ||
|
||
const getCurrentWeather = { | ||
name: "get_current_weather", | ||
description: "Get the current weather in a given location", | ||
parameters: { | ||
type: "object", | ||
properties: { | ||
location: { | ||
type: "string", | ||
description: "The city and state, e.g. San Francisco, CA", | ||
}, | ||
unit: { | ||
type: "string", | ||
enum: ["celsius", "fahrenheit"], | ||
}, | ||
}, | ||
required: ["location"], | ||
}, | ||
}; | ||
|
||
async function main() { | ||
console.log("== Chat Completions Sample With Functions =="); | ||
|
||
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); | ||
const deploymentId = "gpt-4"; | ||
const result = await client.getChatCompletions(deploymentId, messages, { | ||
functions: [getCurrentWeather], | ||
}); | ||
|
||
for (const choice of result.choices) { | ||
console.log(choice.message?.functionCall); | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); | ||
|
||
module.exports = { main }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Demonstrates how to generate images from prompts using Azure OpenAI Batch Image Generation. | ||
* | ||
* @summary generates images from prompts using Azure OpenAI Batch Image Generation. | ||
*/ | ||
|
||
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai"); | ||
|
||
// Load the .env file if it exists | ||
require("dotenv").config(); | ||
|
||
// You will need to set these environment variables or edit the following values | ||
const endpoint = process.env["ENDPOINT"] || "<endpoint>"; | ||
const azureApiKey = process.env["AZURE_API_KEY"] || "<api key>"; | ||
|
||
// The prompt to generate images from | ||
const prompt = "a monkey eating a banana"; | ||
const size = "256x256"; | ||
|
||
// The number of images to generate | ||
const n = 3; | ||
|
||
async function main() { | ||
console.log("== Batch Image Generation =="); | ||
|
||
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); | ||
const results = await client.getImages(prompt, { n, size }); | ||
|
||
for (const image of results.data) { | ||
console.log(`Image generation result URL: ${image.url}`); | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); | ||
|
||
module.exports = { main }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.