Skip to content

Commit

Permalink
Add timeout to OpenAI API
Browse files Browse the repository at this point in the history
  • Loading branch information
ouchi2501 committed Sep 29, 2023
1 parent c959463 commit 72f8f4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ export async function completionRequest(
): Promise<string> {
try {
const openai = new OpenAI({ apiKey })
const response = await openai.chat.completions.create({
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
],
model: 'gpt-3.5-turbo'
})
const response = await openai.chat.completions.create(
{
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
],
model: 'gpt-3.5-turbo'
},
{
timeout: 60 * 1000 // 60s
}
)
if (
response.choices &&
response.choices[0] &&
Expand Down

0 comments on commit 72f8f4d

Please sign in to comment.