Skip to content

Commit

Permalink
Merge pull request #23 from ca-dp/releases/add-timeout
Browse files Browse the repository at this point in the history
Add timeout to OpenAI API
  • Loading branch information
ouchi2501 authored Sep 29, 2023
2 parents c959463 + 000b500 commit 50a3f3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions dist/index.js

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

20 changes: 13 additions & 7 deletions src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ 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 requestTimeout = 300 * 1000 // 5 minutes
const response = await openai.chat.completions.create(
{
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
],
model: 'gpt-3.5-turbo'
},
{
timeout: requestTimeout
}
)
if (
response.choices &&
response.choices[0] &&
Expand Down

0 comments on commit 50a3f3a

Please sign in to comment.