diff --git a/sdk/openai/openai/samples-dev/chatCompletions.ts b/sdk/openai/openai/samples-dev/chatCompletions.ts index fc670f585dca..a76c2022b6f8 100644 --- a/sdk/openai/openai/samples-dev/chatCompletions.ts +++ b/sdk/openai/openai/samples-dev/chatCompletions.ts @@ -29,7 +29,7 @@ export async function main() { console.log("== Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; + const deploymentId = "gpt-35-turbo"; const result = await client.getChatCompletions(deploymentId, messages); for (const choice of result.choices) { diff --git a/sdk/openai/openai/samples-dev/completions.ts b/sdk/openai/openai/samples-dev/completions.ts index 493093cc6007..5788fa1ed004 100644 --- a/sdk/openai/openai/samples-dev/completions.ts +++ b/sdk/openai/openai/samples-dev/completions.ts @@ -25,7 +25,7 @@ export async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const result = await client.getCompletions(deploymentId, prompt); + const result = await client.getCompletions(deploymentId, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text); diff --git a/sdk/openai/openai/samples-dev/completionsRest.ts b/sdk/openai/openai/samples-dev/completionsRest.ts new file mode 100644 index 000000000000..52a12bae2ab3 --- /dev/null +++ b/sdk/openai/openai/samples-dev/completionsRest.ts @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * Demonstrates how to get completions for the provided prompt. + * + * @summary get completions. + * @azsdk-weight 100 + */ + +import { AzureKeyCredential } from "@azure/core-auth"; +import OpenAIClient, { isUnexpected } from "@azure/openai/rest"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +// You will need to set these environment variables or edit the following values +const endpoint = process.env["ENDPOINT"] || ""; +const azureApiKey = process.env["AZURE_API_KEY"] || ""; + +const prompt = ["What is Azure OpenAI?"]; + +export 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); +}); diff --git a/sdk/openai/openai/samples-dev/listChatCompletions.ts b/sdk/openai/openai/samples-dev/listChatCompletions.ts index fce86db78db8..3fea7d228112 100644 --- a/sdk/openai/openai/samples-dev/listChatCompletions.ts +++ b/sdk/openai/openai/samples-dev/listChatCompletions.ts @@ -29,8 +29,8 @@ export async function main() { console.log("== Streaming Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; - const events = await client.listChatCompletions(deploymentId, messages); + const deploymentId = "gpt-35-turbo"; + const events = await client.listChatCompletions(deploymentId, messages, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples-dev/listCompletions.ts b/sdk/openai/openai/samples-dev/listCompletions.ts index 3fd76cf25410..e511399856a5 100644 --- a/sdk/openai/openai/samples-dev/listCompletions.ts +++ b/sdk/openai/openai/samples-dev/listCompletions.ts @@ -25,7 +25,7 @@ export async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const events = await client.listCompletions(deploymentId, prompt); + const events = await client.listCompletions(deploymentId, prompt, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples-dev/openAi.ts b/sdk/openai/openai/samples-dev/openAi.ts index a5db9ea1e4a9..7a8f76493d29 100644 --- a/sdk/openai/openai/samples-dev/openAi.ts +++ b/sdk/openai/openai/samples-dev/openAi.ts @@ -25,7 +25,7 @@ export async function main() { const client = new OpenAIClient(new OpenAIKeyCredential(openApiKey)); const model = "text-davinci-003"; - const result = await client.getCompletions(model, prompt); + const result = await client.getCompletions(model, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text); diff --git a/sdk/openai/openai/samples/v1-beta/javascript/chatCompletions.js b/sdk/openai/openai/samples/v1-beta/javascript/chatCompletions.js index 75c9e927a839..9d0948d607a8 100644 --- a/sdk/openai/openai/samples/v1-beta/javascript/chatCompletions.js +++ b/sdk/openai/openai/samples/v1-beta/javascript/chatCompletions.js @@ -27,7 +27,7 @@ async function main() { console.log("== Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; + const deploymentId = "gpt-35-turbo"; const result = await client.getChatCompletions(deploymentId, messages); for (const choice of result.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/javascript/completions.js b/sdk/openai/openai/samples/v1-beta/javascript/completions.js index 578b781c92e0..e0f507a98363 100644 --- a/sdk/openai/openai/samples/v1-beta/javascript/completions.js +++ b/sdk/openai/openai/samples/v1-beta/javascript/completions.js @@ -23,7 +23,7 @@ async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const result = await client.getCompletions(deploymentId, prompt); + const result = await client.getCompletions(deploymentId, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text); diff --git a/sdk/openai/openai/samples/v1-beta/javascript/listChatCompletions.js b/sdk/openai/openai/samples/v1-beta/javascript/listChatCompletions.js index 78815aa17a94..dedd8c477fe7 100644 --- a/sdk/openai/openai/samples/v1-beta/javascript/listChatCompletions.js +++ b/sdk/openai/openai/samples/v1-beta/javascript/listChatCompletions.js @@ -27,8 +27,8 @@ async function main() { console.log("== Streaming Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; - const events = await client.listChatCompletions(deploymentId, messages); + const deploymentId = "gpt-35-turbo"; + const events = await client.listChatCompletions(deploymentId, messages, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/javascript/listCompletions.js b/sdk/openai/openai/samples/v1-beta/javascript/listCompletions.js index e1d16e9dcb7f..5addb35bea3d 100644 --- a/sdk/openai/openai/samples/v1-beta/javascript/listCompletions.js +++ b/sdk/openai/openai/samples/v1-beta/javascript/listCompletions.js @@ -23,7 +23,7 @@ async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const events = await client.listCompletions(deploymentId, prompt); + const events = await client.listCompletions(deploymentId, prompt, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/javascript/openAi.js b/sdk/openai/openai/samples/v1-beta/javascript/openAi.js index 1a0d6f473b7d..5a06e4a0fff1 100644 --- a/sdk/openai/openai/samples/v1-beta/javascript/openAi.js +++ b/sdk/openai/openai/samples/v1-beta/javascript/openAi.js @@ -2,7 +2,7 @@ // Licensed under the MIT License. /** - * Demonstrates how to get completions for the provided prompt using OpenAI API. + * Demonstrates how to get completions for the provided prompt using OpenAI hosted service. * * @summary get completions using the OpenAI API. */ @@ -24,7 +24,7 @@ async function main() { const client = new OpenAIClient(new OpenAIKeyCredential(openApiKey)); const model = "text-davinci-003"; - const result = await client.getCompletions(model, prompt); + const result = await client.getCompletions(model, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text); diff --git a/sdk/openai/openai/samples/v1-beta/typescript/src/chatCompletions.ts b/sdk/openai/openai/samples/v1-beta/typescript/src/chatCompletions.ts index f0c8f9c5e473..8db995322f1b 100644 --- a/sdk/openai/openai/samples/v1-beta/typescript/src/chatCompletions.ts +++ b/sdk/openai/openai/samples/v1-beta/typescript/src/chatCompletions.ts @@ -28,7 +28,7 @@ export async function main() { console.log("== Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; + const deploymentId = "gpt-35-turbo"; const result = await client.getChatCompletions(deploymentId, messages); for (const choice of result.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/typescript/src/completions.ts b/sdk/openai/openai/samples/v1-beta/typescript/src/completions.ts index d46a31c37b4c..598cc48abc93 100644 --- a/sdk/openai/openai/samples/v1-beta/typescript/src/completions.ts +++ b/sdk/openai/openai/samples/v1-beta/typescript/src/completions.ts @@ -24,7 +24,7 @@ export async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const result = await client.getCompletions(deploymentId, prompt); + const result = await client.getCompletions(deploymentId, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text); diff --git a/sdk/openai/openai/samples/v1-beta/typescript/src/listChatCompletions.ts b/sdk/openai/openai/samples/v1-beta/typescript/src/listChatCompletions.ts index f9b64a57cb43..177c2d03b5fd 100644 --- a/sdk/openai/openai/samples/v1-beta/typescript/src/listChatCompletions.ts +++ b/sdk/openai/openai/samples/v1-beta/typescript/src/listChatCompletions.ts @@ -28,8 +28,8 @@ export async function main() { console.log("== Streaming Chat Completions Sample =="); const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); - const deploymentId = "gpt-3.5-turbo"; - const events = await client.listChatCompletions(deploymentId, messages); + const deploymentId = "gpt-35-turbo"; + const events = await client.listChatCompletions(deploymentId, messages, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/typescript/src/listCompletions.ts b/sdk/openai/openai/samples/v1-beta/typescript/src/listCompletions.ts index 15cf069c71b8..46cbed9404e7 100644 --- a/sdk/openai/openai/samples/v1-beta/typescript/src/listCompletions.ts +++ b/sdk/openai/openai/samples/v1-beta/typescript/src/listCompletions.ts @@ -24,7 +24,7 @@ export async function main() { const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); const deploymentId = "text-davinci-003"; - const events = await client.listCompletions(deploymentId, prompt); + const events = await client.listCompletions(deploymentId, prompt, { maxTokens: 128 }); for await (const event of events) { for (const choice of event.choices) { diff --git a/sdk/openai/openai/samples/v1-beta/typescript/src/openAi.ts b/sdk/openai/openai/samples/v1-beta/typescript/src/openAi.ts index 9356358c97fe..29da1755e2ae 100644 --- a/sdk/openai/openai/samples/v1-beta/typescript/src/openAi.ts +++ b/sdk/openai/openai/samples/v1-beta/typescript/src/openAi.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. /** - * Demonstrates how to get completions for the provided prompt using OpenAI API. + * Demonstrates how to get completions for the provided prompt using OpenAI hosted service. * * @summary get completions using the OpenAI API. */ @@ -24,7 +24,7 @@ export async function main() { const client = new OpenAIClient(new OpenAIKeyCredential(openApiKey)); const model = "text-davinci-003"; - const result = await client.getCompletions(model, prompt); + const result = await client.getCompletions(model, prompt, { maxTokens: 128 }); for (const choice of result.choices) { console.log(choice.text);