Class: Langchain::LLM::Azure

Inherits:
OpenAI show all
Defined in:
lib/langchain/llm/azure.rb

Overview

LLM interface for Azure OpenAI Service APIs: learn.microsoft.com/en-us/azure/ai-services/openai/

Gem requirements:

gem "ruby-openai", "~> 6.3.0"

Usage:

openai = Langchain::LLM::Azure.new(api_key:, llm_options: {}, embedding_deployment_url: chat_deployment_url:)

Constant Summary

Constants inherited from OpenAI

OpenAI::DEFAULTS, OpenAI::EMBEDDING_SIZES, OpenAI::LENGTH_VALIDATOR

Instance Attribute Summary collapse

Attributes inherited from OpenAI

#defaults

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from OpenAI

#default_dimensions, #summarize

Methods inherited from Base

#default_dimensions, #summarize

Methods included from DependencyHelper

#depends_on

Constructor Details

#initialize(api_key:, llm_options: {}, default_options: {}, embedding_deployment_url: nil, chat_deployment_url: nil) ⇒ Azure

Returns a new instance of Azure.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/langchain/llm/azure.rb', line 16

def initialize(
  api_key:,
  llm_options: {},
  default_options: {},
  embedding_deployment_url: nil,
  chat_deployment_url: nil
)
  depends_on "ruby-openai", req: "openai"
  @embed_client = ::OpenAI::Client.new(
    access_token: api_key,
    uri_base: embedding_deployment_url,
    **llm_options
  )
  @chat_client = ::OpenAI::Client.new(
    access_token: api_key,
    uri_base: chat_deployment_url,
    **llm_options
  )
  @defaults = DEFAULTS.merge(default_options)
end

Instance Attribute Details

#chat_clientObject (readonly)

Returns the value of attribute chat_client.



14
15
16
# File 'lib/langchain/llm/azure.rb', line 14

def chat_client
  @chat_client
end

#embed_clientObject (readonly)

Returns the value of attribute embed_client.



13
14
15
# File 'lib/langchain/llm/azure.rb', line 13

def embed_client
  @embed_client
end

Instance Method Details

#chatObject



47
48
49
50
# File 'lib/langchain/llm/azure.rb', line 47

def chat(...)
  @client = @chat_client
  super(...)
end

#completeObject



42
43
44
45
# File 'lib/langchain/llm/azure.rb', line 42

def complete(...)
  @client = @chat_client
  super(...)
end

#embedObject



37
38
39
40
# File 'lib/langchain/llm/azure.rb', line 37

def embed(...)
  @client = @embed_client
  super(...)
end