Skip to content

Commit

Permalink
ollama: starting with configuration + frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldschilly committed Feb 23, 2024
1 parent fd4a48e commit e06b06e
Show file tree
Hide file tree
Showing 29 changed files with 245 additions and 75 deletions.
3 changes: 2 additions & 1 deletion src/packages/frontend/admin/site-settings/row-entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export function RowEntry({
{displayed_val != null && (
<span>
{" "}
Interpreted as <code>{displayed_val}</code>.{" "}
{valid ? "Interpreted as" : "Invalid:"}{" "}
<code>{displayed_val}</code>.{" "}
</span>
)}
{valid != null && Array.isArray(valid) && (
Expand Down
2 changes: 1 addition & 1 deletion src/packages/frontend/chat/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Gap, Icon, TimeAgo, Tip } from "@cocalc/frontend/components";
import MostlyStaticMarkdown from "@cocalc/frontend/editors/slate/mostly-static-markdown";
import { IS_TOUCH } from "@cocalc/frontend/feature";
import { modelToName } from "@cocalc/frontend/frame-editors/chatgpt/model-switch";
import { modelToName } from "@cocalc/frontend/frame-editors/llm/model-switch";
import { COLORS } from "@cocalc/util/theme";
import { ChatActions } from "./actions";
import { getUserName } from "./chat-log";
Expand Down
8 changes: 4 additions & 4 deletions src/packages/frontend/codemirror/extensions/ai-formula.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {
HelpIcon,
Markdown,
Paragraph,
Title,
Text,
Title,
} from "@cocalc/frontend/components";
import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-model-icon";
import ModelSwitch, {
modelToName,
} from "@cocalc/frontend/frame-editors/chatgpt/model-switch";
} from "@cocalc/frontend/frame-editors/llm/model-switch";
import { show_react_modal } from "@cocalc/frontend/misc";
import track from "@cocalc/frontend/user-tracking";
import { webapp_client } from "@cocalc/frontend/webapp-client";
import { unreachable } from "@cocalc/util/misc";
import { isFreeModel } from "@cocalc/util/db-schema/openai";
import track from "@cocalc/frontend/user-tracking";
import { unreachable } from "@cocalc/util/misc";

type Mode = "tex" | "md";

Expand Down
26 changes: 19 additions & 7 deletions src/packages/frontend/customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { fromJS, List, Map } from "immutable";
import { join } from "path";

import {
Actions,
rclass,
Expand All @@ -22,13 +23,14 @@ import {
import {
A,
build_date,
Gap,
Loading,
r_join,
smc_git_rev,
smc_version,
Gap,
UNIT,
} from "@cocalc/frontend/components";
import { getGoogleCloudImages, getImages } from "@cocalc/frontend/compute/api";
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
import { callback2, retry_until_success } from "@cocalc/util/async-utils";
import {
Expand All @@ -37,23 +39,23 @@ import {
FALLBACK_SOFTWARE_ENV,
} from "@cocalc/util/compute-images";
import { DEFAULT_COMPUTE_IMAGE } from "@cocalc/util/db-schema";
import type {
GoogleCloudImages,
Images,
} from "@cocalc/util/db-schema/compute-servers";
import {
KUCALC_COCALC_COM,
KUCALC_DISABLED,
KUCALC_ON_PREMISES,
site_settings_conf,
} from "@cocalc/util/db-schema/site-defaults";
import { deep_copy, dict, YEAR } from "@cocalc/util/misc";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
import { sanitizeSoftwareEnv } from "@cocalc/util/sanitize-software-envs";
import * as theme from "@cocalc/util/theme";
import { OllamaPublic } from "@cocalc/util/types/llm";
import { DefaultQuotaSetting, Upgrades } from "@cocalc/util/upgrades/quota";
export { TermsOfService } from "@cocalc/frontend/customize/terms-of-service";
import type {
GoogleCloudImages,
Images,
} from "@cocalc/util/db-schema/compute-servers";
import { getImages, getGoogleCloudImages } from "@cocalc/frontend/compute/api";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";

// this sets UI modes for using a kubernetes based back-end
// 'yes' (historic value) equals 'cocalc.com'
Expand Down Expand Up @@ -148,6 +150,8 @@ export interface CustomizeState {
compute_servers_dns?: string;
compute_servers_images?: TypedMap<Images> | string | null;
compute_servers_images_google?: TypedMap<GoogleCloudImages> | string | null;

ollama?: { [key: string]: OllamaPublic };
}

export class CustomizeStore extends Store<CustomizeState> {
Expand Down Expand Up @@ -238,10 +242,12 @@ async function init_customize() {
registration,
strategies,
software = null,
ollama = null, // the derived public information
} = customize;
process_kucalc(configuration);
process_software(software, configuration.is_cocalc_com);
process_customize(configuration); // this sets _is_configured to true
process_ollama(ollama);
const actions = redux.getActions("account");
// Which account creation strategies we support.
actions.setState({ strategies });
Expand All @@ -251,6 +257,12 @@ async function init_customize() {

init_customize();

function process_ollama(ollama) {
if (ollama) {
actions.setState({ ollama: fromJS(ollama) });
}
}

function process_kucalc(obj) {
// TODO make this a to_val function in site_settings_conf.kucalc
obj.kucalc = validate_kucalc(obj.kucalc);
Expand Down
4 changes: 2 additions & 2 deletions src/packages/frontend/frame-editors/code-editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import {
len,
uuid,
} from "@cocalc/util/misc";
import languageModelCreateChat, { Options } from "../chatgpt/create-chat";
import type { Scope as LanguageModelScope } from "../chatgpt/types";
import languageModelCreateChat, { Options } from "../llm/create-chat";
import type { Scope as LanguageModelScope } from "../llm/types";
import { default_opts } from "../codemirror/cm-options";
import { print_code } from "../frame-tree/print-code";
import * as tree_ops from "../frame-tree/tree-ops";
Expand Down
14 changes: 9 additions & 5 deletions src/packages/frontend/frame-editors/frame-tree/format-error.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// A dismissable error message that appears when formatting code.

import { useMemo } from "react";
import { Alert, Button } from "antd";
import { useMemo } from "react";

import { file_associations } from "@cocalc/frontend/file-associations";
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";
import { CodeMirrorStatic } from "@cocalc/frontend/jupyter/codemirror-static";
import HelpMeFix from "@cocalc/frontend/frame-editors/chatgpt/help-me-fix";
import { file_associations } from "@cocalc/frontend/file-associations";

interface Props {
formatError: string;
Expand All @@ -14,10 +15,13 @@ interface Props {

export default function FormatError({ formatError, formatInput }: Props) {
const { actions } = useFrameContext();
const language = useMemo(() => actions?.languageModelGetLanguage(), [actions]);
const language = useMemo(
() => actions?.languageModelGetLanguage(),
[actions],
);
const mode = useMemo(
() => file_associations[language]?.opts?.mode ?? language,
[language]
[language],
);

if (actions == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { Actions } from "../code-editor/actions";
import { is_safari } from "../generic/browser";
import { SaveButton } from "./save-button";
import { ConnectionStatus, EditorDescription, EditorSpec } from "./types";
import LanguageModelTitleBarButton from "../chatgpt/title-bar-button";
import LanguageModelTitleBarButton from "../llm/title-bar-button";
import userTracking from "@cocalc/frontend/user-tracking";
import TitleBarTour from "./title-bar-tour";
import { IS_MOBILE } from "@cocalc/frontend/feature";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useRedux,
} from "@cocalc/frontend/app-framework";
import { Icon, IconName, Loading } from "@cocalc/frontend/components";
import HelpMeFix from "@cocalc/frontend/frame-editors/chatgpt/help-me-fix";
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";
import { capitalize, is_different, path_split } from "@cocalc/util/misc";
import { COLORS } from "@cocalc/util/theme";
import { EditorState } from "../frame-tree/types";
Expand Down
9 changes: 5 additions & 4 deletions src/packages/frontend/frame-editors/latex-editor/gutters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
// one gets a gutter mark, with pref to errors. The main error log shows everything, so this should be OK.

import { Popover } from "antd";
import { capitalize } from "@cocalc/util/misc";

import { Icon } from "@cocalc/frontend/components";
import { SPEC, SpecItem } from "./errors-and-warnings";
import { IProcessedLatexLog, Error } from "./latex-log-parser";
import HelpMeFix from "@cocalc/frontend/frame-editors/chatgpt/help-me-fix";
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";
import { capitalize } from "@cocalc/util/misc";
import { Actions } from "../code-editor/actions";
import { SPEC, SpecItem } from "./errors-and-warnings";
import { Error, IProcessedLatexLog } from "./latex-log-parser";

export function update_gutters(opts: {
log: IProcessedLatexLog;
Expand Down
3 changes: 2 additions & 1 deletion src/packages/frontend/jupyter/chatgpt/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Use ChatGPT to explain an error message and help the user fix it.
*/

import { CSSProperties } from "react";
import HelpMeFix from "@cocalc/frontend/frame-editors/chatgpt/help-me-fix";

import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";

interface Props {
style?: CSSProperties;
Expand Down
4 changes: 2 additions & 2 deletions src/packages/frontend/jupyter/chatgpt/explain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { Icon } from "@cocalc/frontend/components/icon";
import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-model-icon";
import PopconfirmKeyboard from "@cocalc/frontend/components/popconfirm-keyboard";
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
import ModelSwitch, {
LanguageModel,
modelToMention,
modelToName,
} from "@cocalc/frontend/frame-editors/chatgpt/model-switch";
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
} from "@cocalc/frontend/frame-editors/llm/model-switch";
import { ProjectsStore } from "@cocalc/frontend/projects/store";
import type { JupyterActions } from "../browser-actions";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { Paragraph } from "@cocalc/frontend/components";
import { Icon } from "@cocalc/frontend/components/icon";
import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-model-icon";
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
import { NotebookFrameActions } from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/actions";
import ModelSwitch, {
modelToName,
} from "@cocalc/frontend/frame-editors/chatgpt/model-switch";
import { NotebookFrameActions } from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/actions";
} from "@cocalc/frontend/frame-editors/llm/model-switch";
import { splitCells } from "@cocalc/frontend/jupyter/chatgpt/split-cells";
import track from "@cocalc/frontend/user-tracking";
import { webapp_client } from "@cocalc/frontend/webapp-client";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import { LanguageModelVendorAvatar } from "@cocalc/frontend/components/language-
import ProgressEstimate from "@cocalc/frontend/components/progress-estimate";
import SelectKernel from "@cocalc/frontend/components/run-button/select-kernel";
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
import ModelSwitch, {
modelToName,
} from "@cocalc/frontend/frame-editors/chatgpt/model-switch";
import type { JupyterEditorActions } from "@cocalc/frontend/frame-editors/jupyter-editor/actions";
import { NotebookFrameActions } from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/actions";
import ModelSwitch, {
modelToName,
} from "@cocalc/frontend/frame-editors/llm/model-switch";
import { splitCells } from "@cocalc/frontend/jupyter/chatgpt/split-cells";
import getKernelSpec from "@cocalc/frontend/jupyter/kernelspecs";
import { StartButton } from "@cocalc/frontend/project/start-button";
Expand Down
2 changes: 1 addition & 1 deletion src/packages/frontend/sagews/chatgpt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redux } from "@cocalc/frontend/app-framework";
import { getHelp } from "@cocalc/frontend/frame-editors/chatgpt/help-me-fix";
import { getHelp } from "@cocalc/frontend/frame-editors/llm/help-me-fix";
import { getValidLanguageModelName } from "@cocalc/util/db-schema/openai";
import { MARKERS } from "@cocalc/util/sagews";

Expand Down
12 changes: 7 additions & 5 deletions src/packages/hub/servers/server-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
Synchronized table that tracks server settings.
*/

import { isEmpty } from "lodash";

import { once } from "@cocalc/util/async-utils";
import { EXTRAS as SERVER_SETTINGS_EXTRAS } from "@cocalc/util/db-schema/site-settings-extras";
import { AllSiteSettings } from "@cocalc/util/db-schema/types";
import { startswith } from "@cocalc/util/misc";
import { site_settings_conf as SITE_SETTINGS_CONF } from "@cocalc/util/schema";
import { isEmpty } from "lodash";
import { database } from "./database";

// Returns:
Expand All @@ -22,16 +24,16 @@ import { database } from "./database";
// - table: the table, so you can watch for on change events...
// These get automatically updated when the database changes.

interface ServerSettings {
all: object;
export interface ServerSettingsDynamic {
all: AllSiteSettings;
pub: object;
version: object;
table: any;
}

let serverSettings: ServerSettings | undefined = undefined;
let serverSettings: ServerSettingsDynamic | undefined = undefined;

export default async function getServerSettings(): Promise<ServerSettings> {
export default async function getServerSettings(): Promise<ServerSettingsDynamic> {
if (serverSettings != null) {
return serverSettings;
}
Expand Down
Loading

0 comments on commit e06b06e

Please sign in to comment.