Skip to content

Commit 6aa739d

Browse files
committed
Add support for extra request body in chatbot config
Introduces 'enableExtraBody' and 'extraBody' fields to chatbot configuration, allowing users to specify additional request parameters. Updates UI to toggle and edit extra body, ensures correct merging in request logic, and adds related localization strings.
1 parent c36c011 commit 6aa739d

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

src/main/assets/config/llm.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"stream": true,
3232
"reasoningEffort": null,
3333
"enableThinking": null,
34+
"enableExtraBody": false,
35+
"extraBody": {},
3436
"authorization": true,
3537
"mcp": true
3638
},

src/renderer/components/common/ConfigJsonCard.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script setup lang="ts">
22
import { ref, computed, watch } from 'vue'
33
4+
defineOptions({
5+
inheritAttrs: false
6+
})
7+
48
const emit = defineEmits(['update:modelValue', 'onError', 'focus', 'blur'])
59
610
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue }
@@ -64,6 +68,7 @@ watch(
6468
variant="solo"
6569
outlined
6670
auto-grow
71+
v-bind="$attrs"
6772
:error-messages="jsonError"
6873
:hide-details="!Boolean(jsonError ?? '')"
6974
@focus="handleFocus"

src/renderer/components/pages/SettingPage.vue

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useLayoutStore } from '@/renderer/store/layout'
66
import { v4 as uuidv4 } from 'uuid'
77
import { getApiToken, listenStdioProgress, removeListenStdioProgress } from '@/renderer/utils'
88
import LogoAvatar from '@/renderer/components/common/LogoAvatar.vue'
9+
import ConfigJsonCard from '@/renderer/components/common/ConfigJsonCard.vue'
10+
911
import type { ChatbotConfig } from '@/types/llm'
1012
1113
const layoutStore = useLayoutStore()
@@ -25,8 +27,7 @@ interface Emits {
2527
(_e: 'batch:token', _apiCli: string, _apiKey: string): void
2628
}
2729
28-
// const props =
29-
defineProps<Props>()
30+
const props = defineProps<Props>()
3031
const emit = defineEmits<Emits>()
3132
const handleUpdate = <K extends keyof ChatbotConfig>(key: K, value: ChatbotConfig[K]) => {
3233
emit('update:config', { [key]: value } as Partial<ChatbotConfig>)
@@ -45,6 +46,21 @@ watch(apiDialog, (_val) => {
4546
stderr.value.length = 0
4647
})
4748
49+
watch(
50+
() => props.config.enableExtraBody,
51+
async (val) => {
52+
if (val) {
53+
domExtraBody.value?.scrollIntoView({
54+
behavior: 'smooth',
55+
block: 'center'
56+
})
57+
}
58+
},
59+
{ flush: 'post' }
60+
)
61+
62+
const domExtraBody = ref<HTMLElement | null>(null)
63+
4864
const handleGetApiToken = async (cli: string): Promise<void> => {
4965
const handleProgress = (_event: Event, progress: string) => {
5066
stdout.value.push(progress)
@@ -344,15 +360,33 @@ const validateNumberRange = (min: number, max: number) => {
344360
<v-btn-toggle
345361
class="mt-0"
346362
color="secondary"
363+
v-tooltip:top="$t('setting.enable-thinking-tip')"
347364
:model-value="config.enableThinking"
348365
variant="plain"
349366
@update:model-value="(v) => handleUpdate('enableThinking', v)"
350367
>
351368
<v-btn v-for="level in ENABLE_THINKING" :key="level">{{ level }}</v-btn>
352369
</v-btn-toggle>
353370
</v-field>
371+
<v-switch
372+
min-width="200px"
373+
class="ml-4"
374+
:label="$t('setting.enable-extra-body')"
375+
color="secondary"
376+
base-color="primary"
377+
hide-details
378+
inset
379+
:model-value="config.enableExtraBody"
380+
@update:model-value="(v) => handleUpdate('enableExtraBody', Boolean(v))"
381+
></v-switch>
354382
</v-card-text>
355383
</v-card>
384+
<div ref="domExtraBody">
385+
<v-card v-if="config.enableExtraBody" class="mx-auto mt-4" :title="$t('setting.extra-body')">
386+
<v-divider></v-divider>
387+
<ConfigJsonCard v-model="config.extraBody" clearable rows="1"> </ConfigJsonCard>
388+
</v-card>
389+
</div>
356390
</template>
357391
<style scoped>
358392
.cursor-pointer {

src/renderer/composables/chatCompletions.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,32 @@ export const createCompletion = async (
166166
}
167167
}
168168

169+
const extraBody = chatbotConfig.enableExtraBody ? chatbotConfig.extraBody : {}
170+
169171
const body: ChatRequestBody = {
170172
model: chatbotConfig.model,
171-
stream: chatbotConfig.stream
173+
stream: chatbotConfig.stream,
174+
...extraBody
172175
}
173176

177+
console.log(body)
178+
174179
if (typeof chatbotConfig.reasoningEffort === 'number') {
175180
body['reasoning_effort'] = REASONING_EFFORT[chatbotConfig.reasoningEffort]
176181
}
177182

178183
if (typeof chatbotConfig.enableThinking === 'number') {
179184
if (ENABLE_THINKING[chatbotConfig.enableThinking] === 'true') {
180-
body['chat_template_kwargs'] = { enable_thinking: true }
185+
body['chat_template_kwargs'] = {
186+
enable_thinking: true,
187+
thinking: true
188+
}
181189
body['enable_thinking'] = true
182190
} else if (ENABLE_THINKING[chatbotConfig.enableThinking] === 'false') {
183-
body['chat_template_kwargs'] = { enable_thinking: false }
191+
body['chat_template_kwargs'] = {
192+
enable_thinking: false,
193+
thinking: false
194+
}
184195
body['enable_thinking'] = false
185196
}
186197
}

src/renderer/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
"temperature": "Temperature",
125125
"topP": "Top P",
126126
"enable-thinking": "Enable Thinking",
127+
"enable-thinking-tip": "Will override thinking/enable_thinking in extra body",
128+
"enable-extra-body": "Enable Extra Body",
129+
"extra-body": "Extra Body",
127130
"reasoning-effort": "Reasoning Effort",
128131
"auth-header": "Auth Header",
129132
"auth-prefix": "Auth Prefix",

src/renderer/locales/zh.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
"temperature": "温度",
125125
"topP": "核采样",
126126
"enable-thinking": "思考模式",
127+
"enable-thinking-tip": "会覆盖额外消息体中的 thinking/enable_thinking 字段",
128+
"enable-extra-body": "额外消息体",
129+
"extra-body": "额外消息体",
127130
"reasoning-effort": "推理负荷",
128131
"auth-header": "鉴权头",
129132
"auth-prefix": "鉴权前缀",

src/renderer/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const CHATBOT_DEFAULTS = {
3131
stream: true,
3232
reasoningEffort: undefined,
3333
enableThinking: undefined,
34+
enableExtraBody: false,
35+
extraBody: {},
3436
authorization: true,
3537
mcp: true
3638
}

src/types/llm.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export interface ChatbotConfig {
3434
stream: boolean
3535
reasoningEffort?: number
3636
enableThinking?: number
37+
enableExtraBody: boolean
38+
extraBody: object
3739
authorization: boolean
3840
mcp: boolean
3941
}

0 commit comments

Comments
 (0)