Class: AiClient::XAI::Client
- Inherits:
-
Object
- Object
- AiClient::XAI::Client
- Defined in:
- lib/ai_client/xai.rb
Constant Summary collapse
- BASE_URI =
Replace with actual xAI API endpoint
'https://api.x.ai/v1'
Instance Method Summary collapse
- #chat(prompt:, model: 'grok3', **options) ⇒ Object
-
#initialize(api_key: ENV['XAI_API_KEY']) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key: ENV['XAI_API_KEY']) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/ai_client/xai.rb', line 8 def initialize(api_key: ENV['XAI_API_KEY']) @api_key = api_key @connection = OmniAI::HTTP::Connection.new(BASE_URI) end |
Instance Method Details
#chat(prompt:, model: 'grok3', **options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ai_client/xai.rb', line 13 def chat(prompt:, model: 'grok3', **) response = @connection.post( '/chat/completions', # Adjust endpoint based on xAI API docs headers: { 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json' }, body: { model: model, messages: [{ role: 'user', content: prompt }], temperature: [:temperature] || 0.7, max_tokens: [:max_tokens] || 1024 }.to_json ) parse_response(response) end |