38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { app } from './index.ts';
|
||
|
||
import { useIssueEnv, useCommentEnv, useRepoInfoEnv } from '../src/index.ts'
|
||
import { pick } from 'es-toolkit';
|
||
|
||
const main = async () => {
|
||
const repoInfoEnv = useRepoInfoEnv();
|
||
const commentEnv = useCommentEnv();
|
||
const issueEnv = useIssueEnv();
|
||
const pickCommentEnv = pick(commentEnv, ['commentId', 'commentIdLabel']);
|
||
const pickIssueEnv = pick(issueEnv, ['issueId', 'issueIdLabel', 'issueIid', 'issueIidLabel', 'issueTitle', 'issueTitleLabel', 'issueDescription', 'issueDescriptionLabel']);
|
||
const pickRepoInfoEnv = pick(repoInfoEnv, ['repoId', 'repoIdLabel', 'repoName', 'repoNameLabel', 'repoSlug', 'repoSlugLabel']);
|
||
const messages = [
|
||
{
|
||
role: 'system',
|
||
content: `你是一个智能的代码助手, 根据用户提供的上下文信息,提供有用的建议和帮助。并把最后的结果提交一个评论到对应的issue中。用户提供的上下文信息如下:`
|
||
},
|
||
{
|
||
role: 'system',
|
||
content: `相关变量:${JSON.stringify({ ...pickCommentEnv, ...pickIssueEnv, ...pickRepoInfoEnv })}`
|
||
}, {
|
||
role: 'user',
|
||
content: commentEnv.commentBody || pickIssueEnv.issueDescription || '无'
|
||
}
|
||
]
|
||
const result = await app.run({
|
||
path: 'cnb',
|
||
key: 'chat',
|
||
payload: {
|
||
messages
|
||
}
|
||
})
|
||
if (result.code === 200) {
|
||
console.log('执行完成')
|
||
}
|
||
}
|
||
|
||
main(); |