Skip to content

Commit 1addbd7

Browse files
committed
Refactor temperature handling + improve options extraction in custom APIs
1 parent aa7c4e1 commit 1addbd7

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/api/Providers/deepinfra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const DeepInfraProvider = {
141141
model: model,
142142
messages: json_chat,
143143
tools: tools.length > 0 ? tools : undefined,
144-
temperature: options.temperature,
144+
temperature: options.temperature ?? 0.7,
145145
max_tokens: 100000,
146146
stream: true,
147147
...overrides[model],

src/api/Providers/replicate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const ReplicateProvider = {
3232
prompt: format_chat_to_prompt(chat, { model: model }),
3333
max_tokens: model.includes("meta-llama-3") ? 512 : null, // respected by meta-llama-3
3434
max_new_tokens: model.includes("mixtral") ? 1024 : null, // respected by mixtral-8x7b
35-
temperature: options.temperature,
35+
temperature: options.temperature ?? 0.7,
3636
},
3737
};
3838

src/api/Providers/special/custom_openai.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const CustomOpenAIProvider = {
2525
isCustom: true,
2626
config: {},
2727
generate: async function* (chat, options) {
28-
const url = options.url;
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
let { url, model, apiKey, config: _, ...reqBody } = options;
2930

3031
let apiData = {};
3132
try {
@@ -36,7 +37,6 @@ export const CustomOpenAIProvider = {
3637

3738
// Initialize
3839
const api_url = url.endsWith("/chat/completions") ? url : url + "/chat/completions";
39-
let { model, apiKey, ...reqBody } = options;
4040
apiKey = apiKey || apiData.apiKey;
4141
const config = { ...this.config, ...apiData.config };
4242

@@ -54,8 +54,8 @@ export const CustomOpenAIProvider = {
5454
messages: chat,
5555
stream: true,
5656
model: model,
57-
...config,
5857
...reqBody,
58+
...config, // config overrides reqBody
5959
};
6060

6161
let response = await fetch(

src/api/providers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const additional_provider_options = (provider, chatOptions = null) => {
1313
let options = {};
1414
if (chatOptions?.creativity) {
1515
let temperature = Number(chatOptions.creativity);
16-
temperature = Math.max(0.0, temperature).toFixed(1);
16+
temperature = Math.max(0.0, temperature);
1717
options.temperature = temperature;
1818
} else {
1919
options.temperature = 0.7;
@@ -48,13 +48,14 @@ export const get_provider_info = (providerString) => {
4848

4949
// Get options from info
5050
export const get_options_from_info = (info, chatOptions = {}) => {
51-
// we delete the provider key since it's not an option
52-
return {
51+
let o = {
5352
...(info || {}),
54-
...(chatOptions || {}),
53+
config: { ...(chatOptions || {}) },
5554
...additional_provider_options(info?.provider, chatOptions),
56-
provider: undefined,
5755
};
56+
// we delete the provider key since it's not an option
57+
delete o.provider;
58+
return o;
5859
};
5960

6061
// Get provider info from alias

0 commit comments

Comments
 (0)