-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use server' | ||
|
||
import {initSDK} from '@opensdks/core' | ||
import {githubSdkDef, type githubTypes} from '@opensdks/sdk-github' | ||
import {openaiSdkDef} from '@opensdks/sdk-openai' | ||
|
||
type Commit = githubTypes['components']['schemas']['commit'] | ||
|
||
const github = initSDK(githubSdkDef, { | ||
headers: { | ||
Authorization: `Bearer ${process.env['GITHUB_TOKEN']}`, | ||
'X-GitHub-Api-Version': '2022-11-28', | ||
}, | ||
}) | ||
|
||
export async function fetchCommits(prLink: string) { | ||
const prUrl = new URL(prLink) | ||
const [, owner, repo, , prNumber] = prUrl.pathname.split('/') | ||
|
||
return github | ||
.GET('/repos/{owner}/{repo}/pulls/{pull_number}/commits', { | ||
params: { | ||
path: {owner, repo, pull_number: Number(prNumber)}, | ||
}, | ||
}) | ||
.then((r) => r.data) | ||
} | ||
|
||
const apiKey = process.env['OPENAI_API_KEY'] | ||
|
||
const openai = initSDK(openaiSdkDef, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
|
||
export const summarizeCommits = async (commits: Commit[]) => { | ||
const messages = commits.map((commit) => commit.commit.message).join('\n') | ||
const prompt = `I have a list of software commit messages and need a summary of the changes. Here are the commit messages:\n${messages}\nCan you provide a summary?` | ||
|
||
try { | ||
const response = await openai.POST('/chat/completions', { | ||
body: { | ||
model: 'gpt-3.5-turbo', | ||
max_tokens: 1000, | ||
messages: [ | ||
{role: 'system', content: prompt}, | ||
{role: 'user', content: messages}, | ||
], | ||
}, | ||
}) | ||
return response.data.choices[0].message.content | ||
} catch (err) { | ||
console.error('Error summarizing commits:', err) | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dde7be8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
opensdks – ./
opensdks-venice.vercel.app
opensdks-git-main-venice.vercel.app
opensdks.vercel.app
opensdks.org