Class: LLM::Fillin::OpenAIAdapter
- Inherits:
-
Object
- Object
- LLM::Fillin::OpenAIAdapter
- Defined in:
- lib/llm/fillin/adapters/openai_adapter.rb
Instance Method Summary collapse
-
#initialize(api_key:, model:, temperature: 0) ⇒ OpenAIAdapter
constructor
A new instance of OpenAIAdapter.
- #step(system_prompt:, messages:, tools:, tool_results: []) ⇒ Object
- #tool_result_message(tool_call_id:, name:, content:) ⇒ Object
Constructor Details
#initialize(api_key:, model:, temperature: 0) ⇒ OpenAIAdapter
Returns a new instance of OpenAIAdapter.
8 9 10 11 12 |
# File 'lib/llm/fillin/adapters/openai_adapter.rb', line 8 def initialize(api_key:, model:, temperature: 0) @client = OpenAI::Client.new(access_token: api_key) @model = model @temperature = temperature end |
Instance Method Details
#step(system_prompt:, messages:, tools:, tool_results: []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/llm/fillin/adapters/openai_adapter.rb', line 14 def step(system_prompt:, messages:, tools:, tool_results: []) resp = @client.chat(parameters: { model: @model, temperature: @temperature, tools: tools, tool_choice: "auto", messages: [{ role: "system", content: system_prompt }] + + tool_results }) msg = resp.dig("choices", 0, "message") { tool_calls: msg["tool_calls"], content: msg["content"] } end |
#tool_result_message(tool_call_id:, name:, content:) ⇒ Object
28 29 30 |
# File 'lib/llm/fillin/adapters/openai_adapter.rb', line 28 def (tool_call_id:, name:, content:) { role: "tool", tool_call_id:, name:, content: content.to_json } end |