Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add temperature option to OpenAI API #288

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/konjacbot/translate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const defaults = {
lang: 'ja',
promptDir: path.join(import.meta.dirname, `prompt`),
isCI: process.env.CI ?? false,
temperature: 0,
} as const

const log = createLogger(basename(import.meta.filename))
Expand Down Expand Up @@ -52,7 +53,8 @@ const command = await (async () => {
new OpenAI({
apiKey: defaults.apiKey,
maxRetries: defaults.maxRetries,
})
}),
{ temperature: defaults.temperature }
)

const systemContent = (
Expand Down
4 changes: 3 additions & 1 deletion scripts/konjacbot/utils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export function createLogger(prefix: string) {
* @returns {(prompt: { system: string; user: string }) => Promise<string>} A function that takes a prompt and returns the assistant's response as a string.
*/
export function createOpenAIClient(
openai: OpenAI
openai: OpenAI,
options: { temperature?: number } = {}
jonghyo marked this conversation as resolved.
Show resolved Hide resolved
): (prompt: { system: string; user: string }) => Promise<string> {
async function fetch(prompt: {
system: string
Expand All @@ -258,6 +259,7 @@ export function createOpenAIClient(
model: 'gpt-4o',
messages,
stream: false,
temperature: options.temperature,
})

const choice = response.choices[0]
Expand Down