Class: Roseflow::OpenAI::Provider
- Inherits:
-
Object
- Object
- Roseflow::OpenAI::Provider
- Defined in:
- lib/roseflow/openai/provider.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#chat(model:, messages:, **options, &block) ⇒ Roseflow::OpenAI::ChatResponse
Chat with a model.
-
#client ⇒ Object
Returns the client for the provider.
-
#completion(model:, prompt:, **options) ⇒ Roseflow::OpenAI::CompletionResponse
Create a completion.
-
#edit(model:, instruction:, **options) ⇒ Roseflow::OpenAI::EditResponse
Creates a new edit for the provided input, instruction, and parameters.
-
#embedding(model:, input:, **options) ⇒ Object
Creates an embedding vector representing the input text.
- #image(prompt:, **options) ⇒ Object
-
#initialize(config = Roseflow::OpenAI::Config.new) ⇒ Provider
constructor
A new instance of Provider.
-
#models ⇒ Object
Returns the model repository for the provider.
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
107 108 109 |
# File 'lib/roseflow/openai/provider.rb', line 107 def config @config end |
Instance Method Details
#chat(model:, messages:, **options, &block) ⇒ Roseflow::OpenAI::ChatResponse
Chat with a model
41 42 43 44 45 46 47 48 49 |
# File 'lib/roseflow/openai/provider.rb', line 41 def chat(model:, messages:, **, &block) streaming = .fetch(:streaming, false) if streaming client.streaming_chat_completion(model: model, messages: .map(&:to_h), **, &block) else client.create_chat_completion(model: model, messages: .map(&:to_h), **) end end |
#client ⇒ Object
Returns the client for the provider
14 15 16 |
# File 'lib/roseflow/openai/provider.rb', line 14 def client @client ||= Client.new(config, self) end |
#completion(model:, prompt:, **options) ⇒ Roseflow::OpenAI::CompletionResponse
Create a completion.
69 70 71 72 73 74 75 76 77 |
# File 'lib/roseflow/openai/provider.rb', line 69 def completion(model:, prompt:, **) streaming = .fetch(:streaming, false) if streaming client.streaming_completion(model: model, prompt: prompt, **) else client.create_completion(model: model, prompt: prompt, **) end end |
#edit(model:, instruction:, **options) ⇒ Roseflow::OpenAI::EditResponse
Creates a new edit for the provided input, instruction, and parameters.
89 90 91 |
# File 'lib/roseflow/openai/provider.rb', line 89 def edit(model:, instruction:, **) client.create_edit(model: model, instruction: instruction, **) end |
#embedding(model:, input:, **options) ⇒ Object
Creates an embedding vector representing the input text.
99 100 101 |
# File 'lib/roseflow/openai/provider.rb', line 99 def (model:, input:, **) client.(model: model, input: input, **).. end |
#image(prompt:, **options) ⇒ Object
103 104 105 |
# File 'lib/roseflow/openai/provider.rb', line 103 def image(prompt:, **) client.create_image(prompt: prompt, **) end |
#models ⇒ Object
Returns the model repository for the provider
19 20 21 |
# File 'lib/roseflow/openai/provider.rb', line 19 def models @models ||= ModelRepository.new(self) end |