Επεξεργασία

Κοινή χρήση μέσω


Azure OpenAI extension for Azure Functions

Important

The Azure OpenAI extension for Azure Functions is currently in preview.

The Azure OpenAI extension for Azure Functions implements a set of triggers and bindings that enable you to easily integrate features and behaviors of Azure OpenAI Service into your function code executions.

Azure Functions is an event-driven compute service that provides a set of triggers and bindings to easily connect with other Azure services.

With the integration between Azure OpenAI and Functions, you can build functions that can:

Action Trigger/binding type
Use a standard text prompt for content completion Azure OpenAI text completion input binding
Respond to an assistant request to call a function Azure OpenAI assistant trigger
Create an assistant Azure OpenAI assistant create output binding
Message an assistant Azure OpenAI assistant post input binding
Get assistant history Azure OpenAI assistant query input binding
Read text embeddings Azure OpenAI embeddings input binding
Write to a vector database Azure OpenAI embeddings store output binding
Read from a vector database Azure OpenAI semantic search input binding

Install extension

The extension NuGet package you install depends on the C# mode in-process or isolated worker process you're using in your function app:

Add the Azure OpenAI extension to your project by installing the Microsoft.Azure.Functions.Worker.Extensions.OpenAI NuGet package, which you can do using the .NET CLI:

dotnet add package Microsoft.Azure.Functions.Worker.Extensions.OpenAI  --prerelease

When using a vector database for storing content, you should also install at least one of these NuGet packages:

Install bundle

You can add the preview extension by adding or replacing the following code in your host.json file, which specifically targets a preview version of the 4.x bundle that contains the OpenAI extension:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
    "version": "[4.*, 5.0.0)"
  }
}

Application settings

To use the Azure OpenAI binding extension, you need to add one or more of these settings, which are used to connect to your OpenAI resource. During local development, you also need to add these settings to your local.settings.json file.

Setting name Description
AZURE_OPENAI_ENDPOINT Required. Sets the endpoint of the OpenAI resource used by your bindings.
AZURE_OPENAI_KEY Sets the key used to access an Azure OpenAI resource.
OPENAI_API_KEY Sets the key used to access a non-Azure OpenAI resource.
AZURE_CLIENT_ID Sets a user-assigned managed identity used to access the Azure OpenAI resource.

For more information, see Work with application settings.