mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-04 18:30:14 +08:00
feat: temperature config (#256)
This commit is contained in:
@@ -105,6 +105,7 @@ export const defaultConfig = {
|
||||
|
||||
maxResponseTokenLength: 1000,
|
||||
maxConversationContextLength: 9,
|
||||
temperature: 1,
|
||||
customChatGptWebApiUrl: 'https://chat.openai.com',
|
||||
customChatGptWebApiPath: '/backend-api/conversation',
|
||||
customOpenAiApiUrl: 'https://api.openai.com',
|
||||
|
||||
+19
-4
@@ -33,6 +33,7 @@ import {
|
||||
isMobile,
|
||||
isSafari,
|
||||
openUrl,
|
||||
parseFloatWithClamp,
|
||||
parseIntWithClamp,
|
||||
} from '../utils/index.mjs'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@@ -432,9 +433,9 @@ function AdvancedPart({ config, updateConfig }) {
|
||||
return (
|
||||
<>
|
||||
<label>
|
||||
{t('Max Response Token Length')}
|
||||
{t('Max Response Token Length') + `: ${config.maxResponseTokenLength}`}
|
||||
<input
|
||||
type="number"
|
||||
type="range"
|
||||
min="100"
|
||||
max="40000"
|
||||
step="100"
|
||||
@@ -446,9 +447,9 @@ function AdvancedPart({ config, updateConfig }) {
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t('Max Conversation Length')}
|
||||
{t('Max Conversation Length') + `: ${config.maxConversationContextLength}`}
|
||||
<input
|
||||
type="number"
|
||||
type="range"
|
||||
min="0"
|
||||
max="100"
|
||||
step="1"
|
||||
@@ -459,6 +460,20 @@ function AdvancedPart({ config, updateConfig }) {
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t('Temperature') + `: ${config.temperature}`}
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="2"
|
||||
step="0.1"
|
||||
value={config.temperature}
|
||||
onChange={(e) => {
|
||||
const value = parseFloatWithClamp(e.target.value, 1, 0, 2)
|
||||
updateConfig({ temperature: value })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t('Custom ChatGPT Web API Url')}
|
||||
<input
|
||||
|
||||
@@ -36,6 +36,7 @@ export async function generateAnswersWithAzureOpenaiApi(port, question, session)
|
||||
messages: prompt,
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
}),
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
|
||||
@@ -43,6 +43,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
|
||||
model: modelName,
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
}),
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
|
||||
@@ -50,6 +50,7 @@ export async function generateAnswersWithGptCompletionApi(
|
||||
model: Models[modelName].value,
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
}),
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
@@ -114,6 +115,7 @@ export async function generateAnswersWithChatgptApi(port, question, session, api
|
||||
model: Models[modelName].value,
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
}),
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
|
||||
@@ -13,6 +13,7 @@ export * from './is-mobile'
|
||||
export * from './is-safari'
|
||||
export * from './limited-fetch'
|
||||
export * from './open-url'
|
||||
export * from './parse-float-with-clamp'
|
||||
export * from './parse-int-with-clamp'
|
||||
export * from './set-element-position-in-viewport'
|
||||
export * from './stream-async-iterable'
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export function parseFloatWithClamp(value, defaultValue, min, max) {
|
||||
value = parseFloat(value)
|
||||
|
||||
if (isNaN(value)) value = defaultValue
|
||||
else if (value > max) value = max
|
||||
else if (value < min) value = min
|
||||
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user