Skip to content

Commit

Permalink
frontend/llm: collect LLM descriptions in the universal llm-util
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldschilly committed Mar 15, 2024
1 parent 5d3f293 commit cb66d65
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 54 deletions.
60 changes: 12 additions & 48 deletions src/packages/frontend/frame-editors/llm/model-switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CSS, redux, useTypedRedux } from "@cocalc/frontend/app-framework";
import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-model-icon";
import {
DEFAULT_MODEL,
LLM_DESCR,
LLM_USERNAMES,
LanguageModel,
MISTRAL_MODELS,
Expand Down Expand Up @@ -90,7 +91,7 @@ export default function ModelSwitch({
);
const tooltip = (
<>
<strong>{model}</strong>: {title}
<strong>{model}</strong> {title}
</>
);
const display = (
Expand All @@ -108,64 +109,26 @@ export default function ModelSwitch({
function appendOpenAI(ret: NonNullable<SelectProps["options"]>) {
if (!showOpenAI) return null;

makeLLMOption(
ret,
"gpt-3.5-turbo",
"OpenAI's fastest model, great for most everyday tasks (4k token context)",
);
makeLLMOption(
ret,
"gpt-3.5-turbo-16k",
`Same as ${modelToName(
"gpt-3.5-turbo",
)} but with much larger context size (16k token context)`,
);
makeLLMOption(
ret,
"gpt-4",
"GPT-4 can follow complex instructions in natural language and solve difficult problems with accuracy. (8k token context)",
);
makeLLMOption(
ret,
"gpt-4-turbo-preview",
"GPT-4 Turbo is more powerful, has fresher knowledge and offered at a lower price than GPT-4. (128k token context)",
);
makeLLMOption(ret, "gpt-3.5-turbo", LLM_DESCR["gpt-3.5-turbo"]);
makeLLMOption(ret, "gpt-3.5-turbo-16k", LLM_DESCR["gpt-3.5-turbo-16k"]);
makeLLMOption(ret, "gpt-4", LLM_DESCR["gpt-4"]);
makeLLMOption(ret, "gpt-4-turbo-preview", LLM_DESCR["gpt-4-turbo-preview"]);
}

function appendGoogle(ret: NonNullable<SelectProps["options"]>) {
if (!showGoogle) return null;

return (
<>
{makeLLMOption(
ret,
GOOGLE_GEMINI,
`Google's Gemini Pro Generative AI model (30k token context)`,
)}
</>
);
return <>{makeLLMOption(ret, GOOGLE_GEMINI, LLM_DESCR[GOOGLE_GEMINI])}</>;
}

function appendMistral(ret: NonNullable<SelectProps["options"]>) {
if (!showMistral) return null;

return (
<>
{makeLLMOption(
ret,
MISTRAL_MODELS[0],
"Fast, simple queries, short answers, less capabilities",
)}
{makeLLMOption(
ret,
MISTRAL_MODELS[1],
"Intermediate tasks, summarizing, generating documents, etc.",
)}
{makeLLMOption(
ret,
MISTRAL_MODELS[2],
"Slowest, most powerful, large reasoning capabilities",
)}
{makeLLMOption(ret, MISTRAL_MODELS[0], LLM_DESCR[MISTRAL_MODELS[0]])}
{makeLLMOption(ret, MISTRAL_MODELS[1], LLM_DESCR[MISTRAL_MODELS[1]])}
{makeLLMOption(ret, MISTRAL_MODELS[2], LLM_DESCR[MISTRAL_MODELS[2]])}
</>
);
}
Expand All @@ -178,7 +141,8 @@ export default function ModelSwitch({
const ollamaModel = toOllamaModel(key);
const text = (
<>
<strong>{display}</strong> {getPrice(ollamaModel)}: {desc ?? "Ollama"}
<strong>{display}</strong> {getPrice(ollamaModel)}{" "}
{desc ?? "Ollama"}
</>
);
ret.push({
Expand Down
37 changes: 32 additions & 5 deletions src/packages/util/db-schema/llm-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,7 @@ export function fromMistralService(model: MistralService) {
return model.slice(MISTRAL_PREFIX.length);
}

// Map from psuedo account_id to what should be displayed to user.
// This is used in various places in the frontend.
// Google PaLM: https://cloud.google.com/vertex-ai/docs/generative-ai/pricing
export const LLM_USERNAMES: {
type LLM2String = {
[key in
| (typeof USER_SELECTABLE_LANGUAGE_MODELS)[number]
| "chatgpt" // some additional ones, backwards compatibility
Expand All @@ -275,7 +272,12 @@ export const LLM_USERNAMES: {
| "gpt-4-32k"
| "text-bison-001"
| "chat-bison-001"]: string;
} = {
};

// Map from psuedo account_id to what should be displayed to user.
// This is used in various places in the frontend.
// Google PaLM: https://cloud.google.com/vertex-ai/docs/generative-ai/pricing
export const LLM_USERNAMES: LLM2String = {
chatgpt: "GPT-3.5",
chatgpt3: "GPT-3.5",
chatgpt4: "GPT-4",
Expand All @@ -292,6 +294,31 @@ export const LLM_USERNAMES: {
"mistral-large-latest": "Mistral AI Large",
} as const;

// similar to the above, we map to short user-visible description texts
// this comes next to the name, hence you do not have to mention the name
export const LLM_DESCR: LLM2String = {
chatgpt: "Fast, great for everyday tasks. (OpenAI, 4k token context)",
chatgpt3: "Fast, great for everyday tasks. (OpenAI, 4k token context)",
chatgpt4:
"Can follow complex instructions and solve difficult problems. (OpenAI, 8k token context)",
"gpt-4":
"Can follow complex instructions and solve difficult problems. (OpenAI, 8k token context)",
"gpt-4-32k": "",
"gpt-3.5-turbo": "Fast, great for everyday tasks. (OpenAI, 4k token context)",
"gpt-3.5-turbo-16k": `Same as ${LLM_USERNAMES["gpt-3.5-turbo"]} but with larger 16k token context`,
"gpt-4-turbo-preview":
"More powerful, fresher knowledge, and lower price than GPT-4. (OpenAI, 128k token context)",
"text-bison-001": "",
"chat-bison-001": "",
"gemini-pro": "Google's Gemini Pro Generative AI model (30k token context)",
"mistral-small-latest":
"Fast, simple queries, short answers, less capabilities. (Mistral AI, 4k token context)",
"mistral-medium-latest":
"Intermediate tasks, summarizing, generating documents, etc. (Mistral AI, 4k token context)",
"mistral-large-latest":
"Most powerful, large reasoning capabilities, but slower. (Mistral AI, 4k token context)",
} as const;

export function isFreeModel(model: unknown) {
if (isOllamaLLM(model)) return true;
if (isMistralModel(model)) {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/util/db-schema/site-settings-extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const EXTRAS: SettingsExtras = {
},
ollama_configuration: {
name: "Ollama Configuration",
desc: 'Configure Ollama endpoints. e.g. Ollama has "gemma" installed and runs at localhost:11434: `{"gemma" : {"baseUrl": "http://localhost:11434/" , cocalc: {display: "Gemma", desc: "Google\'s Gemma Model"}}',
desc: 'Configure Ollama endpoints. e.g. Ollama has "gemma" installed and is available at localhost:11434: `{"gemma" : {"baseUrl": "http://localhost:11434/" , cocalc: {display: "Gemma", desc: "Google\'s Gemma Model"}}',
default: "",
multiline: 5,
show: ollama_enabled,
Expand Down

0 comments on commit cb66d65

Please sign in to comment.