@@ -4,22 +4,12 @@ import { maxResponseTokenLength, Models, getUserConfig } from '../../config/inde
44import { fetchSSE } from '../../utils/fetch-sse'
55import { getConversationPairs } from '../../utils/get-conversation-pairs'
66import { isEmpty } from 'lodash-es'
7- import { pushRecord , setAbortController } from './shared.mjs'
8-
9- const getChatgptPromptBase = async ( ) => {
10- return `You are a helpful, creative, clever, and very friendly assistant. You are familiar with various languages in the world.`
11- }
12-
13- const getGptPromptBase = async ( ) => {
14- return (
15- `The following is a conversation with an AI assistant.` +
16- `The assistant is helpful, creative, clever, and very friendly. The assistant is familiar with various languages in the world.\n\n` +
17- `Human: Hello, who are you?\n` +
18- `AI: I am an AI created by OpenAI. How can I help you today?\n` +
19- `Human: 谢谢\n` +
20- `AI: 不客气\n`
21- )
22- }
7+ import {
8+ getChatSystemPromptBase ,
9+ getCompletionPromptBase ,
10+ pushRecord ,
11+ setAbortController ,
12+ } from './shared.mjs'
2313
2414/**
2515 * @param {Browser.Runtime.Port } port
@@ -38,9 +28,9 @@ export async function generateAnswersWithGptCompletionApi(
3828 const { controller, messageListener } = setAbortController ( port )
3929
4030 const prompt =
41- ( await getGptPromptBase ( ) ) +
42- getConversationPairs ( session . conversationRecords , false ) +
43- `Human:${ question } \nAI:`
31+ ( await getCompletionPromptBase ( ) ) +
32+ getConversationPairs ( session . conversationRecords , true ) +
33+ `Human: ${ question } \nAI: `
4434 const apiUrl = ( await getUserConfig ( ) ) . customOpenAiApiUrl
4535
4636 let answer = ''
@@ -101,8 +91,8 @@ export async function generateAnswersWithGptCompletionApi(
10191export async function generateAnswersWithChatgptApi ( port , question , session , apiKey , modelName ) {
10292 const { controller, messageListener } = setAbortController ( port )
10393
104- const prompt = getConversationPairs ( session . conversationRecords , true )
105- prompt . unshift ( { role : 'system' , content : await getChatgptPromptBase ( ) } )
94+ const prompt = getConversationPairs ( session . conversationRecords , false )
95+ prompt . unshift ( { role : 'system' , content : await getChatSystemPromptBase ( ) } )
10696 prompt . push ( { role : 'user' , content : question } )
10797 const apiUrl = ( await getUserConfig ( ) ) . customOpenAiApiUrl
10898
0 commit comments