Skip to content

Commit

Permalink
feat: local Ollama example (#865)
Browse files Browse the repository at this point in the history
* feat: local ollama example

* update lockfile, rename project,
  • Loading branch information
stevologic authored Sep 21, 2024
1 parent aca9ead commit 4e60d3a
Show file tree
Hide file tree
Showing 18 changed files with 394 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/local-ollama/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OLLAMA_API_URL=
3 changes: 3 additions & 0 deletions examples/local-ollama/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
}
63 changes: 63 additions & 0 deletions examples/local-ollama/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# OS generated files
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp
65 changes: 65 additions & 0 deletions examples/local-ollama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Project Overview

This project configures `assistant-ui` to work with Ollama hosted on a local instance. Additionally, it changes the theme to dark mode.

This source code was generated using the `Getting Started` guide hosted on [assistant-ui.com/docs](https://www.assistant-ui.com/docs).

```bash
npx assistant-ui@latest create my-app
cd my-app
```



## Prerequisites

Ensure you have the following installed:

- Node.js
- npm

## Installation

Clone the repository:

```bash
git clone https://github.com/yourusername/assistant-ui-local-ollama.git
cd assistant-ui-local-ollama
```

Install the dependencies:

```bash
npm install
```

## Configuration
Copy the `.env.local.example` file to `.env`:

Add `OLLAMA_API_URL` to the `.env` file:
```
OLLAMA_API_URL=http:/x.x.x.x:11434/api
```

## Running the Development Server

Start the development server:

```bash
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Editing the Project

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

## Changing the Theme to Dark Mode

The theme has been set to dark mode by default. You can customize the theme by annotating html with the className `dark`.


## License

This project is licensed under the MIT License.
10 changes: 10 additions & 0 deletions examples/local-ollama/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createOllama } from "ollama-ai-provider";
import { createEdgeRuntimeAPI } from "@assistant-ui/react/edge";

const local_ollama = createOllama({
baseURL: process.env.OLLAMA_API_URL,
});

export const { POST } = createEdgeRuntimeAPI({
model: local_ollama("llama3.1"),
});
Binary file added examples/local-ollama/app/favicon.ico
Binary file not shown.
Binary file added examples/local-ollama/app/fonts/GeistMonoVF.woff
Binary file not shown.
Binary file added examples/local-ollama/app/fonts/GeistVF.woff
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/local-ollama/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
35 changes: 35 additions & 0 deletions examples/local-ollama/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en" className="dark">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
9 changes: 9 additions & 0 deletions examples/local-ollama/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { MyAssistant } from "@/components/MyAssistant";

export default function Home() {
return (
<main className="h-dvh">
<MyAssistant />
</main>
);
}
18 changes: 18 additions & 0 deletions examples/local-ollama/components/MyAssistant.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

import { useEdgeRuntime } from "@assistant-ui/react";
import { Thread } from "@assistant-ui/react";
import { makeMarkdownText } from "@assistant-ui/react-markdown";

const MarkdownText = makeMarkdownText();

export function MyAssistant() {
const runtime = useEdgeRuntime({ api: "/api/chat" });

return (
<Thread
runtime={runtime}
assistantMessage={{ components: { Text: MarkdownText } }}
/>
);
}
4 changes: 4 additions & 0 deletions examples/local-ollama/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
31 changes: 31 additions & 0 deletions examples/local-ollama/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "with-local-ollama",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@assistant-ui/react": "^0.5",
"@assistant-ui/react-markdown": "^0.2",
"next": "14.2.11",
"ollama-ai-provider": "^0.15.0",
"react": "^18",
"react-dom": "^18",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.11",
"postcss": "^8",
"tailwindcss": "^3.4.11",
"typescript": "^5"
}
}
8 changes: 8 additions & 0 deletions examples/local-ollama/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
17 changes: 17 additions & 0 deletions examples/local-ollama/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Config } from "tailwindcss";

const config = {
darkMode: "class",
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
],
plugins: [
require("tailwindcss-animate"),
require("@assistant-ui/react/tailwindcss"),
require("@assistant-ui/react-markdown/tailwindcss"),
],
} satisfies Config;

export default config;
26 changes: 26 additions & 0 deletions examples/local-ollama/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 4e60d3a

Please sign in to comment.