Skip to content

Commit

Permalink
Merge pull request #7296 from sagemathinc/support-ollama-api
Browse files Browse the repository at this point in the history
Ollama, Mistral AI, etc.
  • Loading branch information
williamstein authored Mar 17, 2024
2 parents 436c8d5 + 28b989a commit 0b15762
Show file tree
Hide file tree
Showing 95 changed files with 3,690 additions and 1,684 deletions.
2 changes: 1 addition & 1 deletion src/packages/frontend/account/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-
import { ProjectTitle } from "@cocalc/frontend/projects/project-title";
import { DEFAULT_COLOR } from "@cocalc/frontend/users/store";
import { webapp_client } from "@cocalc/frontend/webapp-client";
import { service2model } from "@cocalc/util/db-schema/openai";
import { service2model } from "@cocalc/util/db-schema/llm-utils";
import { ensure_bound, startswith, trunc_middle } from "@cocalc/util/misc";
import { avatar_fontcolor } from "./font-color";

Expand Down
39 changes: 23 additions & 16 deletions src/packages/frontend/account/chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,46 @@ When new models are added, e.g., Claude soon (!), they will go here.
*/

import { redux } from "@cocalc/frontend/app-framework";
import {
LANGUAGE_MODELS,
LANGUAGE_MODEL_PREFIXES,
LLM_USERNAMES,
MODELS,
Vendor,
model2vendor,
} from "@cocalc/util/db-schema/openai";
fromMistralService,
fromOllamaModel,
isMistralService,
isOllamaLLM,
} from "@cocalc/util/db-schema/llm-utils";

// we either check if the prefix is one of the known ones (used in some circumstances)
// or if the account id is exactly one of the language models (more precise)
export function isChatBot(account_id?: string) {
export function isChatBot(account_id?: string): boolean {
if (typeof account_id !== "string") return false;
return (
LANGUAGE_MODEL_PREFIXES.some((prefix) => account_id?.startsWith(prefix)) ||
MODELS.some((model) => account_id === model)
LANGUAGE_MODELS.some((model) => account_id === model) ||
isOllamaLLM(account_id)
);
}

export function getChatBotVendor(account_id?: string): Vendor {
if (account_id == null) {
return "openai";
}
return model2vendor(account_id as any);
}

export function chatBotName(account_id?: string): string {
if (account_id?.startsWith("chatgpt")) {
if (typeof account_id !== "string") return "ChatBot";
if (account_id.startsWith("chatgpt")) {
return LLM_USERNAMES[account_id] ?? "ChatGPT";
}
if (account_id?.startsWith("openai-")) {
if (account_id.startsWith("openai-")) {
return LLM_USERNAMES[account_id.slice("openai-".length)] ?? "ChatGPT";
}
if (account_id?.startsWith("google-")) {
if (account_id.startsWith("google-")) {
return LLM_USERNAMES[account_id.slice("google-".length)] ?? "Gemini";
}
if (isMistralService(account_id)) {
return LLM_USERNAMES[fromMistralService(account_id)] ?? "Mistral";
}
if (isOllamaLLM(account_id)) {
const ollama = redux.getStore("customize").get("ollama")?.toJS() ?? {};
const key = fromOllamaModel(account_id);
return ollama[key]?.display ?? "Ollama";
}
return "ChatBot";
}
Loading

0 comments on commit 0b15762

Please sign in to comment.