@@ -4,22 +4,12 @@ import { maxResponseTokenLength, Models, getUserConfig } from '../../config/inde
4
4
import { fetchSSE } from '../../utils/fetch-sse'
5
5
import { getConversationPairs } from '../../utils/get-conversation-pairs'
6
6
import { 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'
23
13
24
14
/**
25
15
* @param {Browser.Runtime.Port } port
@@ -38,9 +28,9 @@ export async function generateAnswersWithGptCompletionApi(
38
28
const { controller, messageListener } = setAbortController ( port )
39
29
40
30
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: `
44
34
const apiUrl = ( await getUserConfig ( ) ) . customOpenAiApiUrl
45
35
46
36
let answer = ''
@@ -101,8 +91,8 @@ export async function generateAnswersWithGptCompletionApi(
101
91
export async function generateAnswersWithChatgptApi ( port , question , session , apiKey , modelName ) {
102
92
const { controller, messageListener } = setAbortController ( port )
103
93
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 ( ) } )
106
96
prompt . push ( { role : 'user' , content : question } )
107
97
const apiUrl = ( await getUserConfig ( ) ) . customOpenAiApiUrl
108
98
0 commit comments