Skip to content

Commit ecca97b

Browse files
committed
simplify to avoid recursion
1 parent e8121ac commit ecca97b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

apps/web/utils/llms/model.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ export function getModel(
1818
model: string;
1919
llmModel: LanguageModelV1;
2020
} {
21-
if (useEconomyModel) return getEconomyModel(userAi);
21+
if (useEconomyModel) return selectEconomyModel(userAi);
22+
return selectModel(userAi);
23+
}
2224

25+
function selectModel(userAi: UserAIFields): {
26+
provider: string;
27+
model: string;
28+
llmModel: LanguageModelV1;
29+
} {
2330
const defaultProvider = getDefaultProvider();
2431
const aiApiKey = userAi.aiApiKey;
2532
let aiProvider: string;
@@ -136,19 +143,19 @@ export function getModel(
136143
* - Bulk processing emails
137144
* - Any task with large context windows where cost efficiency matters
138145
*/
139-
function getEconomyModel(userAi: UserAIFields) {
146+
function selectEconomyModel(userAi: UserAIFields) {
140147
if (env.ECONOMY_LLM_PROVIDER && env.ECONOMY_LLM_MODEL) {
141148
const apiKey = getProviderApiKey(env.ECONOMY_LLM_PROVIDER);
142-
if (!apiKey) return getModel(userAi);
149+
if (!apiKey) return selectModel(userAi);
143150

144-
return getModel({
151+
return selectModel({
145152
aiProvider: env.ECONOMY_LLM_PROVIDER,
146153
aiModel: env.ECONOMY_LLM_MODEL,
147154
aiApiKey: apiKey,
148155
});
149156
}
150157

151-
return getModel(userAi);
158+
return selectModel(userAi);
152159
}
153160

154161
function getProviderApiKey(

0 commit comments

Comments
 (0)