Skip to content

Commit f8f18c6

Browse files
fix(chat): skip temperature sending when such feature is disabled (Issue #6449) (#6459)
1 parent 77a1221 commit f8f18c6

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

apps/chat/src/pages/api/chat.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import { ChatBody } from '@/src/types/chat';
2323
import { EntityType } from '@/src/types/common';
2424

2525
import { DEFAULT_SYSTEM_PROMPT } from '@/src/constants/default-server-settings';
26-
import {
27-
DEFAULT_TEMPERATURE,
28-
FALLBACK_TEMPERATURE,
29-
} from '@/src/constants/default-ui-settings';
26+
import { DEFAULT_TEMPERATURE } from '@/src/constants/default-ui-settings';
3027
import { errorsMessages } from '@/src/constants/errors';
3128

3229
import { authOptions } from './auth/[...nextauth]';
@@ -65,9 +62,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
6562
}
6663

6764
let temperatureToUse = temperature;
68-
if (!doesModelAllowTemperature(model)) {
69-
temperatureToUse = FALLBACK_TEMPERATURE;
70-
} else if (
65+
if (
66+
doesModelAllowTemperature(model) &&
7167
!temperatureToUse &&
7268
temperatureToUse !== 0 &&
7369
model.type !== EntityType.Application
@@ -111,7 +107,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
111107

112108
const stream = await OpenAIStream({
113109
model,
114-
temperature: temperatureToUse,
115110
messages: messagesToSend,
116111
userJWT: token?.token ?? '',
117112
chatReference: reference ?? id,
@@ -120,6 +115,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
120115
? limits?.maxRequestTokens
121116
: undefined,
122117
configurationSchemaValue: configurationValue,
118+
...(temperatureToUse !== undefined && { temperature: temperatureToUse }),
123119
});
124120
res.setHeader('Transfer-Encoding', 'chunked');
125121
res.setHeader('Content-Type', 'application/octet-stream');

apps/chat/src/store/conversations/conversations.epics.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ import { LOCAL_BUCKET } from '@/src/constants/chat';
120120
import {
121121
DEFAULT_CONVERSATION_NAME,
122122
DEFAULT_TEMPERATURE,
123-
FALLBACK_TEMPERATURE,
124123
} from '@/src/constants/default-ui-settings';
125124
import { errorsMessages } from '@/src/constants/errors';
126125
import { DEFAULT_EXTERNAL_APPS_SCHEMA_ID } from '@/src/constants/external-apps';
@@ -1520,17 +1519,18 @@ const streamMessageEpic: AppEpic = (action$, state$) =>
15201519
const modelsMap = ModelsSelectors.selectModelsMap(state$.value);
15211520
const lastModel = modelsMap[payload.conversation.model.id];
15221521
const conversationModelType = lastModel?.type ?? EntityType.Model;
1523-
let modelAdditionalSettings = {};
1522+
const modelAdditionalSettings: Partial<
1523+
Pick<ChatBody, 'prompt' | 'temperature'>
1524+
> = {};
15241525

15251526
if (conversationModelType === EntityType.Model) {
1526-
modelAdditionalSettings = {
1527-
prompt: doesModelAllowSystemPrompt(lastModel)
1528-
? payload.conversation.prompt
1529-
: undefined,
1530-
temperature: doesModelAllowTemperature(lastModel)
1531-
? payload.conversation.temperature
1532-
: FALLBACK_TEMPERATURE,
1533-
};
1527+
if (doesModelAllowSystemPrompt(lastModel)) {
1528+
modelAdditionalSettings.prompt = payload.conversation.prompt;
1529+
}
1530+
if (doesModelAllowTemperature(lastModel)) {
1531+
modelAdditionalSettings.temperature =
1532+
payload.conversation.temperature;
1533+
}
15341534
}
15351535

15361536
const chatBody: ChatBody = {

apps/chat/src/utils/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ export const OpenAIStream = async ({
6363
configurationSchemaValue,
6464
}: {
6565
model: DialAIEntityModel;
66-
temperature: number | undefined;
6766
messages: Message[];
6867
userJWT: string;
6968
chatReference: string;
7069
jobTitle: string | undefined;
7170
maxRequestTokens: number | undefined;
7271
configurationSchemaValue?: MessageFormValue;
72+
temperature?: number;
7373
}) => {
7474
let messagesToSend = messages;
7575
const url = getUrl(model);

0 commit comments

Comments
 (0)