Class: LlmGateway::Adapters::OpenAi::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- LlmGateway::Adapters::OpenAi::Client
- Defined in:
- lib/llm_gateway/adapters/open_ai/client.rb
Instance Attribute Summary
Attributes inherited from BaseClient
#api_key, #base_endpoint, #model_key
Instance Method Summary collapse
- #chat(messages, response_format: { type: "text" }, tools: nil, system: [], max_completion_tokens: 4096) ⇒ Object
- #generate_embeddings(input) ⇒ Object
-
#initialize(model_key: "gpt-4o", api_key: ENV["OPENAI_API_KEY"]) ⇒ Client
constructor
A new instance of Client.
Methods inherited from BaseClient
Constructor Details
#initialize(model_key: "gpt-4o", api_key: ENV["OPENAI_API_KEY"]) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/llm_gateway/adapters/open_ai/client.rb', line 9 def initialize(model_key: "gpt-4o", api_key: ENV["OPENAI_API_KEY"]) @base_endpoint = "https://api.openai.com/v1" super(model_key: model_key, api_key: api_key) end |
Instance Method Details
#chat(messages, response_format: { type: "text" }, tools: nil, system: [], max_completion_tokens: 4096) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/llm_gateway/adapters/open_ai/client.rb', line 14 def chat(, response_format: { type: "text" }, tools: nil, system: [], max_completion_tokens: 4096) body = { model: model_key, messages: system + , max_completion_tokens: max_completion_tokens } body[:tools] = tools if tools post("chat/completions", body) end |
#generate_embeddings(input) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/llm_gateway/adapters/open_ai/client.rb', line 25 def (input) body = { input:, model: model_key } post("embeddings", body) end |