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:

llm = 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

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #defaults

Instance Method Summary collapse

Methods inherited from OpenAI

#default_dimensions, #summarize

Methods inherited from Base

#chat_parameters, #default_dimension, #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.

[View source]

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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)
  chat_parameters.update(
    model: {default: @defaults[:chat_model]},
    logprobs: {},
    top_logprobs: {},
    n: {default: @defaults[:n]},
    temperature: {default: @defaults[:temperature]},
    user: {},
    response_format: {default: @defaults[:response_format]}
  )
  chat_parameters.ignore(:top_k)
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

[View source]

57
58
59
60
# File 'lib/langchain/llm/azure.rb', line 57

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

#completeObject

[View source]

52
53
54
55
# File 'lib/langchain/llm/azure.rb', line 52

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

#embedObject

[View source]

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

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