Skip to content

Latest commit

 

History

History
111 lines (82 loc) · 6.06 KB

functions-bindings-openai.md

File metadata and controls

111 lines (82 loc) · 6.06 KB
titledescriptionms.topicms.customms.collectionms.datezone_pivot_groups
Azure OpenAI extension for Azure Functions
Learn to configure the Azure OpenAI extension to be able to integrate your Azure Functions code executions with Azure OpenAI APIs.
reference
build-2024
devx-track-extended-java
devx-track-js
devx-track-python
devx-track-ts
ce-skilling-ai-copilot
05/14/2024
programming-languages-set-functions

Azure OpenAI extension for Azure Functions

[!INCLUDE preview-support]

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:

ActionTrigger/binding type
Use a standard text prompt for content completionAzure OpenAI text completion input binding
Respond to an assistant request to call a functionAzure OpenAI assistant trigger
Create an assistantAzure OpenAI assistant create output binding
Message an assistantAzure OpenAI assistant post input binding
Get assistant historyAzure OpenAI assistant query input binding
Read text embeddingsAzure OpenAI embeddings input binding
Write to a vector databaseAzure OpenAI embeddings store output binding
Read from a vector databaseAzure OpenAI semantic search input binding

::: zone pivot="programming-language-csharp"

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:

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

dotnet add package Microsoft.Azure.WebJobs.Extensions.OpenAI --prerelease 

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


::: zone-end ::: zone pivot="programming-language-java,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"

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)" } }

::: zone-end

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 nameDescription
AZURE_OPENAI_ENDPOINTRequired. Sets the endpoint of the OpenAI resource used by your bindings.
AZURE_OPENAI_KEYSets the key used to access an Azure OpenAI resource.
OPENAI_API_KEYSets the key used to access a non-Azure OpenAI resource.
AZURE_CLIENT_IDSets a user-assigned managed identity used to access the Azure OpenAI resource.

For more information, see Work with application settings.

Related content

close