-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
/
index.ts
50 lines (46 loc) · 1.7 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { ModelProvider } from '../types';
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
import { QwenAIStream } from '../utils/streams';
/*
QwenLegacyModels: A set of legacy Qwen models that do not support presence_penalty.
Currently, presence_penalty is only supported on Qwen commercial models and open-source models starting from Qwen 1.5 and later.
*/
export const QwenLegacyModels = new Set([
'qwen-72b-chat',
'qwen-14b-chat',
'qwen-7b-chat',
'qwen-1.8b-chat',
'qwen-1.8b-longcontext-chat',
]);
export const LobeQwenAI = LobeOpenAICompatibleFactory({
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
chatCompletion: {
handlePayload: (payload) => {
const { model, presence_penalty, temperature, top_p, ...rest } = payload;
return {
...rest,
frequency_penalty: undefined,
model,
presence_penalty:
QwenLegacyModels.has(model)
? undefined
: (presence_penalty !== undefined && presence_penalty >= -2 && presence_penalty <= 2)
? presence_penalty
: undefined,
stream: !payload.tools,
temperature: (temperature !== undefined && temperature >= 0 && temperature < 2) ? temperature : undefined,
...(model.startsWith('qwen-vl') ? {
top_p: (top_p !== undefined && top_p > 0 && top_p <= 1) ? top_p : undefined,
} : {
enable_search: true,
top_p: (top_p !== undefined && top_p > 0 && top_p < 1) ? top_p : undefined,
}),
} as any;
},
handleStream: QwenAIStream,
},
debug: {
chatCompletion: () => process.env.DEBUG_QWEN_CHAT_COMPLETION === '1',
},
provider: ModelProvider.Qwen,
});