or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai@v0.9.0
tile.json

tessl/golang-github-com-azure-azure-sdk-for-go-sdk-ai-azopenai

tessl install tessl/golang-github-com-azure-azure-sdk-for-go-sdk-ai-azopenai@0.9.0

Azure OpenAI extensions module for Go providing models and convenience functions to simplify integration with Azure OpenAI features.

index.mddocs/

Azure OpenAI Extensions for Go (azopenai)

The Azure OpenAI extensions module for Go provides models and convenience functions to simplify integration with Azure-specific OpenAI features when using the OpenAI Go client. It enables developers to leverage Azure-specific extensions such as Azure OpenAI On Your Data, content filtering, and chat completions extensions.

Package Information

  • Package Name: azopenai
  • Package Type: golang
  • Language: Go
  • Installation: go get github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai
  • Import Path: github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai
  • Minimum Go Version: 1.21+

Core Imports

import (
    "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/azure"
)

Basic Usage

The azopenai package is designed to work alongside the OpenAI Go client, adding Azure-specific capabilities. Here's a basic example:

import (
    "context"
    "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/azure"
)

// Create Azure OpenAI client
credential, err := azidentity.NewDefaultAzureCredential(nil)
client := openai.NewClient(
    azure.WithEndpoint("https://your-resource.openai.azure.com", "2024-08-01-preview"),
    azure.WithTokenCredential(credential),
)

// Make a chat completion request
resp, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
    Model: openai.ChatModel("your-deployment-name"),
    Messages: []openai.ChatCompletionMessageParamUnion{{
        OfUser: &openai.ChatCompletionUserMessageParam{
            Content: openai.ChatCompletionUserMessageParamContentUnion{
                OfString: openai.String("Hello!"),
            },
        },
    }},
})

Capabilities

Azure OpenAI On Your Data (RAG)

Configure Azure OpenAI to retrieve information from your own data sources during chat completions, enabling retrieval-augmented generation (RAG) scenarios.

func WithDataSources(dataSources ...AzureChatExtensionConfigurationClassification) option.RequestOption

The WithDataSources function adds Azure data sources to chat completion requests. Supported data sources include:

  • Azure AI Search (Cognitive Search)
  • Azure Cosmos DB for MongoDB vCore
  • Elasticsearch
  • MongoDB
  • Pinecone

Azure OpenAI On Your Data Documentation

Content Filtering

Access Azure OpenAI's content filtering capabilities to detect and handle potentially harmful content in prompts and completions.

func ExtractContentFilterError(err error, contentFilterErr **ContentFilterError) bool

Content filtering provides detection and severity ratings for:

  • Hate speech
  • Sexual content
  • Violence
  • Self-harm
  • Profanity
  • Jailbreak attempts
  • Custom blocklists

Content Filtering Documentation

Enhancements (OCR and Grounding)

Configure Azure-specific enhancements for chat completions, including optical character recognition (OCR) and grounding.

func WithEnhancements(config AzureChatEnhancementConfiguration) option.RequestOption

type AzureChatEnhancementConfiguration struct {
    Grounding *AzureChatGroundingEnhancementConfiguration
    Ocr       *AzureChatOCREnhancementConfiguration
}

The WithEnhancements function adds OCR and grounding capabilities to chat requests, enabling image text extraction and bounding box detection for identified objects.

Response Wrappers

The package provides wrapper types that add Azure-specific methods to OpenAI response types:

type ChatCompletion openai.ChatCompletion
type ChatCompletionChoice openai.ChatCompletionChoice
type ChatCompletionMessage openai.ChatCompletionMessage
type ChatCompletionChunk openai.ChatCompletionChunk
type ChatCompletionChunkChoiceDelta openai.ChatCompletionChunkChoiceDelta
type Completion openai.Completion
type CompletionChoice openai.CompletionChoice

These wrappers provide methods to access Azure-specific data like content filtering results and chat extension context.

Authentication

The azopenai package supports multiple authentication methods for data sources and vectorization endpoints:

  • API Key Authentication
  • Access Token Authentication
  • Connection String Authentication
  • System-Assigned Managed Identity
  • User-Assigned Managed Identity
  • Elasticsearch Key and Key ID
  • Username and Password

Authentication Documentation

Type Definitions

The package includes comprehensive type definitions for all Azure OpenAI extension configurations and response data.

Type Definitions Documentation

Key Concepts

Azure OpenAI On Your Data: Enables retrieval-augmented generation by integrating your data sources (search indexes, databases, vector stores) directly into chat completions.

Content Filtering: Azure's content safety system that evaluates both input prompts and generated completions for potentially harmful content across multiple categories.

Chat Extensions: Configuration objects that specify how Azure OpenAI should integrate with external data sources during chat completions.

Vectorization Sources: Mechanisms for generating embeddings used in vector search, including internal deployment names, external endpoints, and integrated vectorizers.

Polymorphic Types: The package uses Go interfaces to represent types that can have multiple concrete implementations (e.g., different data source configurations).

Architecture

The azopenai package follows these design patterns:

  1. Wrapper Pattern: Azure-specific response types wrap OpenAI types, adding methods to extract Azure-specific data while preserving the original OpenAI structure.

  2. Option Pattern: Functions like WithDataSources and WithEnhancements return option.RequestOption values that can be passed to OpenAI client methods.

  3. Classification Interfaces: Polymorphic types use "Classification" interfaces (e.g., AzureChatExtensionConfigurationClassification) to provide type-safe access to different implementations.

  4. Embedded Fields: Many Azure types are anonymously embedded in response structs, providing direct access to their fields and methods.