Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Summarize the PR instructions and use it as a title for the PR

Tomas Valenta1f6e89204822
diff --git a/github/pullRequest.ts b/github/pullRequest.ts
index 6d774b5cc..70b1d635a 100644
--- a/github/pullRequest.ts
+++ b/github/pullRequest.ts
@@ -1,8 +1,39 @@
+import { Configuration, OpenAIApi } from 'openai'
+
import api from 'api-client/api'
import { deployments, prisma } from 'db/prisma'
import { GitHubClient } from './client'
+
+const configuration = new Configuration({
+ apiKey: process.env.OPENAI_API_KEY,
+})
+
+const openai = new OpenAIApi(configuration)
+
+export async function prTitleFromInstructions(instructions: string) {
+ try {
+ const result = await openai.createChatCompletion({
+ model: 'gpt-4',
+ messages: [
+ {
+ content: `${instructions}\n\nTl;dr in one sentence (around 50 characters) describing what to build. Don't use pronouns, just describe the thing:`,
+ role: 'user',
+ }
+ ],
+ })
+ return result.data.choices[0].message?.content
+ } catch (error: any) {
+ if (error.response) {
+ console.log(error.response.status)
+ console.log(error.response.data)
+ } else {
+ console.log(error.message)
+ }
+ }
+}
+
// All PRs are also issues - GH API endpoint for issues is used for the shared functionality
export async function createPR({
client,
diff --git a/package-lock.json b/package-lock.json
index a03b16a06..f3a684ef1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -35,6 +35,7 @@
"nanoid": "^4.0.1",
"next": "13.2.3",
"next-superjson-plugin": "^0.5.6",
+ "openai": "^3.2.1",
"openapi-typescript-fetch": "^1.1.3",
"posthog-js": "^1.63.3",
"posthog-node": "^3.1.1",
@@ -6218,6 +6219,23 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/openai": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz",
+ "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==",
+ "dependencies": {
+ "axios": "^0.26.0",
+ "form-data": "^4.0.0"
+ }
+ },
+ "node_modules/openai/node_modules/axios": {
+ "version": "0.26.1",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
+ "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
+ "dependencies": {
+ "follow-redirects": "^1.14.8"
+ }
+ },
"node_modules/openapi-typescript": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/openapi-typescript/-/openapi-typescript-6.2.1.tgz",
diff --git a/package.json b/package.json
index b59fb13a8..4bc015280 100644
--- a/package.json
+++ b/package.json
@@ -65,6 +65,7 @@
"nanoid": "^4.0.1",
"next": "13.2.3",
"next-superjson-plugin": "^0.5.6",
+ "openai": "^3.2.1",
"openapi-typescript-fetch": "^1.1.3",
"posthog-js": "^1.63.3",
"posthog-node": "^3.1.1",
diff --git a/pages/api/agent/index.ts b/pages/api/agent/index.ts
index 24d49dcd5..97502e8cd 100644
--- a/pages/api/agent/index.ts
+++ b/pages/api/agent/index.ts
@@ -8,7 +8,7 @@ import { prisma } from 'db/prisma'
import { serverCreds } from 'db/credentials'
import { PostAgentBody } from 'pages/agent/smol-developer/setup'
import { getGHInstallationClient } from 'github/installationClient'
-import { createAgentDeployment, createPR, getGHAccessToken, getGHAppInfo, triggerSmolDevAgentRun } from 'github/pullRequest'
+import { createAgentDeployment, createPR, getGHAccessToken, getGHAppInfo, prTitleFromInstructions, triggerSmolDevAgentRun } from 'github/pullRequest'
import { TemplateID } from 'state/template'
export interface DeploymentAuthData {
@@ -78,9 +78,16 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
repositoryID,
})
+
+ const prTitle = await prTitleFromInstructions(body)
+
+ if (!prTitle) {
+ throw new Error('Generated PR title is empty')
+ }
+
const { issueID, number: pullNumber, url: pullURL } = await createPR({
client,
- title,
+ title: prTitle,
defaultBranch,
branch,
commitMessage,