Skip to content

Commit 5de174b

Browse files
committed
Merge remote-tracking branch 'origin/master' into onprem-gpu
2 parents 112dd09 + 837fead commit 5de174b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1444
-425
lines changed

src/packages/frontend/account/chatbot.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ When new models are added, e.g., Claude soon (!), they will go here.
88
*/
99

1010
import { redux } from "@cocalc/frontend/app-framework";
11+
import {
12+
getUserDefinedLLMByModel
13+
} from "@cocalc/frontend/frame-editors/llm/use-userdefined-llm";
1114
import {
1215
LANGUAGE_MODELS,
1316
LANGUAGE_MODEL_PREFIXES,
@@ -20,6 +23,7 @@ import {
2023
isCustomOpenAI,
2124
isMistralService,
2225
isOllamaLLM,
26+
isUserDefinedModel
2327
} from "@cocalc/util/db-schema/llm-utils";
2428

2529
// we either check if the prefix is one of the known ones (used in some circumstances)
@@ -30,7 +34,8 @@ export function isChatBot(account_id?: string): boolean {
3034
LANGUAGE_MODEL_PREFIXES.some((prefix) => account_id?.startsWith(prefix)) ||
3135
LANGUAGE_MODELS.some((model) => account_id === model) ||
3236
isOllamaLLM(account_id) ||
33-
isCustomOpenAI(account_id)
37+
isCustomOpenAI(account_id) ||
38+
isUserDefinedModel(account_id)
3439
);
3540
}
3641

@@ -62,5 +67,9 @@ export function chatBotName(account_id?: string): string {
6267
const key = fromCustomOpenAIModel(account_id);
6368
return custom_openai[key]?.display ?? "OpenAI (custom)";
6469
}
70+
if (isUserDefinedModel(account_id)) {
71+
const um = getUserDefinedLLMByModel(account_id);
72+
return um?.display ?? "ChatBot";
73+
}
6574
return "ChatBot";
6675
}

src/packages/frontend/account/custom-llm.tsx

Lines changed: 0 additions & 255 deletions
This file was deleted.

src/packages/frontend/account/other-settings.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Card, InputNumber } from "antd";
77
import { Map } from "immutable";
88

99
import { Checkbox, Panel } from "@cocalc/frontend/antd-bootstrap";
10-
import { Rendered, redux } from "@cocalc/frontend/app-framework";
10+
import { Rendered, redux, useTypedRedux } from "@cocalc/frontend/app-framework";
1111
import {
1212
A,
1313
Icon,
@@ -30,10 +30,10 @@ import {
3030
VBAR_OPTIONS,
3131
getValidVBAROption,
3232
} from "../project/page/vbar";
33-
import { CustomLLM } from "./custom-llm";
3433
import { dark_mode_mins, get_dark_mode_config } from "./dark-mode";
3534
import Tours from "./tours";
3635
import { useLanguageModelSetting } from "./useLanguageModelSetting";
36+
import { UserDefinedLLMComponent } from "./user-defined-llm";
3737

3838
interface Props {
3939
other_settings: Map<string, any>;
@@ -42,6 +42,8 @@ interface Props {
4242
}
4343

4444
export function OtherSettings(props: Readonly<Props>): JSX.Element {
45+
const isCoCalcCom = useTypedRedux("customize", "is_cocalc_com");
46+
const user_defined_llm = useTypedRedux("customize", "user_defined_llm");
4547
const [model, setModel] = useLanguageModelSetting();
4648

4749
function on_change(name: string, value: any): void {
@@ -391,10 +393,9 @@ export function OtherSettings(props: Readonly<Props>): JSX.Element {
391393
}
392394

393395
function render_custom_llm(): Rendered {
394-
// This is disabled for now, will be enabled in a future PR
395-
return;
396-
// @ts-ignore
397-
return <CustomLLM on_change={on_change} />;
396+
// on cocalc.com, do not even show that they're disabled
397+
if (isCoCalcCom && !user_defined_llm) return;
398+
return <UserDefinedLLMComponent on_change={on_change} />;
398399
}
399400

400401
if (props.other_settings == null) {

src/packages/frontend/account/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MessageInfo } from "@cocalc/frontend/client/hub";
1010
import {
1111
NEW_FILENAMES,
1212
NewFilenameTypes,
13+
OTHER_SETTINGS_USERDEFINED_LLM,
1314
} from "@cocalc/util/db-schema/defaults";
1415
import { LanguageModel } from "@cocalc/util/db-schema/llm-utils";
1516
import { PassportStrategyFrontend } from "@cocalc/util/types/passport-types";
@@ -46,6 +47,7 @@ export interface AccountState {
4647
dark_mode_sepia: number;
4748
dark_mode_grayscale: number;
4849
news_read_until: number; // JavaScript timestamp in milliseconds
50+
[OTHER_SETTINGS_USERDEFINED_LLM]: string; // string is JSON: CustomLLM[]
4951
}>;
5052
stripe_customer?: TypedMap<{
5153
subscriptions: { data: Map<string, any> };

src/packages/frontend/account/useLanguageModelSetting.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { redux, useMemo, useTypedRedux } from "@cocalc/frontend/app-framework";
2+
import { getUserDefinedLLM } from "@cocalc/frontend/frame-editors/llm/use-userdefined-llm";
23
import {
34
LLMServicesAvailable,
45
LanguageService,
@@ -7,6 +8,8 @@ import {
78
getValidLanguageModelName,
89
isCustomOpenAI,
910
isOllamaLLM,
11+
isUserDefinedModel,
12+
unpackUserDefinedLLMModel,
1013
} from "@cocalc/util/db-schema/llm-utils";
1114

1215
export const SETTINGS_LANGUAGE_MODEL_KEY = "language_model";
@@ -78,11 +81,21 @@ export function setDefaultLLM(llm: LanguageService) {
7881
isCustomOpenAI(llm) &&
7982
custom_openai?.get(fromCustomOpenAIModel(llm))
8083
) {
81-
// ... or a custom_openai llm
84+
redux
85+
.getActions("account")
86+
.set_other_settings(SETTINGS_LANGUAGE_MODEL_KEY, llm);
87+
} else if (isUserDefinedModel(llm) && userDefinedLLMExists(llm)) {
8288
redux
8389
.getActions("account")
8490
.set_other_settings(SETTINGS_LANGUAGE_MODEL_KEY, llm);
8591
} else {
8692
console.warn(`setDefaultLLM: LLM "${llm}" is unknown.`);
8793
}
8894
}
95+
96+
function userDefinedLLMExists(model: string): boolean {
97+
const user_llm = getUserDefinedLLM();
98+
const um = unpackUserDefinedLLMModel(model);
99+
if (um == null) return false;
100+
return user_llm.some((m) => m.service === um.service && m.model === um.model);
101+
}

0 commit comments

Comments
 (0)