mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat(server): add real-world prompt test for copilot apis (#8629)
fix AF-1432, PD-1176
This commit is contained in:
19
tools/copilot-result/index.js
Normal file
19
tools/copilot-result/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { WebClient } from '@slack/web-api';
|
||||
|
||||
import { render } from './markdown.js';
|
||||
|
||||
const { CHANNEL_ID, SLACK_BOT_TOKEN, COPILOT_RESULT, BRANCH_SHA, BRANCH_NAME } =
|
||||
process.env;
|
||||
|
||||
const { ok } = await new WebClient(SLACK_BOT_TOKEN).chat.postMessage({
|
||||
channel: CHANNEL_ID,
|
||||
text: `AFFiNE Copilot Test ${COPILOT_RESULT}`,
|
||||
blocks: render(
|
||||
`# AFFiNE Copilot Test ${COPILOT_RESULT}
|
||||
|
||||
- [${BRANCH_NAME?.replace('refs/heads/', '') || BRANCH_SHA}](https://github.com/toeverything/AFFiNE/commit/${BRANCH_SHA})
|
||||
`
|
||||
),
|
||||
});
|
||||
|
||||
console.assert(ok, 'Failed to send a message to Slack');
|
||||
25
tools/copilot-result/markdown.js
Normal file
25
tools/copilot-result/markdown.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { jsxslack } from 'jsx-slack';
|
||||
import { marked, Renderer } from 'marked';
|
||||
|
||||
export const render = markdown => {
|
||||
const rendered = marked(markdown, {
|
||||
renderer: new (class CustomRenderer extends Renderer {
|
||||
heading({ tokens }) {
|
||||
return `
|
||||
<Fragment>
|
||||
<Section><b>${tokens[0].text}</b></Section>
|
||||
<Divider />
|
||||
</Fragment>`;
|
||||
}
|
||||
|
||||
list(token) {
|
||||
return `<Section>${super.list(token)}</Section>`;
|
||||
}
|
||||
|
||||
hr() {
|
||||
return `<Divider />`;
|
||||
}
|
||||
})(),
|
||||
});
|
||||
return jsxslack([`<Blocks>${rendered}</Blocks>`]);
|
||||
};
|
||||
16
tools/copilot-result/package.json
Normal file
16
tools/copilot-result/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@affine/copilot-result",
|
||||
"version": "0.17.0",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"description": "Send copilot result to slack",
|
||||
"dependencies": {
|
||||
"@slack/web-api": "^7.3.4",
|
||||
"jsx-slack": "^6.1.1",
|
||||
"marked": "^14.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.12"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user