feat: add support for temperature, top_p to be configurable (#2200)

Co-authored-by: twix03 <sathwikbalaa@gmail.com>
Co-authored-by: RainbowBird <git@luoling.moe>
This commit is contained in:
Vikranth Kumar Bala
2026-09-08 00:02:53 +08:00
committed by GitHub
co-authored by twix03 RainbowBird
parent 66c6aa9b57
commit e293b71abc
17 changed files with 179 additions and 39 deletions
@@ -62,6 +62,10 @@ export interface ChatOrchestratorSendOptions {
toolReferences?: ChatToolReference[]
/** Original transport input metadata used by bridge/devtools observers. */
input?: ChatStreamEventContext['input']
/** Temperature for the LLM request. */
temperature?: number
/** Top_p for the LLM request. */
topP?: number
}
interface QueuedSend {
@@ -766,6 +770,8 @@ export function createChatOrchestratorRuntime(deps: ChatOrchestratorRuntimeDeps)
roundId: correlation.roundId,
},
tools: options.tools,
temperature: options.temperature,
topP: options.topP,
waitForTools: true,
onMessages: (messages) => {
const currentTurnMessages = messages.slice(providerInputMessageCount)
@@ -198,6 +198,8 @@ export async function streamFrom({
messages: sanitized,
headers: options?.headers,
streamOptions: { includeUsage: true },
temperature: options?.temperature,
topP: options?.topP,
stopWhen: stepCountAtLeast(10),
tools,
toolChoice: options?.toolChoice,
+11
View File
@@ -34,6 +34,17 @@ export interface StreamOptions {
conversationId: string
roundId: string
}
/**
* The temperature parameter controls the randomness of the model's output.
* A lower value results in more deterministic and focused output, while a
* higher value increases creativity and diversity.
*/
temperature?: number
/**
* The top_p parameter controls nucleus sampling. A value of 0.1 means only
* the tokens comprising the top 10% probability mass are considered.
*/
topP?: number
toolsCompatibility?: Map<string, boolean>
supportsTools?: boolean
waitForTools?: boolean
@@ -685,6 +685,10 @@ pages:
search_results: Found {count} of {total} models
show_less: Show less
show_more: Show more
temperature_label: Temperature
temperature_description: Control the randomness of the model's output. A lower value (e.g. 0.2) results in more deterministic, precise, and analytical output, while a higher value (e.g. 1.0) increases creativity and diversity.
top_p_label: Top P
top_p_description: Control the diversity of the model's output via nucleus sampling. A lower value (e.g. 0.2) limits the output to only high-probability tokens, while a higher value (e.g. 1.0) includes a broader set of possibilities.
subtitle: Select a default model from the provider
title: Model
model-options:
@@ -660,6 +660,10 @@ pages:
search_results: 找到 {count} / {total} 个模型
show_less: 显示更多
show_more: 收起
temperature_label: 温度
temperature_description: 控制模型输出的随机性。较低的温度(例如 0.2)会使输出更精确和确定;较高的温度(例如 1.0)会增加创造力和多样性。
top_p_label: Top P
top_p_description: 控制模型输出的多样性(核采样)。较低的值(例如 0.2)会将输出限制在概率较高的词汇;较高的值(例如 1.0)则会包含更广泛的可能性。
subtitle: 选择一个默认模型
title: 模型
model-options:
@@ -108,6 +108,7 @@ function createBedrockConverseProvider(config: {
inferenceConfig: {
maxTokens: body.max_tokens || 4096,
...(body.temperature !== undefined && { temperature: body.temperature }),
...(body.top_p !== undefined && { topP: body.top_p }),
},
}
if (system)
@@ -6,7 +6,7 @@ import { useConsciousnessStore } from '@proj-airi/stage-ui/stores/modules/consci
import { useConsciousnessSettingsStore } from '@proj-airi/stage-ui/stores/modules/consciousness-settings'
import { useProviderConfigStore } from '@proj-airi/stage-ui/stores/providers/config'
import { useProviderStore } from '@proj-airi/stage-ui/stores/providers/provider'
import { FieldCheckbox } from '@proj-airi/ui'
import { FieldCheckbox, FieldRange } from '@proj-airi/ui'
import { storeToRefs } from 'pinia'
import { watch } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -29,6 +29,8 @@ const {
providerModels,
isLoadingActiveProviderModels,
activeProviderModelError,
activeTemperature,
activeTopP,
} = storeToRefs(consciousnessStore)
const { t } = useI18n()
@@ -304,6 +306,29 @@ async function updateReasoning(value: boolean) {
</section>
</div>
<div v-if="activeProvider" :class="['bg-neutral-50 dark:bg-[rgba(0,0,0,0.3)]', 'rounded-xl', 'p-4', 'flex flex-col gap-4', 'mt-4']">
<div :class="['flex flex-col gap-4']">
<FieldRange
v-model="activeTemperature"
:label="t('settings.pages.modules.consciousness.sections.section.provider-model-selection.temperature_label')"
:description="t('settings.pages.modules.consciousness.sections.section.provider-model-selection.temperature_description')"
:min="0"
:max="2"
:step="0.1"
:format-value="value => value.toFixed(1)"
/>
<FieldRange
v-model="activeTopP"
:label="t('settings.pages.modules.consciousness.sections.section.provider-model-selection.top_p_label')"
:description="t('settings.pages.modules.consciousness.sections.section.provider-model-selection.top_p_description')"
:min="0"
:max="1"
:step="0.1"
:format-value="value => value.toFixed(1)"
/>
</div>
</div>
<div
v-motion
text="neutral-200/50 dark:neutral-600/20" pointer-events-none
+6
View File
@@ -58,6 +58,10 @@ export interface ChatSendPayload {
text: string
/** Request-specific tools selected by their model-facing names. */
tools?: ChatToolReference[]
/** Request-specific temperature override. */
temperature?: number
/** Request-specific top_p override. */
topP?: number
}
/** The durable messages appended while one chat request executes. */
@@ -401,6 +405,8 @@ export const useChatStore = defineStore('chat', () => {
attachments: payload.attachments,
input: payload.input,
toolReferences: payload.tools,
temperature: payload.temperature ?? consciousnessStore.activeTemperature,
topP: payload.topP ?? consciousnessStore.activeTopP,
// Resolve this function after the request reaches the per-session queue.
// The history then contains tool names from every earlier queued turn.
tools: async () => {
@@ -56,7 +56,7 @@ export const useContextBridgeStore = defineStore('mods:api:context-bridge', () =
const contextObservability = useContextObservabilityStore()
const characterOrchestratorStore = useCharacterOrchestratorStore()
const consciousnessStore = useConsciousnessStore()
const { activeProvider, activeModel } = storeToRefs(consciousnessStore)
const { activeProvider, activeModel, activeTemperature, activeTopP } = storeToRefs(consciousnessStore)
const streamingControl = useLlmStreamingControlStore()
type SparkNotifyBridgeMessage
@@ -724,6 +724,8 @@ export const useContextBridgeStore = defineStore('mods:api:context-bridge', () =
await chatOrchestrator.ingest(messageText, {
model: activeModel.value,
chatProvider,
temperature: activeTemperature.value,
topP: activeTopP.value,
input: {
type: 'input:text',
data: {
@@ -41,6 +41,18 @@ export const useConsciousnessStore = defineStore('consciousness', () => {
return providersStore.modelLoadError[activeProvider.value] || null
})
const activeTemperature = useLocalStorageManualReset<number>(
'settings/consciousness/active-temperature',
0.7,
persistenceOptions,
)
const activeTopP = useLocalStorageManualReset<number>(
'settings/consciousness/active-top-p',
1.0,
persistenceOptions,
)
const filteredModels = computed(() => {
if (!modelSearchQuery.value.trim()) {
return providerModels.value
@@ -109,6 +121,8 @@ export const useConsciousnessStore = defineStore('consciousness', () => {
function resetState() {
activeProvider.reset()
resetModelSelection()
activeTemperature.reset()
activeTopP.reset()
}
return {
@@ -116,6 +130,8 @@ export const useConsciousnessStore = defineStore('consciousness', () => {
configured,
activeProvider,
activeModel,
activeTemperature,
activeTopP,
customModelName: activeCustomModelName,
expandedDescriptions,
modelSearchQuery,
+5
View File
@@ -21,6 +21,7 @@ export const CharacterCapabilityConfigSchema = object({
apiBaseUrl: string(),
llm: optional(object({
temperature: number(),
topP: optional(number()),
model: string(),
})),
tts: optional(object({
@@ -171,6 +172,10 @@ export const UpdateCharacterSchema = object({
version: optional(string()),
coverUrl: optional(string()),
characterId: optional(string()),
capabilities: optional(array(object({
type: CharacterCapabilityTypeSchema,
config: CharacterCapabilityConfigSchema,
}))),
})
// --- Type Exports ---