Class: LLM::Alibaba

Inherits:
OpenAI show all
Defined in:
lib/llm/providers/alibaba.rb,
lib/llm/providers/alibaba/error_handler.rb,
lib/llm/providers/alibaba/request_adapter.rb

Overview

The Alibaba class implements a provider for Alibaba Cloud Model Studio through its OpenAI-compatible API, including the Qwen3 family of models.

The default host is the pay-as-you-go DashScope international endpoint (dashscope-intl.aliyuncs.com). Configure a different host either globally through the DASHSCOPE_API_HOST environment variable, or per instance through LLM.alibaba(host: "token-plan.ap-southeast-1.maas.aliyuncs.com") (for example Alibaba's Token Plan).

Examples:

#!/usr/bin/env ruby
require "llm"

llm = LLM.alibaba(key: ENV["DASHSCOPE_API_KEY"])
ctx = LLM::Context.new(llm)
ctx.talk "Hello"

Defined Under Namespace

Modules: RequestAdapter Classes: ErrorHandler

Constant Summary collapse

HOST =
"dashscope-intl.aliyuncs.com"
BASE_PATH =
"/compatible-mode/v1"

Instance Method Summary collapse

Methods inherited from OpenAI

#adapt_function, #complete, #embed, #files, #models, #server_tools, #web_search

Methods inherited from Provider

#adapt_function, #assistant_role, #build_messages, #chat, #complete, #developer_role, #embed, #files, #host, #inspect, #interrupt!, #key?, #models, #ocr, #port, #registry, #request_owner, #respond, #retry_errors, #schema, #server_tool, #server_tools, #system_role, #tool_role, #tracer, #tracer=, #user_role, #web_search, #with, #with_tracer

Constructor Details

#initialize(host: ENV.fetch("DASHSCOPE_API_HOST", HOST), base_path: BASE_PATH) ⇒ LLM::Alibaba

Parameters:

  • key (String, nil) —

    The secret key for authentication

  • host (String) (defaults to: ENV.fetch("DASHSCOPE_API_HOST", HOST)) —

    The host address of the LLM provider

  • base_path (String) (defaults to: BASE_PATH) —

    Optional base path prefix for HTTP API routes.



37
38
39
# File 'lib/llm/providers/alibaba.rb', line 37

def initialize(host: ENV.fetch("DASHSCOPE_API_HOST", HOST), base_path: BASE_PATH, **)
  super
end

Instance Method Details

#retry_budget ⇒ Integer

Returns the number of times a rate-limited request is retried.

Alibaba (token plan) will frequently issue rate limits or time outs that it recovers from. The higher retry count is to account for scenarios where it takes longer than expected to recover.

Returns:

  • (Integer)

See Also:



104
105
106
# File 'lib/llm/providers/alibaba.rb', line 104

def retry_budget
  8
end

#name ⇒ Symbol

Returns the provider's name

Returns:

  • (Symbol) —

    Returns the provider's name



44
45
46
# File 'lib/llm/providers/alibaba.rb', line 44

def name
  :alibaba
end

#error_handler ⇒ Class

Returns the class that handles unsuccessful responses

Returns:

  • (Class) —

    Returns the class that handles unsuccessful responses



51
52
53
# File 'lib/llm/providers/alibaba.rb', line 51

def error_handler
  LLM::Alibaba::ErrorHandler
end

#images ⇒ Object

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/llm/providers/alibaba.rb', line 57

def images
  raise NotImplementedError
end

#audio ⇒ Object

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/llm/providers/alibaba.rb', line 63

def audio
  raise NotImplementedError
end

#moderations ⇒ Object

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/llm/providers/alibaba.rb', line 69

def moderations
  raise NotImplementedError
end

#responses ⇒ Object

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/llm/providers/alibaba.rb', line 75

def responses
  raise NotImplementedError
end

#vector_stores ⇒ Object

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/llm/providers/alibaba.rb', line 81

def vector_stores
  raise NotImplementedError
end

#default_model ⇒ String

Returns the default model for chat completions

Returns:

  • (String)

See Also:



89
90
91
# File 'lib/llm/providers/alibaba.rb', line 89

def default_model
  "deepseek-v4-flash-0731"
end