diff --git a/web/src/locales/zh-CN.json b/web/src/locales/zh-CN.json index e54f3df5..66b8ecc9 100644 --- a/web/src/locales/zh-CN.json +++ b/web/src/locales/zh-CN.json @@ -2,6 +2,7 @@ "common": { "ask_user_register": "请注册, 只有注册账号才能继续对话", "help": "第一条是主题(prompt, 角色定义), 上下文默认包括10条信息, 参数可以点击按钮进行调节, 请务必注意隐私, 不输入涉密, 敏感信息.", + "copy": "复制", "edit": "编辑", "delete": "删除", "save": "保存", @@ -40,7 +41,8 @@ "list": "机器人列表", "all": { "title": "机器人列表" - } + }, + "showCode": "生成API调用代码" }, "chat": { "new": "新对话", diff --git a/web/src/service/snapshot.ts b/web/src/service/snapshot.ts new file mode 100644 index 00000000..8a499dc8 --- /dev/null +++ b/web/src/service/snapshot.ts @@ -0,0 +1,56 @@ +import { displayLocaleDate, formatYearMonth } from '@/utils/date' + + + + + +export function generateAPIHelper(uuid: string, apiToken: string, origin: string) { + const data = { + "message": "Your message here", + "snapshot_uuid": uuid, + "stream": false, + } + return `curl -X POST ${origin}/api/chatbot -H "Content-Type: application/json" -H "Authorization: Bearer ${apiToken}" -d '${JSON.stringify(data)}'` +} + +export function getChatbotPosts(posts: Snapshot.Snapshot[]) { + return posts + .filter((post: Snapshot.Snapshot) => post.typ === 'chatbot') + .map((post: Snapshot.Snapshot): Snapshot.PostLink => ({ + uuid: post.uuid, + date: displayLocaleDate(post.createdAt), + title: post.title, + })) +} + +export function getSnapshotPosts(posts: Snapshot.Snapshot[]) { + return posts + .filter((post: Snapshot.Snapshot) => post.typ === 'snapshot') + .map((post: Snapshot.Snapshot): Snapshot.PostLink => ({ + uuid: post.uuid, + date: displayLocaleDate(post.createdAt), + title: post.title, + })) +} + +export function postsByYearMonthTransform(posts: Snapshot.PostLink[]) { + const init: Record = {} + return posts.reduce((acc, post) => { + const yearMonth = formatYearMonth(new Date(post.date)) + if (!acc[yearMonth]) + acc[yearMonth] = [] + + acc[yearMonth].push(post) + return acc + }, init) +} + +export function getSnapshotPostLinks(snapshots: Snapshot.Snapshot[]): Record { + const snapshotPosts = getSnapshotPosts(snapshots) + return postsByYearMonthTransform(snapshotPosts) +} + +export function getBotPostLinks(bots: Snapshot.Snapshot[]): Record { + const chatbotPosts = getChatbotPosts(bots) + return postsByYearMonthTransform(chatbotPosts) +} \ No newline at end of file diff --git a/web/src/typings/chat.d.ts b/web/src/typings/chat.d.ts index 9ee89e75..aa14164a 100644 --- a/web/src/typings/chat.d.ts +++ b/web/src/typings/chat.d.ts @@ -78,4 +78,24 @@ declare namespace Chat { userEmail: string rateLimit: string } + + } + +declare namespace Snapshot { + + interface Snapshot { + uuid: string; + title: string; + summary: string; + tags: Record; + createdAt: string; + typ: 'chatbot' | 'snapshot'; + } + + interface PostLink { + uuid: string; + date: string; + title: string; + } +} \ No newline at end of file diff --git a/web/src/views/bot/all.vue b/web/src/views/bot/all.vue index 68b6f63c..19c4648b 100644 --- a/web/src/views/bot/all.vue +++ b/web/src/views/bot/all.vue @@ -1,56 +1,42 @@