Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/chatbot.ts
Views: 687
/*1We abuse the account_id field in some cases, especially chat, to also2be a string (not a uuid) to refer to various chatbots. Any code that3displays or detects this *should* go through the functions below.45When new models are added, e.g., Claude soon (!), they will go here.67*/89import { redux } from "@cocalc/frontend/app-framework";10import {11getUserDefinedLLMByModel12} from "@cocalc/frontend/frame-editors/llm/use-userdefined-llm";13import {14LANGUAGE_MODELS,15LANGUAGE_MODEL_PREFIXES,16LLM_USERNAMES,17fromAnthropicService,18fromCustomOpenAIModel,19fromMistralService,20fromOllamaModel,21isAnthropicService,22isCustomOpenAI,23isMistralService,24isOllamaLLM,25isUserDefinedModel26} from "@cocalc/util/db-schema/llm-utils";2728// we either check if the prefix is one of the known ones (used in some circumstances)29// or if the account id is exactly one of the language models (more precise)30export function isChatBot(account_id?: string): boolean {31if (typeof account_id !== "string") return false;32return (33LANGUAGE_MODEL_PREFIXES.some((prefix) => account_id?.startsWith(prefix)) ||34LANGUAGE_MODELS.some((model) => account_id === model) ||35isOllamaLLM(account_id) ||36isCustomOpenAI(account_id) ||37isUserDefinedModel(account_id)38);39}4041export function chatBotName(account_id?: string): string {42if (typeof account_id !== "string") return "ChatBot";43if (account_id.startsWith("chatgpt")) {44return LLM_USERNAMES[account_id] ?? "ChatGPT";45}46if (account_id.startsWith("openai-")) {47return LLM_USERNAMES[account_id.slice("openai-".length)] ?? "ChatGPT";48}49if (account_id.startsWith("google-")) {50return LLM_USERNAMES[account_id.slice("google-".length)] ?? "Gemini";51}52if (isMistralService(account_id)) {53return LLM_USERNAMES[fromMistralService(account_id)] ?? "Mistral";54}55if (isAnthropicService(account_id)) {56return LLM_USERNAMES[fromAnthropicService(account_id)] ?? "Anthropic";57}58if (isOllamaLLM(account_id)) {59const ollama = redux.getStore("customize").get("ollama")?.toJS() ?? {};60const key = fromOllamaModel(account_id);61return ollama[key]?.display ?? "Ollama";62}63if (isCustomOpenAI(account_id)) {64const custom_openai =65redux.getStore("customize").get("custom_openai")?.toJS() ?? {};66const key = fromCustomOpenAIModel(account_id);67return custom_openai[key]?.display ?? "OpenAI (custom)";68}69if (isUserDefinedModel(account_id)) {70const um = getUserDefinedLLMByModel(account_id);71return um?.display ?? "ChatBot";72}73return "ChatBot";74}757677