Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add PR title summarization backoff and retry

Tomas Valenta5572d128ee47
diff --git a/github/pullRequest.ts b/github/pullRequest.ts
index 70b1d635a..5ec06f142 100644
--- a/github/pullRequest.ts
+++ b/github/pullRequest.ts
@@ -1,4 +1,6 @@
import { Configuration, OpenAIApi } from 'openai'
+import { backOff } from 'exponential-backoff'
+
import api from 'api-client/api'
import { deployments, prisma } from 'db/prisma'
@@ -14,7 +16,7 @@ const openai = new OpenAIApi(configuration)
export async function prTitleFromInstructions(instructions: string) {
try {
- const result = await openai.createChatCompletion({
+ const result = await backOff(() => openai.createChatCompletion({
model: 'gpt-4',
messages: [
{
@@ -22,7 +24,7 @@ export async function prTitleFromInstructions(instructions: string) {
role: 'user',
}
],
- })
+ }))
return result.data.choices[0].message?.content
} catch (error: any) {
if (error.response) {
diff --git a/package-lock.json b/package-lock.json
index f3a684ef1..8756aee45 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,6 +26,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"cross-fetch": "^3.1.5",
+ "exponential-backoff": "^3.1.1",
"fuse.js": "^6.6.2",
"http-proxy-middleware": "^3.0.0-beta.1",
"immer": "^9.0.19",
@@ -3693,6 +3694,11 @@
"node": ">=6"
}
},
+ "node_modules/exponential-backoff": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz",
+ "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw=="
+ },
"node_modules/ext": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
diff --git a/package.json b/package.json
index 4bc015280..605023a9c 100644
--- a/package.json
+++ b/package.json
@@ -56,6 +56,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"cross-fetch": "^3.1.5",
+ "exponential-backoff": "^3.1.1",
"fuse.js": "^6.6.2",
"http-proxy-middleware": "^3.0.0-beta.1",
"immer": "^9.0.19",