azure

package
v0.1.0-alpha.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package azure provides configuration options so you can connect and use Azure OpenAI using the [openai.Client].

Typical usage of this package will look like this:

client := openai.NewClient(
	azure.WithEndpoint(azureOpenAIEndpoint, azureOpenAIAPIVersion),
	azure.WithTokenCredential(azureIdentityTokenCredential),
	// or azure.WithAPIKey(azureOpenAIAPIKey),
)

Or, if you want to construct a specific service:

client := openai.NewChatCompletionService(
	azure.WithEndpoint(azureOpenAIEndpoint, azureOpenAIAPIVersion),
	azure.WithTokenCredential(azureIdentityTokenCredential),
	// or azure.WithAPIKey(azureOpenAIAPIKey),
)
Example (Authentication)
// There are two ways to authenticate - using a TokenCredential (via the azidentity
// package), or using an API Key.
const azureOpenAIEndpoint = "https://<your-azureopenai-instance>.openai.azure.com"
const azureOpenAIAPIVersion = "<api version string>"

// Using a TokenCredential
{
	// For a full list of credential types look at the documentation for the Azure Identity
	// package: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity
	tokenCredential, err := azidentity.NewDefaultAzureCredential(nil)

	if err != nil {
		fmt.Printf("Failed to create TokenCredential: %s\n", err)
		return
	}

	client := openai.NewClient(
		azure.WithEndpoint(azureOpenAIEndpoint, azureOpenAIAPIVersion),
		azure.WithTokenCredential(tokenCredential),
	)

	_ = client
}

// Using an API Key
{
	const azureOpenAIAPIKey = "<key from Azure portal>"

	client := openai.NewClient(
		azure.WithEndpoint(azureOpenAIEndpoint, azureOpenAIAPIVersion),
		azure.WithAPIKey(azureOpenAIAPIKey),
	)

	_ = client
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAPIKey

func WithAPIKey(apiKey string) option.RequestOption

WithAPIKey configures this client to authenticate using an API key. This function should be paired with a call to WithEndpoint to point to your Azure OpenAI instance.

func WithEndpoint

func WithEndpoint(endpoint string, apiVersion string) option.RequestOption

WithEndpoint configures this client to connect to an Azure OpenAI endpoint.

  • endpoint - the Azure OpenAI endpoint to connect to. Ex: https://<azure-openai-resource>.openai.azure.com
  • apiVersion - the Azure OpenAI API version to target (ex: 2024-06-01). See Azure OpenAI apiversions for current API versions. This value cannot be empty.

This function should be paired with a call to authenticate, like azure.WithAPIKey or azure.WithTokenCredential, similar to this:

client := openai.NewClient(
	azure.WithEndpoint(azureOpenAIEndpoint, azureOpenAIAPIVersion),
	azure.WithTokenCredential(azureIdentityTokenCredential),
	// or azure.WithAPIKey(azureOpenAIAPIKey),
)

func WithTokenCredential

func WithTokenCredential(tokenCredential azcore.TokenCredential) option.RequestOption

WithTokenCredential configures this client to authenticate using an Azure Identity TokenCredential. This function should be paired with a call to WithEndpoint to point to your Azure OpenAI instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL