docs: replace README with Next.js boilerplate template

Updated README.md from a detailed OllaHub project description to the standard Next.js getting started template, likely to initialize or reset the project as a Next.js application.
This commit is contained in:
Evandro Fonseca Junior committed 2025-10-28 12:51:19 -03:00
1 parent 58e5522700
commit a3f8226fda
42 files changed
+4465 -314

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
export function extractCodeBlocks(
text: string
): Array<{ language: string; code: string }> {
const regex = /```(\w+)?\n([\s\S]*?)```/g;
const blocks: Array<{ language: string; code: string }> = [];
let match: RegExpExecArray | null;
while ((match = regex.exec(text)) !== null) {
const language = match[1] || "text";
const code = match[2]?.trimEnd() || "";
blocks.push({ language, code });
}
return blocks;
}
export function stripMarkdown(md: string): string {
// Remove code blocks first
let plain = md.replace(/```[\s\S]*?```/g, (block) =>
block.replace(/```[\s\S]*?\n/, "").replace(/```$/, "")
);
// Remove inline code
plain = plain.replace(/`([^`]+)`/g, "$1");
// Remove common markdown syntax
plain = plain
.replace(/(^|\s)[#>*_~`-]+/g, " ")
.replace(/\[(.*?)\]\((.*?)\)/g, "$1");
return plain;
}
+77
View File
@@ -0,0 +1,77 @@
"use client";
import { useCallback, useEffect, useState } from "react";
export type DevicePref = "auto" | "cpu" | "gpu";
type Prefs = {
systemPrompt: string;
device: DevicePref;
gpuIndex: number; // main_gpu
numGpu: number; // num_gpu
};
const KEYS = {
systemPrompt: "ollahub-system-prompt",
device: "ollahub-device-pref",
gpuIndex: "ollahub-gpu-index",
numGpu: "ollahub-num-gpu",
} as const;
const defaultPrefs: Prefs = {
systemPrompt: "",
device: "auto",
gpuIndex: 0,
numGpu: 1,
};
export function useUserPrefs() {
const [prefs, setPrefs] = useState<Prefs>(defaultPrefs);
const [ready, setReady] = useState(false);
useEffect(() => {
if (typeof window === "undefined") return;
const p: Prefs = {
systemPrompt:
localStorage.getItem(KEYS.systemPrompt) || defaultPrefs.systemPrompt,
device:
(localStorage.getItem(KEYS.device) as DevicePref) ||
defaultPrefs.device,
gpuIndex: Number(
localStorage.getItem(KEYS.gpuIndex) || defaultPrefs.gpuIndex
),
numGpu: Number(localStorage.getItem(KEYS.numGpu) || defaultPrefs.numGpu),
};
setPrefs(p);
setReady(true);
}, []);
const update = useCallback((next: Partial<Prefs>) => {
setPrefs((prev) => {
const merged: Prefs = { ...prev, ...next };
if (typeof window !== "undefined") {
localStorage.setItem(KEYS.systemPrompt, merged.systemPrompt);
localStorage.setItem(KEYS.device, merged.device);
localStorage.setItem(KEYS.gpuIndex, String(merged.gpuIndex));
localStorage.setItem(KEYS.numGpu, String(merged.numGpu));
}
return merged;
});
}, []);
return { prefs, ready, update };
}
export function buildOllamaOptions(
device: DevicePref,
numGpu: number,
gpuIndex: number
) {
if (device === "auto") return undefined;
if (device === "cpu") return { num_gpu: 0 } as const;
// gpu
return {
num_gpu: Math.max(1, numGpu),
main_gpu: Math.max(0, gpuIndex),
} as const;
}