Skip to content

Commit 1e0b8f0

Browse files
authored
OpenAI: custom temperature (#673)
1 parent f5ca65c commit 1e0b8f0

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/i18n/tasks/translators/openai_translator.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def model
7373
@model ||= @i18n_tasks.translation_config[:openai_model].presence || "gpt-4o-mini"
7474
end
7575

76+
def temperature
77+
@temperature ||= @i18n_tasks.translation_config[:openai_temperature].presence || 0.0
78+
end
79+
7680
def system_prompt(to_locale)
7781
prompt = if locale_prompts[to_locale].present?
7882
locale_prompts[to_locale]
@@ -105,7 +109,7 @@ def translate(values, from, to)
105109
parameters: {
106110
model: model,
107111
messages: build_messages(values, from, to),
108-
temperature: 0.0,
112+
temperature: temperature,
109113
response_format: {type: "json_object"}
110114
}
111115
)

templates/config/i18n-tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ search:
123123
# # OpenAI
124124
# openai_api_key: "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
125125
# # openai_model: "gpt-4o-mini" # see https://platform.openai.com/docs/models
126+
# # openai_temperature: 0.0 # Controls randomness in responses (0.0-2.0), default: 0.0
126127
# # may contain `%{from}` and `%{to}`, which will be replaced by source and target locale codes, respectively (using `Kernel.format`)
127128
# # openai_system_prompt: >-
128129
# # You are a professional translator that translates content from the %{from} locale

0 commit comments

Comments
 (0)