diff --git a/sdk/openai/openai/.mocharc.json b/sdk/openai/openai/.mocharc.json deleted file mode 100644 index 332e7113dd57..000000000000 --- a/sdk/openai/openai/.mocharc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extension": ["ts"], - "timeout": "1200000", - "loader": "ts-node/esm" -} diff --git a/sdk/openai/openai/CHANGELOG.md b/sdk/openai/openai/CHANGELOG.md deleted file mode 100644 index 523c7f97ea06..000000000000 --- a/sdk/openai/openai/CHANGELOG.md +++ /dev/null @@ -1,199 +0,0 @@ -# Release History - -## 2.0.0-beta.3 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - -## 2.0.0-beta.2 (2024-09-09) - -### Features Added - -- Adds `CompletionChoice` interface with content filter result. -- Updates the `license` property to be optional in `ContentFilterCitedDetectionResultOutput`. -- Updates `custom_blocklists` type in `ContentFilterResultsForChoiceOutput` to `ContentFilterDetailedResults`. - -### Bugs Fixed - -- Add `@azure-rest/core-client` as a dependency so TypeScript users don't have to import it manually in their code. - -## 2.0.0-beta.1 (2024-07-22) - -### Features Added - -- Adds subpath `@azure/openai/types` which exports types for Azure On Your Data and Azure content filtering. Checkout the [samples folder](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples) for examples of how to import it. - -### Breaking Changes - -- `OpenAIClient` has been deleted. Follow the [migration guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/MIGRATION.md) to use `AzureOpenAI` from the official [OpenAI client library for JavaScript](https://www.npmjs.com/package/openai) instead. - -## 1.0.0-beta.12 (2024-04-01) - -### Features Added - -- Adds a new property `logprobs` in `ChatChoice` to support log probabilities for this chat choice -- Adds new properties `logprobs` and `topLogprobs` in `ChatCompletionsOptions` class to support log probabilities for chat completions -- Adds `dimensions` in `GetEmbeddingsOptions`. -when using Azure OpenAI, specifies the input type to use for embedding search. -- Updates the default service API version to `2024-03-01-preview` -- Returns content filter results and prompt filter results for image generations through `contentFilterResults` and `promptFilterResults` properties - -### Breaking Changes - -- `AzureChatExtensionConfiguration`, `OnYourDataAuthenticationOptions`, `OnYourDataVectorizationSource`, `OnYourDataVectorizationSourceType`, `ChatCompletionsNamedToolSelection`, `ChatCompletionsToolDefinition`, `ChatCompletionsToolCall`, `ChatMessageContentItem`, `ChatRequestMessage`, `ChatFinishDetails` are renamed with `Union` postfix. -- `AzureCognitiveSearchQueryType`, `ChatMessageImageDetailLevel`, `ElasticsearchQueryType`, `FunctionCallPreset`, `ImageGenerationQuality`, `ImageGenerationResponseFormat`, `ImageSize`, `ImageGenerationStyle`, `OnYourDataAuthenticationType`, `OnYourDataVectorizationSourceType` union types no longer have fixed values. -- `prompFilterResults` property in `ChatCompletions`, `prompFilterResults` property in `Choice`, `toolCalls` in `ChatResponseMessage` are now optional - -Changes to "bring your own data" features: -- Introduces a new type: `AzureChatExtensionDataSourceResponseCitation` -- For `AzureChatExtensionsMessageContext`, replaced `messages` property with `citations` and added `intent` as a string -- Rename `AzureCognitiveSearch` to `AzureSearch` -- `embeddingDependency` is a required property for `AzureCosmosDBChatExtensionConfiguration` -- All extension configuration `type` properties are changed into snake casing. For example, type `AzureCosmosDB` is changed into `azure_cosmos_db`in `AzureCosmosDBChatExtensionConfiguration` -- All authentication `type` properties are changed into snake casing. For example, type `ConnectionString` is changed into `connection_string`in `OnYourDataConnectionStringAuthenticationOptions` -- New properties are added to `AzureCosmosDBFieldMappingOptions`: `contentFields`, `contentFieldsSeparator`, `filepathField`, `titleField`, and `urlField`. -- Adds additional support for different authentication options, including access token and encoded API key authentication -- `embeddingDependency` is required in `PineconeChatExtensionConfiguration` -- `contentField` is required in `PineconeFieldMappingOptions` - -### Bugs Fixed - -- Fix a bug where `ChatCompletionsFunctionToolCall` did not expose the `index` property for the streaming mode. - -## 1.0.0-beta.11 (2024-01-25) - -### Bugs Fixed - -- Fix a bug where `toolChoice` field in the input options to chat completion methods wasn't defined correctly. -- Fix a bug where the service returns undefined `choices` in chat completion methods. -- Fix a bug in chat completion methods where the returned stream was causing an error in Bun. - -## 1.0.0-beta.10 (2024-01-03) - -### Bugs Fixed - -- Fix `responseFormat` behavior in `getAudioTranscription` and `getAudioTranslation` methods where request wasn't properly formed if it wasn't specified. - -## 1.0.0-beta.9 (2024-01-02) - -### Breaking Changes - -- `listChatCompletions` and `listCompletions` are renamed to `streamChatCompletions` and `streamCompletions` respectively and their return types are updated to be a `ReadableStream`. For example, `streamChatCompletions` can be used as follows: - -```js - const events = await client.streamChatCompletions(deploymentId, messages); - for await (const event of events) { - // use event ... - } -``` - -## 1.0.0-beta.8 (2023-12-07) - -Following OpenAI's November Dev Day and Microsoft's 2023 Ignite conference, this update brings a slew of new -features and changes to the client library. - -### Features Added - -- `-1106` model feature support for `gpt-35-turbo` and `gpt-4-turbo`, including use of `seed`, `system_fingerprint`, parallel function calling via tools, "JSON mode" for guaranteed function outputs, and more -- `dall-e-3` image generation capabilities via `getImages`, featuring higher model quality, automatic prompt revisions by `gpt-4`, and customizable quality/style settings -- Greatly expanded "On Your Data" capabilities in Azure OpenAI, including many new data source options and authentication mechanisms -- Early support for `gpt-4-vision-preview`, which allows the hybrid use of text and images as input to enable scenarios like "describe this image for me" -- Support for Azure enhancements to `gpt-4-vision-preview` results that include grounding and OCR features - -### Breaking Changes - -`ChatMessage` changes: - -- The singular `ChatMessage` type has been replaced by `ChatRequestMessage` and `ChatResponseMessage`, the former of - which is a union of special message structures such as `ChatRequestSystemMessage` and - `ChatRequestUserMessage`. - -Dall-e-3: - -- Azure OpenAI now uses `dall-e-3` model deployments for its image generation API and such a valid deployment must - be provided to the `GetImageGenerations` method. - -On Your Data: - -- The `AzureExtensionChatConfiguration` type has been updated to inline the parameters of the extension into the - configuration object itself. - -## 1.0.0-beta.7 (2023-10-25) - -### Bugs Fixed - -- Support Cloudflare workers by only setting the available fields in the `Request` class for the Fetch API. -- Wait before stop listening to the abort signal until after the response stream has been drained to allow for aborting prolonged responses. - -### Other Changes - -- NodeJS v18 is now the minimum version supported. Check out the [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) for more information on NodeJS support timelines. And check out the [Microsoft Support Policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md#microsoft-support-policy) for more information on Microsoft support timelines. - -## 1.0.0-beta.6 (2023-09-21) - -### Features Added - -- Introduces speech to text and translation capabilities for a wide variety of audio file formats. - - Adds `getAudioTranscription` and `getAudioTranslation` methods for transcribing and translating audio files. The result can be either a simple JSON structure with just a `text` field or a more detailed JSON structure containing the text alongside additional information. In addition, VTT (Web Video Text Tracks), SRT (SubRip Text), and plain text formats are also supported. The type of the result depends on the `format` parameter if specified, otherwise, a simple JSON output is assumed. The methods could take as input an optional text prompt to guide the model's style or continue a previous audio segment. The language of the prompt should match that of the audio file. - - The available model at the time of this release supports the following list of audio file formats: m4a, mp3, wav, ogg, flac, webm, mp4, mpga, mpeg, and oga. - -### Bugs Fixed - -- Returns `usage` information when available. -- Fixes a bug where errors weren't properly being thrown from the streaming methods. -- Returns `error` information in `ContentFilterResults` when available. -- Fixes parsing of `functionCall` in `ChatMessage` objects. - -## 1.0.0-beta.5 (2023-08-25) - -### Features Added - -- (Azure OpenAI specific) Chat completions with your own data is now supported, see [Azure OpenAI's quickstart guide](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart?tabs=command-line&pivots=programming-language-studio) for details. - - A list of AzureExtensionChatConfiguration may be populated on `ChatCompletionsOptions` via its `azureExtensionOption.extensions` property. These configurations include a type together with a JSON Schema representation of its parameters. The type is used to determine which extension to use when generating chat completions. See the `bringYourOwnData.js` sample for an example of how to use this feature. -- Functions for chat completions are now supported: see [OpenAI's blog post on the topic](https://openai.com/blog/function-calling-and-other-api-updates) for much more detail. - - A list of `FunctionDefinition` objects may be populated on `ChatCompletionsOptions` via its `functions` property. These definitions include a name and description together with a serialized JSON Schema representation of its parameters. - - **NOTE**: Chat Functions requires a minimum of the `-0613` model versions for `gpt-4` and `gpt-3.5-turbo`/`gpt-35-turbo`. Please ensure you're using these later model versions, as Functions are not supported with older model revisions. For Azure OpenAI, you can update a deployment's model version or create a new model deployment with an updated version via the Azure AI Studio interface, also accessible through Azure Portal. -- (Azure OpenAI specific) Completions and Chat Completions responses now include embedded content filter annotations for prompts and responses - -### Breaking Changes - -- Remove `beginAzureBatchImageGeneration` and `getAzureBatchImageGenerationOperationStatus` methods. -- `getImages` has been updated to return the image URLs/payloads directly, rather than requiring the user to call `getAzureBatchImageGenerationOperationStatus` to retrieve them. - -## 1.0.0-beta.4 (2023-08-09) - -### Features Added - -- Exporting individual capabilities as separate functions to be used in code-size-concious applications. For example, streaming completions can be imported individually as follows: - -```js -import { listCompletions, createOpenAI } from "@azure/openai/api"; -const client = createOpenAI(endpoint, new AzureKeyCredential(azureApiKey)); -const events = listCompletions(client, prompt, deploymentId, { maxTokens: 128 }); -``` - -### Bugs Fixed - -- Fix a bug where server-sent events were not being parsed correctly. - -## 1.0.0-beta.3 (2023-07-13) - -### Features Added - -- Added support for batch image generation via `beginAzureBatchImageGeneration` and `getAzureBatchImageGenerationOperationStatus`. -- Added GetImages convenience API for above, as well as supporting ImageGenerationOptions and ImageGenerationResponse aliases. - -## 1.0.0-beta.2 (2023-06-06) - -### Bugs Fixed - -- Fix a bug where the customer-passed options for credentials were overwritten by the defaults values. - -## 1.0.0-beta.1 (2023-05-22) - -- This is the initial beta release for Azure OpenAI inference capabilities, including completions, chat completions, and embeddings. diff --git a/sdk/openai/openai/LICENSE b/sdk/openai/openai/LICENSE deleted file mode 100644 index 31db5faf30b7..000000000000 --- a/sdk/openai/openai/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2023 Microsoft - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/sdk/openai/openai/MIGRATION.md b/sdk/openai/openai/MIGRATION.md deleted file mode 100644 index 2f6ca2bf093a..000000000000 --- a/sdk/openai/openai/MIGRATION.md +++ /dev/null @@ -1,551 +0,0 @@ -# Migrating to `openai` - -**Note ⚠️**: This document is a work-in-progress and may change to reflect updates to the package. We value your feedback, please [create an issue](https://github.com/Azure/azure-sdk-for-js/issues/new/choose) to suggest any improvements or report any problems with this guide or with the package itself. - -`openai@4.42.0`, the latest version of the official OpenAI JavaScript client library, features `AzureOpenAI`, a new client that supports the Azure OpenAI Service API, version "2022-12-01" and later. `AzureOpenAI` is now the preferred JavaScript client for interfacing with the Azure OpenAI service. This guide will highlight the differences and enhancements over other client libraries such as `@azure/openai@1.0.0-beta.12` and `@azure/openai-assistants@1.0.0-beta.5`, ensuring a smooth transition for users updating their implementations. - -- `@azure/openai@1.0.0-beta.12` exports `OpenAIClient` that supports most of Azure OpenAI features such as chat completions, On Your Data, embeddings, and audio translation and transcription. It doesn't support Azure OpenAI Assistants. -- `@azure/openai-assistants@1.0.0-beta.5` exports `AssistantsClient` that supports Azure OpenAI Assistants v1 features. -- Both `OpenAIClient` and `AssistantsClient` will be deprecated in the coming weeks and will be removed in the future. -- `openai@4.42.0` exports `AzureOpenAI` which can connect to Azure OpenAI service and supports all of its features. - -This document provides instructions for updating your application code to use `AzureOpenAI` provided by `openai`. In this document, the examples provided use TypeScript to provide type information, but all runtime behavior changes naturally apply to plain JavaScript as well. - -## Authenticating the client - -There are several ways to authenticate with the Azure OpenAI service and the recommended way is to use Microsoft Entra ID tokens. If your application doesn't use them already, it is highly recommended to switch to them. Refer to the [Azure Identity documentation](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md) for more information. - -### Microsoft Entra ID (Formerly known as Azure Active Directory) - -There are several ways to authenticate with the Azure OpenAI service using Microsoft Entra ID tokens. The default way is to use the `DefaultAzureCredential` class from the `@azure/identity` package but your application may be using a different credential class. For the purposes of this guide, we will assume that you are using the `DefaultAzureCredential` class. A credential can be created as follows: - -```typescript -import { DefaultAzureCredential } from "@azure/identity"; -const credential = new DefaultAzureCredential(); -``` - -Which is then passed to the second argument of the client constructors of `OpenAIClient` and `AssistantsClient`. - -However, in order to authenticate the `AzureOpenAI` client, we need to use the `getBearerTokenProvider` function from the `@azure/identity` package. This function creates a token provider that `AzureOpenAI` uses internally to obtain tokens for each request. The token provider is created as follows: - -```typescript -import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; -const credential = new DefaultAzureCredential(); -const scope = "https://cognitiveservices.azure.com/.default"; -const azureADTokenProvider = getBearerTokenProvider(credential, scope); -``` - -`azureADTokenProvider` will be passed to the options object when creating the `AzureOpenAI` client. - -### (⚠️ Highly Discouraged) API Key - -API keys are not recommended for production use because they are less secure than other authentication methods. However, if you are using an API key to authenticate `OpenAIClient` or `AssistantsClient`, an `AzureKeyCredential` object must have been created as follows: - -```typescript -import { AzureKeyCredential } from "@azure/openai"; -const apiKey = new AzureKeyCredential("your API key"); -``` - -Authenticating `AzureOpenAI` with an API key is as simple as setting the `AZURE_OPENAI_API_KEY` environment variable or as setting the `apiKey` string property in the options object when creating the `AzureOpenAI` client. - -## Constructing the client - -`OpenAIClient` and `AssistantsClient` are constructed similarly as follows: - -Original code: - -```typescript -import { OpenAIClient } from "@azure/openai"; -const endpoint = "Your Azure OpenAI resource endpoint"; -const client = new OpenAIClient(endpoint, credential); -``` - -If not set, the API version defaults to the last known one before the release of the client. Also, the client is not locked to a single model deployment, meaning that the deployment name has to be passed to each method that requires it. - -On the other hand, the `AzureOpenAI` client is constructed as follows: - -Migrated code: - -```typescript -import { AzureOpenAI } from "openai"; -const deployment = "Your Azure OpenAI deployment"; -const apiVersion = "2024-07-01-preview"; -const options = { azureADTokenProvider, deployment, apiVersion } -const client = new AzureOpenAI(options); -``` - -The endpoint of the Azure OpenAI resource can be specified by setting the `endpoint` option but it can also be loaded by the client from the environment variable `AZURE_OPENAI_ENDPOINT`. This is the recommended way to set the endpoint because it allows the client to be used in different environments without changing the code and also to protect the endpoint from being exposed in the code. -Note that the API version is required to be specified, this is necessary to ensure that existing code doesn't break between preview API versions. Refer to [API Versions Documentation](https://learn.microsoft.com/azure/ai-services/openai/api-version-deprecation) to learn more about Azure OpenAI API versions. Additionally, the `deployment` property is not required but it is recommended to be set. Once `deployment` is set, it is used as the default deployment for all operations that require it. If the client is not created with the `deployment` option, the `model` property in the options object should be set with the deployment name. However, audio operations such as `audio.transcriptions.create` require the client to be created with the `deployment` option set to the deployment name. - -## API differences - -There are key differences between the `OpenAIClient` and `AssistantsClient` clients and the `AzureOpenAI` client: - -- Operations are represented as a flat list of methods in both `OpenAIClient` and `AssistantsClient`, e.g. `client.getChatCompletions(...)`. In `AzureOpenAI`, operations are grouped in nested groups, e.g. `client.chat.completions.create({ ... })`. -- `OpenAIClient` and `AssistantsClient` rename many of the names used in the Azure OpenAI service API. For example, snake case is used in the API but camel case is used in the client. In `AzureOpenAI`, names are kept the same as in the Azure OpenAI service API. - -## Migration examples - -The following sections provide examples of how to migrate from `OpenAIClient` and `AssistantsClient` to `AzureOpenAI`. - -### Chat completions - -The following example shows how to migrate the `getChatCompletions` method call. - -Original code: - -```typescript -const result = await client.getChatCompletions(deploymentName, messages, { maxTokens: 100 }); -``` - -Migrated code: - -```typescript -const result = await client.chat.completions.create({ messages, model: '', max_tokens: 100 }); -``` - -Notice the following: - -- The `getChatCompletions` method has been replaced with the `chat.completions.create` method -- The `messages` parameter is now passed in the options object with the `messages` property -- The `maxTokens` property has been renamed to `max_tokens` and the `deploymentName` parameter has been removed. Generally, the names of the properties in the `options` object are the same as in the Azure OpenAI service API, following the snake case convention instead of the camel case convention used in the `AssistantsClient`. This is true for all the properties across all requests and responses in the `AzureOpenAI` client -- The `deploymentName` parameter is not needed if the client was created with the `deployment` option. If the client was not created with the `deployment` option, the `model` property in the option object should be set with the deployment name. - -### Streaming chat completions - -The following example shows how to migrate the `streamChatCompletions` method call. - -Original code: - -```typescript -const stream = await client.streamChatCompletions(deploymentName, messages, { maxTokens: 100 }); -``` - -Migrated code: - -```typescript -const stream = await client.chat.completions.create({ model: '', messages, max_tokens: 100, stream: true }); -``` - -### Azure On Your Data - -The following example shows how to migrate a `getChatCompletions` method call that enables Azure On Your Data with Azure Search. - -Original code: - -```typescript -const azureSearchEndpoint = "Your Azure Search resource endpoint"; -const azureSearchIndexName = "Your Azure Search index name"; -const result = await client.getChatCompletions(deploymentName, messages, { azureExtensionOptions: { - data_sources: [{ - type: "azure_search", - endpoint: azureSearchEndpoint, - indexName: azureSearchIndexName, - authentication: { - type: "system_assigned_managed_identity", - } - }] - } -}); -``` - -Migrated code: - -```typescript -import "@azure/openai/types"; - -const azureSearchEndpoint = "Your Azure Search resource endpoint"; -const azureSearchIndexName = "Your Azure Search index name"; -const result = await client.chat.completions.create({ - model: '', - messages, - data_sources: [{ - type: "azure_search", - parameters: { - endpoint: azureSearchEndpoint, - index_name: azureSearchIndexName, - authentication: { - type: "system_assigned_managed_identity", - } - } - }] -}); -``` - -Notice that: - -- `"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `data_sources`) to the client types -- The `azureExtensionOptions` property has been replaced with the inner `data_sources` property -- The `parameters` property has been added to wrap the parameters of the extension, which mirrors the schema of the Azure OpenAI service API -- camel case properties have been replaced with snake case properties - -### Audio transcription - -The following example shows how to migrate the `getAudioTranscription` method call. - -Original code: - -```typescript -import { readFile } from "fs/promises"; - -const audioFilePath = "path/to/audio/file"; -const audio = await readFile(audioFilePath); -const result = await client.getAudioTranscription(deploymentName, audio); -``` - -Migrated code: - -```typescript -import { createReadStream } from "fs"; - -const result = await client.audio.transcriptions.create({ - model: '', - file: createReadStream(audioFilePath), -}); -``` - -Notice that: - -- The `getAudioTranscription` method has been replaced with the `audio.transcriptions.create` method -- The `AzureOpenAI` has to be constructed with the `deployment` option set to the deployment name in order to use audio operations such as `audio.transcriptions.create` -- The `model` property is required to be set in the options object but its value is not used in the operation so feel free to set it to any value -- The `file` property accepts a variety of types including `Buffer`, `fs.ReadaStream`, and `Blob` but in this example, a file is streamed from disk using `fs.createReadStream` - -### Audio translation - -The following example shows how to migrate the `getAudioTranslation` method call. - -Original code: - -```typescript -import { readFile } from "fs/promises"; - -const audioFilePath = "path/to/audio/file"; -const audio = await readFile(audioFilePath); -const result = await client.getAudioTranslation(deploymentName, audio); -``` - -Migrated code: - -```typescript -import { createReadStream } from "fs"; - -const result = await client.audio.translations.create({ - model: '', - file: createReadStream(audioFilePath), -}); -``` - -Notice that: - -- The `getAudioTranslation` method has been replaced with the `audio.translations.create` method -- All other changes are the same as in the audio transcription example - -### Assistants - -The following examples show how to migrate some of the `AssistantsClient` methods. - -#### Assistant creation - -Original code: - -```typescript -const options = { - model: azureOpenAIDeployment, - name: "Math Tutor", - instructions: - "You are a personal math tutor. Write and run JavaScript code to answer math questions.", - tools: [{ type: "code_interpreter" }], -}; -const assistantResponse = await assistantsClient.createAssistant(options); -``` - -Migrated code: - -```typescript -const options = ...; -const assistantResponse = await assistantsClient.beta.assistants.create( - options -); -``` - -Notice that: - -- The `createAssistant` method has been replaced with the `beta.assistants.create` method - -#### Thread creation - -The following example shows how to migrate the `createThread` method call. - -Original code: - -```typescript -const assistantThread = await assistantsClient.createThread(); -``` - -Migration code: - -```typescript -const assistantThread = await assistantsClient.beta.threads.create(); -``` - -Notice that: - -- The `createThread` method has been replaced with the `beta.threads.create` method - -#### Message creation - -The following example shows how to migrate the `createMessage` method call. - -Original code: - -```typescript -const threadResponse = await assistantsClient.createMessage( - assistantThread.id, - role, - message -); -``` - -Migration code: - -```typescript -const threadResponse = await assistantsClient.beta.threads.messages.create( - assistantThread.id, - { - role, - content: message, - } -); -``` - -Notice that: - -- The `createMessage` method has been replaced with the `beta.threads.messages.create` method -- The message specification has been moved from a parameter list to an options object - -#### Runs - -To run an assistant on a thread, the `createRun` method is used to create a run and then a loop is used to poll the run status until it is in a terminal state. The following example shows how to migrate the run creation and polling. - -Original code: - -```typescript -let runResponse = await assistantsClient.createRun(assistantThread.id, { - assistantId: assistantResponse.id, -}); - -do { - await new Promise((r) => setTimeout(r, 500)); - runResponse = await assistantsClient.getRun( - assistantThread.id, - runResponse.id - ); -} while ( - runResponse.status === "queued" || - runResponse.status === "in_progress" -``` - -This code can be migrated and simplified by using the `createAndPoll` method which creates a run and polls it until it is in a terminal state. - -Migration code: - -```typescript -const runResponse = await assistantsClient.beta.threads.runs.createAndPoll( - assistantThread.id, - { - assistant_id: assistantResponse.id, - }, - { pollIntervalMs: 500 } -); -``` - -Notice that: - -- The `createRun` method has been replaced with the `beta.threads.runs.create` and `createAndPoll` methods -- The `createAndPoll` method is used to create a run and poll it until it is in a terminal state - -#### Processing Run results - -Without paging, results had to be accessed manually page by page using the `data` property of the response object. For instance, accessing the first page can be done as follows: - -Original code: - -```typescript -for (const runMessageDatum of runMessages.data) { - for (const item of runMessageDatum.content) { - ... - } -} -``` - -Pages can be looped through by using the `for await` loop. - -Migration code: - -```typescript -for await (const runMessageDatum of runMessages) { - for (const item of runMessageDatum.content) { - ... - } -} -``` - -### Embeddings - -The following example shows how to migrate the `getEmbeddings` method call. - -Original code: - -```typescript -const embeddings = await client.getEmbeddings(deploymentName, input); -``` - -Migrated code: - -```typescript -const embeddings = await client.embeddings.create({ input, model: '' }); -``` - -Notice that: - -- The `getEmbeddings` method has been replaced with the `embeddings.create` method -- The `input` parameter is now passed in the options object with the `input` property -- The `deploymentName` parameter has been removed. The `deploymentName` parameter is not needed if the client was created with the `deployment` option. If the client was not created with the `deployment` option, the `model` property in the option object should be set with the deployment name - -### Image generation - -The following example shows how to migrate the `getImages` method call. - -Original code: - -```typescript -const results = await client.getImages(deploymentName, prompt, { n, size }); -``` - -Migrated code: - -```typescript - const results = await client.images.generate({ prompt, model: '', n, size }); -``` - -Notice that: - -- The `getImages` method has been replaced with the `images.generate` method -- The `prompt` parameter is now passed in the options object with the `prompt` property -- The `deploymentName` parameter has been removed. The `deploymentName` parameter is not needed if the client was created with the `deployment` option. If the client was not created with the `deployment` option, the `model` property in the option object should be set with the deployment name - -### Content filter - -Content filter results is part of the chat completions response types in `OpenAIClient`. The following example shows how to access the content filter results. - -Original code: - -```typescript -const results = await client.getChatCompletions(deploymentName, messages); -for (const choice of results.choices) { - if (!choice.contentFilterResults) { - console.log("No content filter is found"); - return; - } - if (choice.contentFilterResults.error) { - console.log( - `Content filter ran into the error ${choice.contentFilterResults.error.code}: ${choice.contentFilterResults.error.message}`); - } - const { hate, sexual, selfHarm, violence } = choice.contentFilterResults; - ... -} -``` - -However `AzureOpenAI` does not have a direct equivalent to the `contentFilterResults` property in the `ChatCompletion.Choice` interface. The content filter results can be accessed by importing `"@azure/openai/types"` and accessing the `content_filter_results` property. - -Migrated code: - -```typescript -import "@azure/openai/types"; - -const result = await client.chat.completions.create({ model: '', messages }); -for (const choice of results.choices) { - const filterResults = choice.content_filter_results; - if (!filterResults) { - console.log("No content filter is found"); - return; - } - if (filterResults.error) { - console.log( - `Content filter ran into the error ${filterResults.error.code}: ${filterResults.error.message}`); - } - const { hate, sexual, self_harm, violence } = filterResults; - ... -} -``` - -Notice that: - -- camel case properties have been replaced with snake case properties -- `"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `content_filter_results`) to the client types, see the [Azure types](#azure-types) section for more information - -## Comparing Types - -The following table explores several type names from `@azure/openai` and shows their nearest `openai` equivalent. The names differences illustrate several of the above-mentioned changes. This table provides an overview, and more detail and code samples are provided in the following sections. - - -| Old Type Name | Nearest New Type | Symbol Type | Change description | -| ------------------------- | ------------------------- | ----------- | ----------------------------- | -| `OpenAIClient` | `AzureOpenAI` | Class | This class replaces the former and has no methods in common with it. See the section on `AzureOpenAI` below. | -| `AudioResult` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one | -| `AudioResultFormat` | inline union type of the `response_format` property | Alias | It doesn't exist | -| `AudioResultSimpleJson` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one | -| `AudioResultVerboseJson` | N/A | Interface | | -| `AudioSegment` | N/A | Interface | | -| `AudioTranscriptionTask` | N/A | Alias | | -| `AzureChatEnhancementConfiguration`, `AzureChatEnhancements`, `AzureChatExtensionConfiguration`, `AzureChatExtensionConfigurationUnion`, `AzureChatExtensionDataSourceResponseCitation`, `AzureChatExtensionsMessageContext`, `AzureChatExtensionType`, `AzureChatGroundingEnhancementConfiguration`, `AzureChatOCREnhancementConfiguration`, `AzureCosmosDBChatExtensionConfiguration`, `AzureCosmosDBFieldMappingOptions`, `AzureExtensionsOptions`, `AzureGroundingEnhancement`, `AzureGroundingEnhancementCoordinatePoint`, `AzureGroundingEnhancementLine`, `AzureGroundingEnhancementLineSpan`, `AzureMachineLearningIndexChatExtensionConfiguration`, `AzureSearchChatExtensionConfiguration`, `AzureSearchIndexFieldMappingOptions`, `AzureSearchQueryType`, `ContentFilterBlocklistIdResult`, `ContentFilterCitedDetectionResult`, `ContentFilterDetectionResult`, `ContentFilterErrorResults`, `ContentFilterResult`, `ContentFilterResultDetailsForPrompt`, `ContentFilterResultsForChoice`, `ContentFilterSeverity`, `ContentFilterResultsForPrompt`, `ContentFilterSuccessResultDetailsForPrompt`, `ContentFilterSuccessResultsForChoice`, `ElasticsearchChatExtensionConfiguration`, `ElasticsearchIndexFieldMappingOptions`, `ElasticsearchQueryType`, `ImageGenerationContentFilterResults`, `ImageGenerationPromptFilterResults`, `OnYourDataAccessTokenAuthenticationOptions`, `OnYourDataApiKeyAuthenticationOptions`, `OnYourDataAuthenticationOptions`, `OnYourDataAuthenticationOptionsUnion`, `OnYourDataConnectionStringAuthenticationOptions`, `OnYourDataDeploymentNameVectorizationSource`, `OnYourDataEncodedApiKeyAuthenticationOptions`, `OnYourDataEndpointVectorizationSource`, `OnYourDataKeyAndKeyIdAuthenticationOptions`, `OnYourDataModelIdVectorizationSource`, `OnYourDataSystemAssignedManagedIdentityAuthenticationOptions`, `OnYourDataUserAssignedManagedIdentityAuthenticationOptions`, `OnYourDataVectorizationSource`, `OnYourDataVectorizationSourceType`, `OnYourDataVectorizationSourceUnion`, `PineconeChatExtensionConfiguration`, `PineconeFieldMappingOptions` | N/A | Interfaces and Aliases | See the Azure types section below | -| `AzureKeyCredential` | N/A | Class | The API key can be provided as a string value | -| `ChatChoice` | `ChatCompletion.Choice` | Interface | | -| `ChatChoiceLogProbabilityInfo` | `Logprobs` | Interface | | -| `ChatCompletions` | `ChatCompletion` and `ChatCompletionChunk` | Interface | | -| `ChatCompletionsFunctionToolCall` | `ChatCompletionMessageToolCall` | Interface | | -| `ChatRequestFunctionMessage` | `ChatCompletionFunctionMessageParam` | Interface | | -| `ChatRequestMessage` | `ChatCompletionMessageParam` | Interface | | -| `ChatRequestMessageUnion` | `ChatCompletionMessageParam` | | -| `ChatRequestSystemMessage` | `ChatCompletionSystemMessageParam` | Interface | | -| `ChatRequestToolMessage` | `ChatCompletionToolMessageParam` | Interface | | -| `ChatRequestUserMessage` | `ChatCompletionUserMessageParam` | Interface | | -| `ChatResponseMessage` | `Delta` / `ChatCompletionMessage` | Interface | | -| `ChatRole` | N/A | Alias | | -| `ChatTokenLogProbabilityInfo` | `TopLogprob` | Interface | | -| `ChatTokenLogProbabilityResult` | `ChatCompletionTokenLogprob` | Interface | | -| `Choice` | `Choice` | Interface | | -| `Completions` | `Completion` | Interface | | -| `CompletionsFinishReason` | N/A | Alias | | -| `CompletionsLogProbabilityModel` | `Logprobs` | Interface | | -| `CompletionsUsage` | `CompletionUsage` | Interface | | -| `EmbeddingItem` | `Embedding` | Interface | | -| `Embeddings` | `CreateEmbeddingResponse` | Interface | | -| `EmbeddingsUsage` | `CreateEmbeddingResponse.Usage` | Interface | | -| `EventStream` | `Stream` | Interface | | -| `FunctionCall` | `FunctionCall` | Interface | | -| `FunctionCallPreset` | N/A | Alias | | -| `FunctionDefinition` | `Function` | Interface | | -| `FunctionName` | N/A | Alias | | -| `GetAudioTranscriptionOptions` | `TranscriptionCreateParams` | Interface | | -| `GetAudioTranslationOptions` | `TranslationCreateParams` | Interface | | -| `GetChatCompletionsOptions` | `ChatCompletionCreateParamsNonStreaming` and `ChatCompletionCreateParamsStreaming` | Interface | | -| `GetCompletionsOptions` | `CompletionCreateParams` | Interface | | -| `GetEmbeddingsOptions` | `EmbeddingCreateParams` | Interface | | -| `GetImagesOptions` | `ImageGenerateParams` | Interface | | -| `ImageGenerationData` | `Image` | Interface | | -| `ImageGenerationQuality` | N/A | Alias | | -| `ImageGenerationResponseFormat` | N/A | Alias | | -| `ImageGenerations` | `ImagesResponse` | Interface | | -| `ImageGenerationStyle` | N/A | Alias | | -| `ImageSize` | N/A | Alias | | -| `MaxTokensFinishDetails` | N/A | Interface | | -| `OpenAIClientOptions` | `AzureClientOptions` | Interface | | -| `OpenAIError` | `OpenAIError` | Interface | | -| `OpenAIKeyCredential` | N/A | Class | | -| `StopFinishDetails` | N/A | Interface | | - -## Azure types - -`AzureOpenAI` connects to the Azure OpenAI service and can call all the operations available in the service. However, the types of the requests and responses are inherited from the `OpenAI` and are not yet updated to reflect the additional features supported exclusively by the Azure OpenAI service. TypeScript users will need to import `"@azure/openai/types"` from `@azure/openai@2.0.0-beta.1` which will merge Azure-specific definitions into existing types. Examples in [the Migration examples](#migration-examples) section show how to do this. diff --git a/sdk/openai/openai/README.md b/sdk/openai/openai/README.md deleted file mode 100644 index f13edda82293..000000000000 --- a/sdk/openai/openai/README.md +++ /dev/null @@ -1,260 +0,0 @@ -# Azure OpenAI library for TypeScript - -The [Azure OpenAI Service][service_overview] provides access to advanced AI models for conversational, content creation, and data grounding use cases. The Azure OpenAI library for TypeScript is a companion to the official [OpenAI client library for JavaScript][openai_pkg]. The Azure OpenAI library provides additional strongly typed support for request and response models specific to Azure OpenAI scenarios. - -#### **_Migrating from @azure/openai version 1 advisory_ ⚠️** - -Checkout the [Migration Guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/MIGRATION.md) for detailed instructions on how to update your application code from version 1.x of the Azure OpenAI client library to the `openai` library. - -Key links: - -- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/) -- [Package (NPM)](https://www.npmjs.com/package/@azure/openai) -- [API reference documentation](https://learn.microsoft.com/javascript/api/overview/azure/openai-readme) -- [Product documentation][service_overview] -- [Samples][samples_folder] - -## Getting started - -### Currently supported environments - -- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) -- Latest versions of Safari, Chrome, Edge, and Firefox. - -### Prerequisites - -If you'd like to use an Azure OpenAI resource, you must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) -and [Azure OpenAI access](https://learn.microsoft.com/azure/cognitive-services/openai/overview#how-do-i-get-access-to-azure-openai). For more information, see [Quickstart: Get started generating text using Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart). - -### Install both `openai` and `@azure/openai` - -Install the Azure OpenAI client library and the OpenAI library for JavaScript with `npm`: - -```bash -npm install openai @azure/openai -``` - -### Create and authenticate a `AzureOpenAI` - -There are several ways to authenticate with the Azure OpenAI service and the recommended way is to use Microsoft Entra ID for secure, keyless authentication via the [Azure Identity library][azure_identity]. To get started: - -1. Install the [Azure Identity package](https://www.npmjs.com/package/@azure/identity): - - ```bash - npm install @azure/identity - ``` - -2. Create a token provider by calling the `getBearerTokenProvider` with the desired credential type. For example, [DefaultAzureCredential][azure_identity_dac]: - - ```js - import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; - - const credential = new DefaultAzureCredential(); - const scope = "https://cognitiveservices.azure.com/.default"; - const azureADTokenProvider = getBearerTokenProvider(credential, scope); - ``` - -3. Create the client by passing in the token provider: - - ```js - import { AzureOpenAI } from "openai"; - - const deployment = "Your deployment name"; - const apiVersion = "2024-07-01-preview"; - const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); - ``` - -Grant access to your Azure OpenAI resource to your trusted entities by following instructions in [How to configure Azure OpenAI Service with Microsoft Entra ID authentication](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity). - -## Key concepts - -### Assistants - -See [OpenAI's Assistants API overview](https://platform.openai.com/docs/assistants/overview). - -### Audio transcription/translation and text-to-speech generation - -See [OpenAI Capabilities: Speech to text](https://platform.openai.com/docs/guides/speech-to-text/speech-to-text). - -### Batch - -See [OpenAI's Batch API guide](https://platform.openai.com/docs/guides/batch). - -### Chat completion - -Chat models take a list of messages as input and return a model-generated message as output. Although the chat format is -designed to make multi-turn conversations easy, it's also useful for single-turn tasks without any conversation. - -See [OpenAI Capabilities: Chat completion](https://platform.openai.com/docs/guides/text-generation/chat-completions-api). - -### Image generation - -See [OpenAI Capabilities: Image generation](https://platform.openai.com/docs/guides/images/introduction). - -### Files - -See [OpenAI's Files API reference](https://platform.openai.com/docs/api-reference/files). - -### Text embeddings - -See [OpenAI Capabilities: Embeddings](https://platform.openai.com/docs/guides/embeddings/embeddings). - -## Examples - -This section provides examples of using the features of the Azure OpenAI Service. For additional examples, checkout the [samples folder][samples_folder]. - -### Analyze Business Data - -This TypeScript example generates chat responses to input chat questions about your business data. The business data is provided through an Azure Cognitive Search index. To learn more about how to setup an Azure Cognitive Search index as a data source, see Quickstart: [Chat with Azure OpenAI models using your own data][oyd]. - -```ts -import { AzureOpenAI } from "openai"; -import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; -import "@azure/openai/types"; - -// Set AZURE_OPENAI_ENDPOINT to the endpoint of your -// Azure OpenAI resource. You can find this in the Azure portal. -import "dotenv/config"; - -// Your Azure Cognitive Search endpoint, and index name -const azureSearchEndpoint = process.env["AZURE_SEARCH_ENDPOINT"] || ""; -const azureSearchIndexName = process.env["AZURE_SEARCH_INDEX"] || ""; - -export async function main() { - console.log("== Azure On Your Data Sample =="); - - const scope = "https://cognitiveservices.azure.com/.default"; - const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); - const deployment = "gpt-4-1106-preview"; - const apiVersion = "2024-07-01-preview"; - const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); - const events = await client.chat.completions.create({ - stream: true, - messages: [ - { - role: "user", - content: - "What's the most common feedback we received from our customers about the product?", - }, - ], - max_tokens: 128, - model: "", - data_sources: [ - { - type: "azure_search", - parameters: { - endpoint: azureSearchEndpoint, - index_name: azureSearchIndexName, - authentication: { - type: "system_assigned_managed_identity", - }, - }, - }, - ], - }); - - for await (const event of events) { - for (const choice of event.choices) { - console.log(choice.delta?.content); - } - } -} - -main(); -``` - -### Content-filtered Chat Completions - -Azure OpenAI Service includes a content filtering system that works alongside core models. This system detects and takes action on specific categories of potentially harmful content in both input prompts and output completions. This example shows how to access those content filtering results. - -```ts -import { AzureOpenAI } from "openai"; -import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; -import "@azure/openai/types"; - -// Set AZURE_OPENAI_ENDPOINT to the endpoint of your -// OpenAI resource. You can find this in the Azure portal. -import "dotenv/config"; - -async function main() { - console.log("== Streaming Chat Completions Sample =="); - - const scope = "https://cognitiveservices.azure.com/.default"; - const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); - const deployment = "gpt-35-turbo"; - const apiVersion = "2024-07-01-preview"; - const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); - const events = await client.chat.completions.create({ - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, - { role: "user", content: "Can you help me?" }, - { role: "assistant", content: "Arrrr! Of course, me hearty! What can I do for ye?" }, - { role: "user", content: "What's the best way to train a parrot?" }, - ], - model: "", - max_tokens: 128, - stream: true, - }); - - for await (const event of events) { - for (const choice of event.choices) { - console.log(`Chunk: ${choice.delta?.content}`); - const filterResults = choice.content_filter_results; - if (!filterResults) { - continue; - } - if (filterResults.error) { - console.log( - `\tContent filter ran into an error ${filterResults.error.code}: ${filterResults.error.message}`, - ); - } else { - const { hate, sexual, selfHarm, violence } = filterResults; - console.log( - `\tHate category is filtered: ${hate?.filtered}, with ${hate?.severity} severity`, - ); - console.log( - `\tSexual category is filtered: ${sexual?.filtered}, with ${sexual?.severity} severity`, - ); - console.log( - `\tSelf-harm category is filtered: ${selfHarm?.filtered}, with ${selfHarm?.severity} severity`, - ); - console.log( - `\tViolence category is filtered: ${violence?.filtered}, with ${violence?.severity} severity`, - ); - } - } - } -} - -main(); -``` - -## Next steps - -## Troubleshooting - -Refer to the official [OpenAI client library for JavaScript][openai_pkg_readme]. - -## Contributing - -See the [OpenAI CONTRIBUTING.md][openai_contrib] for details on building, testing, and contributing to this library. - -This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. - -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information, see the [Code of Conduct FAQ][code_of_conduct_faq] or contact [opencode@microsoft.com][email_opencode] with any additional questions or comments. - - -[openai_pkg]: https://www.npmjs.com/package/openai -[service_overview]: https://azure.microsoft.com/products/ai-services/openai-service -[azure_identity]: https://learn.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest -[azure_identity_dac]: https://learn.microsoft.com/javascript/api/@azure/identity/defaultazurecredential?view=azure-node-latest -[oyd]: https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart -[samples_folder]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/samples -[openai_pkg_readme]: https://github.com/openai/openai-node/blob/master/README.md -[cla]: https://cla.microsoft.com -[openai_contrib]: https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md -[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ -[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ -[email_opencode]: mailto:opencode@microsoft.com diff --git a/sdk/openai/openai/api-extractor.json b/sdk/openai/openai/api-extractor.json deleted file mode 100644 index cbf75608dfdc..000000000000 --- a/sdk/openai/openai/api-extractor.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "dist/esm/index.d.ts", - "docModel": { - "enabled": true - }, - "apiReport": { - "enabled": true, - "reportFolder": "./review" - }, - "dtsRollup": { - "enabled": true, - "untrimmedFilePath": "", - "publicTrimmedFilePath": "dist/openai.d.ts" - }, - "messages": { - "tsdocMessageReporting": { - "default": { - "logLevel": "none" - } - }, - "extractorMessageReporting": { - "ae-missing-release-tag": { - "logLevel": "none" - }, - "ae-unresolved-link": { - "logLevel": "none" - } - } - } -} diff --git a/sdk/openai/openai/assets.json b/sdk/openai/openai/assets.json deleted file mode 100644 index dc9b29f7cf9a..000000000000 --- a/sdk/openai/openai/assets.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "js", - "TagPrefix": "js/openai/openai", - "Tag": "js/openai/openai_4baca95ece" -} diff --git a/sdk/openai/openai/assets/audio/countdown.mp3 b/sdk/openai/openai/assets/audio/countdown.mp3 deleted file mode 100644 index 95d2a332d5cd..000000000000 Binary files a/sdk/openai/openai/assets/audio/countdown.mp3 and /dev/null differ diff --git a/sdk/openai/openai/assets/audio/countdown.mp4 b/sdk/openai/openai/assets/audio/countdown.mp4 deleted file mode 100644 index 6c695af9b85e..000000000000 Binary files a/sdk/openai/openai/assets/audio/countdown.mp4 and /dev/null differ diff --git a/sdk/openai/openai/eslint.config.mjs b/sdk/openai/openai/eslint.config.mjs deleted file mode 100644 index 79f0d75d9796..000000000000 --- a/sdk/openai/openai/eslint.config.mjs +++ /dev/null @@ -1,15 +0,0 @@ -import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; - -export default [ - ...azsdkEslint.configs.recommended, - { - rules: { - "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", - "@azure/azure-sdk/ts-package-json-module": "off", - "@azure/azure-sdk/ts-package-json-main-is-cjs": "off", - "@azure/azure-sdk/ts-package-json-types": "off", - "@azure/azure-sdk/ts-package-json-files-required": "off", - "no-restricted-imports": "warn", - }, - }, -]; diff --git a/sdk/openai/openai/package.json b/sdk/openai/openai/package.json deleted file mode 100644 index 9d9739542a56..000000000000 --- a/sdk/openai/openai/package.json +++ /dev/null @@ -1,147 +0,0 @@ -{ - "name": "@azure/openai", - "version": "2.0.0-beta.3", - "description": "A companion library to openai for Azure OpenAI.", - "sdk-type": "client", - "main": "./dist/commonjs/index.js", - "browser": "./dist/browser/index.js", - "types": "./dist/commonjs/index.d.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "browser": { - "types": "./dist/browser/index.d.ts", - "default": "./dist/browser/index.js" - }, - "import": { - "types": "./dist/esm/index.d.ts", - "default": "./dist/esm/index.js" - }, - "require": { - "types": "./dist/commonjs/index.d.ts", - "default": "./dist/commonjs/index.js" - } - }, - "./types": { - "browser": { - "types": "./dist/browser/types/index.d.ts", - "default": "./dist/browser/types/index.js" - }, - "import": { - "types": "./dist/esm/types/index.d.ts", - "default": "./dist/esm/types/index.js" - }, - "require": { - "types": "./dist/commonjs/types/index.d.ts", - "default": "./dist/commonjs/types/index.js" - } - } - }, - "files": [ - "dist/", - "README.md", - "LICENSE" - ], - "tshy": { - "exports": { - "./package.json": "./package.json", - ".": "./src/index.ts", - "./types": "./src/types/index.ts" - }, - "dialects": [ - "esm", - "commonjs" - ], - "esmDialects": [ - "browser" - ], - "selfLink": false - }, - "scripts": { - "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", - "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", - "build:samples": "echo Obsolete", - "build:test": "dev-tool run build-package && dev-tool run build-test", - "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", - "clean": "rimraf --glob dist dist-* temp types *.tgz *.log", - "execute:samples": "dev-tool samples run samples-dev", - "extract-api": "dev-tool run build-package && dev-tool run extract-api", - "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", - "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:browser": "dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --no-test-proxy --browser", - "integration-test:node": "dev-tool run test:vitest --no-test-proxy", - "lint": "eslint README.md package.json api-extractor.json src", - "lint:fix": "eslint README.md package.json api-extractor.json src --fix --fix-type [problem,suggestion]", - "pack": "npm pack 2>&1", - "test": "npm run clean && dev-tool run build-package && npm run unit-test:node && dev-tool run build-test && npm run unit-test:browser && npm run integration-test", - "test:browser": "npm run clean && npm run build:test && npm run integration-test:browser", - "test:node": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run integration-test:node", - "unit-test": "npm run unit-test:node && npm run unit-test:browser", - "unit-test:browser": "echo skipped", - "unit-test:node": "echo skipped", - "update-snippets": "echo skipped" - }, - "repository": "github:Azure/azure-sdk-for-js", - "engines": { - "node": ">=18.0.0" - }, - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic", - "openai", - "ai" - ], - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/README.md", - "sideEffects": false, - "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", - "devDependencies": { - "@azure-tools/test-credential": "^2.0.0", - "@azure-tools/test-recorder": "^4.1.0", - "@azure-tools/test-utils-vitest": "^1.0.0", - "@azure/arm-cognitiveservices": "^7.5.0", - "@azure/core-rest-pipeline": "^1.16.2", - "@azure/core-util": "^1.9.1", - "@azure/dev-tool": "^1.0.0", - "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@azure/identity": "^4.2.0", - "@azure/logger": "^1.1.3", - "@microsoft/api-extractor": "^7.31.1", - "@types/node": "^18.0.0", - "@vitest/browser": "^2.0.4", - "@vitest/coverage-istanbul": "^2.0.4", - "cross-env": "^7.0.3", - "dotenv": "^16.0.0", - "eslint": "^9.9.0", - "openai": "^4.47.2", - "playwright": "^1.45.3", - "rimraf": "^3.0.2", - "typescript": "~5.6.2", - "vitest": "^2.0.4" - }, - "dependencies": { - "@azure-rest/core-client": "^2.2.0", - "tslib": "^2.6.3" - }, - "//sampleConfiguration": { - "productName": "Azure OpenAI", - "productSlugs": [ - "azure", - "azure-cognitive-services", - "azure-openai" - ], - "requiredResources": { - "Azure Cognitive Services instance": "https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource" - } - }, - "type": "module", - "module": "./dist/esm/index.js" -} diff --git a/sdk/openai/openai/review/openai-types.api.md b/sdk/openai/openai/review/openai-types.api.md deleted file mode 100644 index 04847ef6784e..000000000000 --- a/sdk/openai/openai/review/openai-types.api.md +++ /dev/null @@ -1,434 +0,0 @@ -## API Report File for "@azure/openai" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import type { ChatCompletion } from 'openai/resources/index'; -import type { ChatCompletionChunk } from 'openai/resources/index'; -import type { ChatCompletionCreateParamsNonStreaming } from 'openai/resources/index'; -import type { ChatCompletionCreateParamsStreaming } from 'openai/resources/index'; -import type { ChatCompletionMessage } from 'openai/resources/index'; -import type { Completion } from 'openai/resources/index'; -import type { CompletionCreateParamsNonStreaming } from 'openai/resources/index'; -import type { CompletionCreateParamsStreaming } from 'openai/resources/index'; -import type { ErrorModel } from '@azure-rest/core-client'; - -// @public -export interface AzureChatEnhancementConfiguration { - grounding?: AzureChatGroundingEnhancementConfiguration; - ocr?: AzureChatOCREnhancementConfiguration; -} - -// @public -export interface AzureChatEnhancementsOutput { - grounding?: AzureGroundingEnhancementOutput; -} - -// @public -export type AzureChatExtensionConfiguration = AzureChatExtensionConfigurationParent | AzureSearchChatExtensionConfiguration | AzureMachineLearningIndexChatExtensionConfiguration | AzureCosmosDBChatExtensionConfiguration | ElasticsearchChatExtensionConfiguration | PineconeChatExtensionConfiguration; - -// @public -export interface AzureChatExtensionConfigurationParent { - type: string; -} - -// @public -export interface AzureChatExtensionDataSourceResponseCitationOutput { - chunk_id?: string; - content: string; - filepath?: string; - title?: string; - url?: string; -} - -// @public -export interface AzureChatExtensionsMessageContextOutput { - citations?: Array; - intent?: string; -} - -// @public -export interface AzureChatExtensionsMessageContextOutput { - citations?: Array; - intent?: string; -} - -// @public -export interface AzureChatGroundingEnhancementConfiguration { - enabled: boolean; -} - -// @public -export interface AzureChatOCREnhancementConfiguration { - enabled: boolean; -} - -// @public -export interface AzureCosmosDBChatExtensionConfiguration extends AzureChatExtensionConfigurationParent { - parameters: AzureCosmosDBChatExtensionParameters; - type: "azure_cosmos_db"; -} - -// @public -export interface AzureCosmosDBChatExtensionParameters { - authentication?: OnYourDataAuthenticationOptions; - container_name: string; - database_name: string; - embedding_dependency: OnYourDataVectorizationSource; - fields_mapping: AzureCosmosDBFieldMappingOptions; - in_scope?: boolean; - index_name: string; - role_information?: string; - strictness?: number; - top_n_documents?: number; -} - -// @public -export interface AzureCosmosDBFieldMappingOptions { - content_fields: string[]; - content_fields_separator?: string; - filepath_field?: string; - title_field?: string; - url_field?: string; - vector_fields: string[]; -} - -// @public -export interface AzureGroundingEnhancementCoordinatePointOutput { - x: number; - y: number; -} - -// @public -export interface AzureGroundingEnhancementCoordinatePointOutput { - x: number; - y: number; -} - -// @public -export interface AzureGroundingEnhancementLineOutput { - spans: Array; - text: string; -} - -// @public -export interface AzureGroundingEnhancementLineOutput { - spans: Array; - text: string; -} - -// @public -export interface AzureGroundingEnhancementLineSpanOutput { - length: number; - offset: number; - polygon: Array; - text: string; -} - -// @public -export interface AzureGroundingEnhancementLineSpanOutput { - length: number; - offset: number; - polygon: Array; - text: string; -} - -// @public -export interface AzureGroundingEnhancementOutput { - lines: Array; -} - -// @public -export interface AzureGroundingEnhancementOutput { - lines: Array; -} - -// @public -export interface AzureMachineLearningIndexChatExtensionConfiguration extends AzureChatExtensionConfigurationParent { - parameters: AzureMachineLearningIndexChatExtensionParameters; - type: "azure_ml_index"; -} - -// @public -export interface AzureMachineLearningIndexChatExtensionParameters { - authentication?: OnYourDataAuthenticationOptions; - filter?: string; - in_scope?: boolean; - name: string; - project_resource_id: string; - role_information?: string; - strictness?: number; - top_n_documents?: number; - version: string; -} - -// @public -export interface AzureSearchChatExtensionConfiguration extends AzureChatExtensionConfigurationParent { - parameters: AzureSearchChatExtensionParameters; - type: "azure_search"; -} - -// @public -export interface AzureSearchChatExtensionParameters { - authentication?: OnYourDataAuthenticationOptions; - embedding_dependency?: OnYourDataVectorizationSource; - endpoint: string; - fields_mapping?: AzureSearchIndexFieldMappingOptions; - filter?: string; - in_scope?: boolean; - index_name: string; - query_type?: string; - role_information?: string; - semantic_configuration?: string; - strictness?: number; - top_n_documents?: number; -} - -// @public -export interface AzureSearchIndexFieldMappingOptions { - content_fields?: string[]; - content_fields_separator?: string; - filepath_field?: string; - image_vector_fields?: string[]; - title_field?: string; - url_field?: string; - vector_fields?: string[]; -} - -export { ChatCompletion } - -export { ChatCompletionChunk } - -export { ChatCompletionCreateParamsNonStreaming } - -export { ChatCompletionCreateParamsStreaming } - -export { ChatCompletionMessage } - -// @public -export type ChatFinishDetailsOutput = ChatFinishDetailsOutputParent | StopFinishDetailsOutput | MaxTokensFinishDetailsOutput; - -// @public -export interface ChatFinishDetailsOutputParent { - type: string; -} - -export { Completion } - -export { CompletionCreateParamsNonStreaming } - -export { CompletionCreateParamsStreaming } - -// @public -export interface ContentFilterBlocklistIdResultOutput { - filtered: boolean; - id: string; -} - -// @public -export interface ContentFilterCitedDetectionResultOutput { - detected: boolean; - filtered: boolean; - license?: string; - URL?: string; -} - -// @public -export interface ContentFilterDetailedResults { - details: ContentFilterBlocklistIdResultOutput[]; - filtered: boolean; -} - -// @public -export interface ContentFilterDetectionResultOutput { - detected: boolean; - filtered: boolean; -} - -// @public -export interface ContentFilterResultDetailsForPromptOutput { - custom_blocklists?: ContentFilterDetailedResults; - error?: ErrorModel; - hate?: ContentFilterResultOutput; - jailbreak?: ContentFilterDetectionResultOutput; - profanity?: ContentFilterDetectionResultOutput; - self_harm?: ContentFilterResultOutput; - sexual?: ContentFilterResultOutput; - violence?: ContentFilterResultOutput; -} - -// @public -export interface ContentFilterResultOutput { - filtered: boolean; - severity: string; -} - -// @public -export interface ContentFilterResultsForChoiceOutput { - custom_blocklists?: ContentFilterDetailedResults; - error?: ErrorModel; - hate?: ContentFilterResultOutput; - profanity?: ContentFilterDetectionResultOutput; - protected_material_code?: ContentFilterCitedDetectionResultOutput; - protected_material_text?: ContentFilterDetectionResultOutput; - self_harm?: ContentFilterResultOutput; - sexual?: ContentFilterResultOutput; - violence?: ContentFilterResultOutput; -} - -// @public -export interface ContentFilterResultsForPromptOutput { - content_filter_results: ContentFilterResultDetailsForPromptOutput; - prompt_index: number; -} - -// @public -export interface ElasticsearchChatExtensionConfiguration extends AzureChatExtensionConfigurationParent { - parameters: ElasticsearchChatExtensionParameters; - type: "elasticsearch"; -} - -// @public -export interface ElasticsearchChatExtensionParameters { - authentication?: OnYourDataAuthenticationOptions; - embedding_dependency?: OnYourDataVectorizationSource; - endpoint: string; - fields_mapping?: ElasticsearchIndexFieldMappingOptions; - in_scope?: boolean; - index_name: string; - query_type?: string; - role_information?: string; - strictness?: number; - top_n_documents?: number; -} - -// @public -export interface ElasticsearchIndexFieldMappingOptions { - content_fields?: string[]; - content_fields_separator?: string; - filepath_field?: string; - title_field?: string; - url_field?: string; - vector_fields?: string[]; -} - -// @public -export interface MaxTokensFinishDetailsOutput extends ChatFinishDetailsOutputParent { - type: "max_tokens"; -} - -// @public -export interface OnYourDataAccessTokenAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - access_token: string; - type: "access_token"; -} - -// @public -export interface OnYourDataApiKeyAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - key: string; - type: "api_key"; -} - -// @public -export type OnYourDataAuthenticationOptions = OnYourDataAuthenticationOptionsParent | OnYourDataApiKeyAuthenticationOptions | OnYourDataConnectionStringAuthenticationOptions | OnYourDataKeyAndKeyIdAuthenticationOptions | OnYourDataEncodedApiKeyAuthenticationOptions | OnYourDataAccessTokenAuthenticationOptions | OnYourDataSystemAssignedManagedIdentityAuthenticationOptions | OnYourDataUserAssignedManagedIdentityAuthenticationOptions; - -// @public -export interface OnYourDataAuthenticationOptionsParent { - type: string; -} - -// @public -export interface OnYourDataConnectionStringAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - connection_string: string; - type: "connection_string"; -} - -// @public -export interface OnYourDataDeploymentNameVectorizationSource extends OnYourDataVectorizationSourceParent { - deployment_name: string; - type: "deployment_name"; -} - -// @public -export interface OnYourDataEncodedApiKeyAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - encoded_api_key: string; - type: "encoded_api_key"; -} - -// @public -export interface OnYourDataEndpointVectorizationSource extends OnYourDataVectorizationSourceParent { - authentication: OnYourDataAuthenticationOptions; - endpoint: string; - type: "endpoint"; -} - -// @public -export interface OnYourDataKeyAndKeyIdAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - key: string; - key_id: string; - type: "key_and_key_id"; -} - -// @public -export interface OnYourDataModelIdVectorizationSource extends OnYourDataVectorizationSourceParent { - model_id: string; - type: "model_id"; -} - -// @public -export interface OnYourDataSystemAssignedManagedIdentityAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - type: "system_assigned_managed_identity"; -} - -// @public -export interface OnYourDataUserAssignedManagedIdentityAuthenticationOptions extends OnYourDataAuthenticationOptionsParent { - managed_identity_resource_id: string; - type: "user_assigned_managed_identity"; -} - -// @public -export type OnYourDataVectorizationSource = OnYourDataVectorizationSourceParent | OnYourDataEndpointVectorizationSource | OnYourDataDeploymentNameVectorizationSource | OnYourDataModelIdVectorizationSource; - -// @public -export interface OnYourDataVectorizationSourceParent { - type: string; -} - -// @public -export interface PineconeChatExtensionConfiguration extends AzureChatExtensionConfigurationParent { - parameters: PineconeChatExtensionParameters; - type: "Pinecone"; -} - -// @public -export interface PineconeChatExtensionParameters { - authentication?: OnYourDataAuthenticationOptions; - embedding_dependency: OnYourDataVectorizationSource; - environment: string; - fields_mapping: PineconeFieldMappingOptions; - in_scope?: boolean; - index_name: string; - role_information?: string; - strictness?: number; - top_n_documents?: number; -} - -// @public -export interface PineconeFieldMappingOptions { - content_fields: string[]; - content_fields_separator?: string; - filepath_field?: string; - title_field?: string; - url_field?: string; -} - -// @public -export interface StopFinishDetailsOutput extends ChatFinishDetailsOutputParent { - stop: string; - type: "stop"; -} - -// (No @packageDocumentation comment for this package) - -``` diff --git a/sdk/openai/openai/review/openai.api.md b/sdk/openai/openai/review/openai.api.md deleted file mode 100644 index 2c38085363d6..000000000000 --- a/sdk/openai/openai/review/openai.api.md +++ /dev/null @@ -1,9 +0,0 @@ -## API Report File for "@azure/openai" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -// (No @packageDocumentation comment for this package) - -``` diff --git a/sdk/openai/openai/sample.env b/sdk/openai/openai/sample.env deleted file mode 100644 index 3e67622c4cf9..000000000000 --- a/sdk/openai/openai/sample.env +++ /dev/null @@ -1,3 +0,0 @@ -# Used to authenticate with the Azure OpenAI. Retrieve these -# values from an Azure OpenAI instance in the Azure Portal. -AZURE_OPENAI_ENDPOINT="https://.openai.azure.com" \ No newline at end of file diff --git a/sdk/openai/openai/samples-dev/audioTranscription.ts b/sdk/openai/openai/samples-dev/audioTranscription.ts deleted file mode 100644 index d9eb05325d55..000000000000 --- a/sdk/openai/openai/samples-dev/audioTranscription.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * Demonstrates how to transcribe the content of an audio file. - * - * @summary audio transcription. - * @azsdk-weight 100 - */ - -import { AzureOpenAI } from "openai"; -import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; -import { createReadStream } from "fs"; - -// Set AZURE_OPENAI_ENDPOINT to the endpoint of your -// OpenAI resource. You can find this in the Azure portal. -// Load the .env file if it exists -import "dotenv/config"; - -// You will need to set these environment variables or edit the following values -const audioFilePath = process.env["AUDIO_FILE_PATH"] || "