Skip to content

Commit

Permalink
feat: Add temperature option to OpenAI API (#288)
Browse files Browse the repository at this point in the history
* feat: add temperature option to openai api

* feat: fix options setting

* feat: fix createOpenAIClient with pr.mts

---------

Co-authored-by: j-kanno <[email protected]>
  • Loading branch information
kannoixia and jumpei-kanno authored Dec 24, 2024
1 parent 1004fb5 commit 68d35af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion scripts/konjacbot/pr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const defaults = {
github: 'https://github.com/vercel/next.js',
web: 'https://nextjs.org/docs',
},
model: 'gpt-4o',
} as const

$.verbose = true
Expand Down Expand Up @@ -94,7 +95,10 @@ async function buildPRSummary(): Promise<string> {
new OpenAI({
apiKey: defaults.apiKey,
maxRetries: defaults.maxRetries,
})
}),
{
model: defaults.model,
}
)

try {
Expand Down
8 changes: 7 additions & 1 deletion scripts/konjacbot/translate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const defaults = {
lang: 'ja',
promptDir: path.join(import.meta.dirname, `prompt`),
isCI: process.env.CI ?? false,
temperature: 0,
model: 'gpt-4o',
} as const

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

const systemContent = (
Expand Down
5 changes: 3 additions & 2 deletions 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: Omit<OpenAI.ChatCompletionCreateParams, 'messages'>
): (prompt: { system: string; user: string }) => Promise<string> {
async function fetch(prompt: {
system: string
Expand All @@ -255,7 +256,7 @@ export function createOpenAIClient(

while (!isComplete) {
const response = await openai.chat.completions.create({
model: 'gpt-4o',
...options,
messages,
stream: false,
})
Expand Down

0 comments on commit 68d35af

Please sign in to comment.