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/components/language-model-icon.tsx
Views: 687
import { CSS, useTypedRedux } from "@cocalc/frontend/app-framework";1import {2LLMServiceName,3LanguageModel,4SERVICES,5fromCustomOpenAIModel,6fromOllamaModel,7fromUserDefinedLLMModel,8isGoogleModel,9isLanguageModel,10isUserDefinedModel,11model2vendor,12} from "@cocalc/util/db-schema/llm-utils";13import { unreachable } from "@cocalc/util/misc";14import AIAvatar from "./ai-avatar";15import AnthropicAvatar from "./anthropic-avatar";16import GoogleGeminiLogo from "./google-gemini-avatar";17import GooglePalmLogo from "./google-palm-avatar";18import MistralAvatar from "./mistral-avatar";19import OllamaAvatar from "./ollama-avatar";20import OpenAIAvatar from "./openai-avatar";2122export function LanguageModelVendorAvatar(23props: Readonly<{24model?: LanguageModel;25size?: number;26style?: CSS;27}>,28) {29const { model, size = 20 } = props;3031const ollama = useTypedRedux("customize", "ollama");32const custom_openai = useTypedRedux("customize", "custom_openai");3334const style: CSS = {35marginRight: "5px",36...props.style,37} as const;3839function fallback() {40return <AIAvatar size={size} style={style} />;41}4243if (model == null) {44return fallback();45}4647function renderImgIcon(icon: string) {48return (49<img50width={size}51height={size}52src={icon}53style={{ display: "inline-block", ...style }}54/>55);56}5758function renderModel(model: string, vendor?: LLMServiceName) {59const useIcon = vendor == null;60const vendorName = vendor ?? model2vendor(model).name;61switch (vendorName) {62case "openai":63return <OpenAIAvatar size={size} style={style} />;6465case "custom_openai": {66const icon = custom_openai?.getIn([67fromCustomOpenAIModel(model),68"icon",69]);70if (useIcon && typeof icon === "string") {71return renderImgIcon(icon);72} else {73return <OpenAIAvatar size={size} style={style} />;74}75}7677case "google": {78if (model === "chat-bison-001") {79// Palm2, no longer supported, just for backwards compatibility80return <GooglePalmLogo size={size} style={style} />;81} else if (!useIcon || isGoogleModel(model)) {82return <GoogleGeminiLogo size={size} style={style} />;83} else {84return fallback();85}86}8788case "mistralai":89return <MistralAvatar size={size} style={style} />;9091case "ollama": {92const icon = ollama?.getIn([fromOllamaModel(model), "icon"]);93if (useIcon && typeof icon === "string") {94return renderImgIcon(icon);95} else {96return <OllamaAvatar size={size} style={style} />;97}98}99100case "anthropic":101return <AnthropicAvatar size={size} style={style} />;102103case "user":104// should never happen, because it is unpacked below105return fallback();106107default:108unreachable(vendorName);109return fallback();110}111}112113if (isUserDefinedModel(model)) {114const udm = fromUserDefinedLLMModel(model);115if (!udm) {116return fallback();117} else {118// TODO: support a customizable icon for user defined LLMs119for (const vendor of SERVICES) {120if (udm.startsWith(`${vendor}-`)) {121return renderModel(udm, vendor);122}123}124}125} else if (isLanguageModel(model)) {126return renderModel(model);127}128129return fallback();130}131132133