Skip to content

Commit 1778106

Browse files
authored
Merge pull request #129 from LyuLumos/main
feat: add generationConfig of Google Gemini & fix: Gemini abort bug
2 parents 1c019ea + aefed85 commit 1778106

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/logics/conversation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ export const callProviderHandler = async(providerId: string, payload: HandlerPay
133133
baseUrl: payload.globalSettings?.baseUrl,
134134
model: payload.globalSettings?.model,
135135
maxTokens: payload.globalSettings?.maxTokens,
136+
maxOutputTokens: payload.globalSettings?.maxOutputTokens,
136137
temperature: payload.globalSettings?.temperature,
137-
top_p: payload.globalSettings?.top_p,
138+
topP: payload.globalSettings?.topP,
139+
topK: payload.globalSettings?.topK,
138140
},
139141
botSettings: payload.botSettings,
140142
})

src/providers/google/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface GoogleFetchPayload {
33
stream: boolean
44
body: Record<string, any>
55
model?: string
6+
signal?: AbortSignal
67
}
78

89
export const fetchChatCompletion = async(payload: GoogleFetchPayload) => {
@@ -11,6 +12,7 @@ export const fetchChatCompletion = async(payload: GoogleFetchPayload) => {
1112
headers: { 'Content-Type': 'application/json' },
1213
method: 'POST',
1314
body: JSON.stringify({ ...body }),
15+
signal: payload.signal,
1416
}
1517
return fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:streamGenerateContent?${stream ? 'alt=sse&' : ''}key=${apiKey}`, initOptions)
1618
}

src/providers/google/handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export const handleRapidPrompt: Provider['handleRapidPrompt'] = async(prompt, gl
1818
globalSettings: {
1919
...globalSettings,
2020
model: 'gemini-pro',
21+
temperature: 0.4,
22+
maxTokens: 10240,
23+
maxOutputTokens: 1024,
24+
topP: 0.8,
25+
topK: 1,
2126
},
2227
botSettings: {},
2328
prompt,
@@ -57,7 +62,14 @@ export const handleChatCompletion = async(payload: HandlerPayload, signal?: Abor
5762
stream,
5863
body: {
5964
contents: parseMessageList(messages),
65+
generationConfig: {
66+
temperature: payload.globalSettings.temperature as number,
67+
maxOutputTokens: payload.globalSettings.maxOutputTokens as number,
68+
topP: payload.globalSettings.topP as number,
69+
topK: payload.globalSettings.topK as number,
70+
}
6071
},
72+
signal,
6173
model: payload.globalSettings.model as string,
6274
})
6375

src/providers/google/index.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,47 @@ const providerGoogle = () => {
3232
type: 'slider',
3333
min: 0,
3434
max: 32768,
35-
default: 2048,
35+
default: 10240,
36+
step: 1,
37+
},
38+
{
39+
key: 'maxOutputTokens',
40+
name: 'Max Output Tokens',
41+
description: 'Specifies the maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.',
42+
type: 'slider',
43+
min: 0,
44+
max: 4096,
45+
default: 1024,
46+
step: 1,
47+
},
48+
{
49+
key: 'temperature',
50+
name: 'Temperature',
51+
description: 'The temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a more deterministic or less open-ended response.',
52+
type: 'slider',
53+
min: 0,
54+
max: 1,
55+
default: 0.4,
56+
step: 0.01,
57+
},
58+
{
59+
key: 'topP',
60+
name: 'Top P',
61+
description: 'An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.',
62+
type: 'slider',
63+
min: 0,
64+
max: 1,
65+
default: 0.95,
66+
step: 0.01,
67+
},
68+
{
69+
key: 'topK',
70+
name: 'Top K',
71+
description: 'Top K sampling chooses from the K most likely tokens.',
72+
type: 'slider',
73+
min: 0,
74+
max: 32768,
75+
default: 1,
3676
step: 1,
3777
},
3878
{

0 commit comments

Comments
 (0)