Class: Rasti::AI::OpenAI::Provider
Constant Summary
collapse
- THINKING_LEVELS =
{
'low' => 'low'.freeze,
'medium' => 'medium'.freeze,
'high' => 'high'.freeze
}.freeze
Constants inherited
from Provider
Provider::ALIASES, Provider::MODULES
Instance Attribute Summary
Attributes inherited from Provider
#model
Instance Method Summary
collapse
Methods inherited from Provider
build, #build_client, #create_assistant, #generate_text, #initialize, names
Instance Method Details
#base_url ⇒ Object
24
25
26
|
# File 'lib/rasti/ai/open_ai/provider.rb', line 24
def base_url
'https://api.openai.com/v1'
end
|
#default_api_key ⇒ Object
20
21
22
|
# File 'lib/rasti/ai/open_ai/provider.rb', line 20
def default_api_key
Rasti::AI.openai_api_key
end
|
#default_model ⇒ Object
16
17
18
|
# File 'lib/rasti/ai/open_ai/provider.rb', line 16
def default_model
Rasti::AI.openai_default_model
end
|
#name ⇒ Object
12
13
14
|
# File 'lib/rasti/ai/open_ai/provider.rb', line 12
def name
:open_ai
end
|
#parse_usage(response) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rasti/ai/open_ai/provider.rb', line 28
def parse_usage(response)
usage = response['usage']
return nil unless usage
Usage.new(
provider: name.to_s,
model: response['model'],
input_tokens: usage['prompt_tokens'],
output_tokens: usage['completion_tokens'],
cached_tokens: usage.dig('prompt_tokens_details', 'cached_tokens') || 0,
reasoning_tokens: usage.dig('completion_tokens_details', 'reasoning_tokens') || 0,
raw: usage
)
end
|