bunnybun07 commited on
Commit
cfe09c2
·
verified ·
1 Parent(s): f3dbae9

Create Temp

Browse files
Files changed (1) hide show
  1. Temp +91 -0
Temp ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * 将 OpenAI 格式参数转换为 PromptPlayer 支持的参数格式
3
+ * @param {object} openaiParams - OpenAI 格式的参数
4
+ * @param {string} provider - 提供商类型
5
+ * @param {string} model - 模型名称
6
+ * @returns {object} - PromptPlayer 格式的参数
7
+ */
8
+ function convertOpenAIParamsToPromptPlayer(openaiParams, provider, model) {
9
+ let params = {}
10
+ switch (provider) {
11
+ case "google":
12
+ params = {
13
+ response_format: openaiParams.response_format || null,
14
+ candidateCount: openaiParams.candidateCount || null,
15
+ stopSequences: openaiParams.stop || null,
16
+ maxOutputTokens: openaiParams.max_tokens ?? 50000,
17
+ temperature: openaiParams.temperature ?? 1,
18
+ topP: openaiParams.top_p ?? null,
19
+ topK: openaiParams.top_k ?? null
20
+ };
21
+ break;
22
+
23
+ case "anthropic":
24
+ case "anthropic.bedrock":
25
+ params = {
26
+ max_tokens: openaiParams.max_tokens ?? (model.includes("sonnet") ? 64000 : model.includes("opus") ? 32000 : 64000),
27
+ temperature: openaiParams.temperature ?? 1,
28
+ top_k: openaiParams.top_k || null,
29
+ top_p: openaiParams.top_p ?? null
30
+ };
31
+
32
+ // 如果模型名称包含 -thinking 或用户传入 thinking 参数
33
+ if (model.includes("-thinking") || openaiParams.thinking) {
34
+ params.thinking = {
35
+ type: "enabled",
36
+ budget_tokens: openaiParams.thinking?.budget_tokens ?? (params.max_tokens ? Math.floor(params.max_tokens / 2) : null)
37
+ };
38
+ }
39
+ break;
40
+
41
+ case "mistral":
42
+ params = {
43
+ temperature: openaiParams.temperature ?? 0.3,
44
+ top_p: openaiParams.top_p ?? 1,
45
+ max_tokens: openaiParams.max_tokens ?? null,
46
+ safe_prompt: openaiParams.safe_prompt || null,
47
+ random_seed: openaiParams.seed || null
48
+ };
49
+ break;
50
+
51
+ case "cohere":
52
+ params = {
53
+ max_tokens: openaiParams.max_tokens ?? null,
54
+ temperature: openaiParams.temperature ?? 0.3,
55
+ k: openaiParams.top_k ?? 0,
56
+ p: openaiParams.top_p ?? 0,
57
+ presence_penalty: openaiParams.presence_penalty ?? 0,
58
+ frequency_penalty: openaiParams.frequency_penalty ?? 0
59
+ };
60
+ break;
61
+
62
+ case "openai":
63
+ case "openai.azure":
64
+ default:
65
+ params = {
66
+ temperature: openaiParams.temperature ?? 1,
67
+ seed: openaiParams.seed || null,
68
+ response_format: openaiParams.response_format || null,
69
+ top_p: openaiParams.top_p ?? 1,
70
+ frequency_penalty: openaiParams.frequency_penalty || null,
71
+ presence_penalty: openaiParams.presence_penalty || null,
72
+ max_completion_tokens: openaiParams.max_tokens ?? null,
73
+ reasoning_effort: openaiParams.reasoning_effort || null
74
+ };
75
+
76
+ // 特殊判断,如果模型名称为 o4-mini,则设置 reasoning_effort 为 high
77
+ if (model.includes("o4-mini")) {
78
+ params.reasoning_effort = "high";
79
+ }
80
+ break;
81
+ }
82
+
83
+ // 去掉为空的参数
84
+ Object.keys(params).forEach(key => {
85
+ if (params[key] === null || params[key] === undefined) {
86
+ delete params[key];
87
+ }
88
+ });
89
+
90
+ return params;
91
+ }