Class: TranslationAPI::Provider::OpenAI
- Inherits:
-
Object
- Object
- TranslationAPI::Provider::OpenAI
- Defined in:
- lib/translation_api/provider/openai.rb,
lib/translation_api/provider/openai/chat.rb,
lib/translation_api/provider/openai/cost.rb,
lib/translation_api/provider/openai/model.rb,
lib/translation_api/provider/openai/response.rb
Defined Under Namespace
Classes: Chat, Cost, Model, Response
Instance Method Summary collapse
-
#initialize(output_logs:, except_words:, language:, custom_prompt: nil) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #name ⇒ Object
- #translate(text) ⇒ Object
Constructor Details
#initialize(output_logs:, except_words:, language:, custom_prompt: nil) ⇒ OpenAI
Returns a new instance of OpenAI.
12 13 14 15 16 17 |
# File 'lib/translation_api/provider/openai.rb', line 12 def initialize(output_logs:, except_words:, language:, custom_prompt: nil) @model = Model.new(ENV["OPENAI_MODEL"] || Model.nano) @prompt = Llm::Prompt.new(except_words:, language:, custom_prompt:) @chat = Chat.new(model: @model, prompt: @prompt) @output_logs = output_logs end |
Instance Method Details
#name ⇒ Object
28 29 30 |
# File 'lib/translation_api/provider/openai.rb', line 28 def name "openai" end |
#translate(text) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/translation_api/provider/openai.rb', line 19 def translate(text) return text if text.strip.empty? @response = @chat.call(text) log.write if @output_logs @response.translated_text end |