Skip to content

Commit

Permalink
fix: 修复api模式下内容重复输出问题
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Dec 3, 2023
1 parent 5cdab82 commit e540f5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 61 deletions.
81 changes: 23 additions & 58 deletions src/lib/bots/bing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,16 @@ const getOptionSets = (conversationStyle: BingConversationStyle, allowSeach = tr
'responsible_ai_policy_235',
'enablemm',
'dv3sugg',
'machine_affinity',
'autosave',
'iyxapbing',
'iycapbing',
'h3imaginative',
'uquopt',
'gcccomp',
'utildv3tosah',
'cpcandi',
'cpcatral3',
'cpcatro50',
'cpcfmql',
'cpcgnddi',
'cpcmattr2',
'cpcmcit1',
'e2ecacheread',
'nocitpass',
'iypapyrus',
'hlthcndans',
'dv3suggtrim',
'gptvprvc',
'fluxpcalc',
'eredirecturl',
'clgalileo',
'gencontentv3'
'gencontentv3',
'fluxv14l'
],
[BingConversationStyle.Balanced]: [
'nlu_direct_response_filter',
Expand All @@ -61,28 +48,14 @@ const getOptionSets = (conversationStyle: BingConversationStyle, allowSeach = tr
'responsible_ai_policy_235',
'enablemm',
'dv3sugg',
'machine_affinity',
'autosave',
'iyxapbing',
'iycapbing',
'galileo',
'saharagenconv5',
'uquopt',
'gcccomp',
'utildv3tosah',
'cpcandi',
'cpcatral3',
'cpcatro50',
'cpcfmql',
'cpcgnddi',
'cpcmattr2',
'cpcmcit1',
'e2ecacheread',
'nocitpass',
'iypapyrus',
'hlthcndans',
'dv3suggtrim',
'eredirecturl'
'gptvprvc',
'fluxpcalc',
'eredirecturl',
'saharagenconv5'
],
[BingConversationStyle.Precise]: [
'nlu_direct_response_filter',
Expand All @@ -91,41 +64,33 @@ const getOptionSets = (conversationStyle: BingConversationStyle, allowSeach = tr
'responsible_ai_policy_235',
'enablemm',
'dv3sugg',
'machine_affinity',
'autosave',
'iyxapbing',
'iycapbing',
'h3precise',
'gptvprvc',
'fluxpcalc',
'eredirecturl',
'clgalileo',
'gencontentv3',
'uquopt',
'gcccomp',
'utildv3tosah',
'cpcandi',
'cpcatral3',
'cpcatro50',
'cpcfmql',
'cpcgnddi',
'cpcmattr2',
'cpcmcit1',
'e2ecacheread',
'nocitpass',
'iypapyrus',
'hlthcndans',
'dv3suggtrim',
'eredirecturl'
'fluxv14l'
],
[BingConversationStyle.Base]: [
'saharasugg',
'enablenewsfc',
'gencontentv3',
'deepleo',
'disable_emoji_spoken_text',
'responsible_ai_policy_235',
'enablemm',
'h3precisedtappid',
'cricinfo',
'cricinfov2',
'dv3sugg',
'autosave',
'iyxapbing',
'iycapbing',
'h3imaginative',
'gptvprvc',
'fluxpcalc',
'eredirecturl',
'clgalileo',
'gencontentv3',
'fluxv14l',
'nojbfedge',
]
}[conversationStyle]
Expand Down
7 changes: 4 additions & 3 deletions src/pages/api/openai/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function parseOpenAIMessage(request: APIRequest) {
prompt,
context,
stream: request.stream,
allowSearch: /gpt-?4/i.test(request.model),
model: /Creative|gpt-?4/i.test(request.model) ? 'Creative' : 'Balanced',
allowSearch: !/Creative|Balanced|Precise/i.test(request.model),
model: /Creative|gpt-?4/i.test(request.model) ? 'Creative' : request.model,
};
}

Expand Down Expand Up @@ -72,7 +72,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
req.socket.once('close', () => {
abortController.abort()
})
const { prompt, stream, model, context } = parseOpenAIMessage(req.body);
const { prompt, stream, model, allowSearch, context } = parseOpenAIMessage(req.body);
let lastLength = 0
let lastText = ''
try {
Expand All @@ -92,6 +92,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
prompt,
context,
options: {
allowSearch,
bingConversationStyle: Object.values(BingConversationStyle)
.includes(toneType) ? toneType : BingConversationStyle.Creative,
},
Expand Down

0 comments on commit e540f5d

Please sign in to comment.