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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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