-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
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
10 changed files
with
143 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
import { OpenAIChatStreamPayload } from '@/types/openai/chat'; | ||
|
||
export const chainLangDetect = (content: string): Partial<OpenAIChatStreamPayload> => ({ | ||
messages: [ | ||
{ | ||
content: | ||
'你是一名精通全世界语言的语言专家,你需要识别用户输入的内容,以国际标准 locale 进行输出', | ||
role: 'system', | ||
}, | ||
{ | ||
content: '{你好}', | ||
role: 'user', | ||
}, | ||
{ | ||
content: 'zh-CN', | ||
role: 'assistant', | ||
}, | ||
{ | ||
content: '{hello}', | ||
role: 'user', | ||
}, | ||
{ | ||
content: 'en-US', | ||
role: 'assistant', | ||
}, | ||
{ | ||
content: `{${content}}`, | ||
role: 'user', | ||
}, | ||
], | ||
}); |
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,34 @@ | ||
import { OpenAIChatStreamPayload } from '@/types/openai/chat'; | ||
|
||
/** | ||
* pick emoji for user prompt | ||
* @param content | ||
*/ | ||
export const chainPickEmoji = (content: string): Partial<OpenAIChatStreamPayload> => ({ | ||
messages: [ | ||
{ | ||
content: '你是一名非常懂设计与时尚的设计师,你需要从用户的描述中匹配一个合适的 emoji。', | ||
role: 'system', | ||
}, | ||
{ | ||
content: `输入:你是一名精通体验设计的设计系统设计师,设计系统存在诸多类别的 token,比如品牌色、成功色等,你需要为各个类别的 token 提供说明文案。`, | ||
role: 'user', | ||
}, | ||
{ | ||
content: `💅`, | ||
role: 'assistant', | ||
}, | ||
{ | ||
content: `输入:用户会输入一串 ts 代码,为了确保所有功能和分支的 100% 的覆盖率,你需要给出需要考虑哪些数据场景。`, | ||
role: 'user', | ||
}, | ||
{ | ||
content: `🧪`, | ||
role: 'assistant', | ||
}, | ||
{ | ||
content: `输入:${content}`, | ||
role: 'user', | ||
}, | ||
], | ||
}); |
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,15 @@ | ||
import { OpenAIChatStreamPayload } from '@/types/openai/chat'; | ||
|
||
export const chainSummaryDescription = (content: string): Partial<OpenAIChatStreamPayload> => ({ | ||
messages: [ | ||
{ | ||
content: | ||
'你是一名擅长会话的助理,你需要将用户的输入的内容总结为一个专家的简介,不超过 20 个字', | ||
role: 'system', | ||
}, | ||
{ | ||
content: `${content}`, | ||
role: 'user', | ||
}, | ||
], | ||
}); |
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,32 @@ | ||
import { chatHelpers } from '@/store/session/slices/chat/helpers'; | ||
import { LanguageModel } from '@/types/llm'; | ||
import { OpenAIChatMessage, OpenAIChatStreamPayload } from '@/types/openai/chat'; | ||
|
||
export const chainSummaryTitle = async ( | ||
messages: OpenAIChatMessage[], | ||
): Promise<Partial<OpenAIChatStreamPayload>> => { | ||
const finalMessages: OpenAIChatMessage[] = [ | ||
{ | ||
content: | ||
'你是一名擅长会话的助理,你需要将用户的会话总结为 10 个字以内的标题,不需要包含标点符号', | ||
role: 'system', | ||
}, | ||
{ | ||
content: `${messages.map((message) => `${message.role}: ${message.content}`).join('\n')} | ||
请总结上述对话为10个字以内的标题,不需要包含标点符号`, | ||
role: 'user', | ||
}, | ||
]; | ||
// 如果超过 4k,则使用 GPT3.5 16K 模型 | ||
const tokens = await chatHelpers.getMessagesTokenCount(finalMessages); | ||
let model: LanguageModel | undefined = undefined; | ||
if (tokens > 4000) { | ||
model = LanguageModel.GPT3_5_16K; | ||
} | ||
|
||
return { | ||
messages: finalMessages, | ||
model, | ||
}; | ||
}; |
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,17 @@ | ||
import { OpenAIChatStreamPayload } from '@/types/openai/chat'; | ||
|
||
export const chainTranslate = ( | ||
content: string, | ||
targetLang: string, | ||
): Partial<OpenAIChatStreamPayload> => ({ | ||
messages: [ | ||
{ | ||
content: '你是一名擅长翻译的助理,你需要将输入的语言翻译为目标语言', | ||
role: 'system', | ||
}, | ||
{ | ||
content: `请将以下内容 ${content},翻译为 ${targetLang} `, | ||
role: 'user', | ||
}, | ||
], | ||
}); |
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