Skip to content

Commit

Permalink
local llm integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lx-0 committed Oct 30, 2024
1 parent f43967d commit 090041c
Show file tree
Hide file tree
Showing 40 changed files with 2,082 additions and 219 deletions.
59 changes: 59 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- Always use TypeScript for better type safety and maintainability
- Maintain clean code principles and follow best practices
- Use strict and explicit typing; never use the 'any' keyword
- Follow DRY principle wherever possible

// Project structure

Expand Down Expand Up @@ -246,3 +247,61 @@ Ensure all required dependencies are properly installed and typed:
- Support function execution tracking
- Add message history support
- Handle message reconstruction

rules:

- name: "TypeScript Strict Mode"
pattern: "*.ts,*.tsx"
rules:
- "No 'any' types allowed"
- "Use explicit return types"
- "Enable strict null checks"
- "Use interface over type where possible"

- name: "Code Organization"
pattern: "src/**/*"
rules:
- "Use feature-based folder structure"
- "Keep components pure and focused"
- "Separate business logic from UI"
- "Use hooks for shared logic"

- name: "API Design"
pattern: "src/app/api/**/*"
rules:
- "Use proper HTTP methods"
- "Validate inputs"
- "Handle errors gracefully"
- "Stream responses when appropriate"

- name: "State Management"
pattern: "src/**/*"
rules:
- "Use React Query for server state"
- "Use local state for UI"
- "Avoid prop drilling"
- "Keep state close to where it's used"

- name: "Testing"
pattern: "**/*.test.ts,**/*.test.tsx"
rules:
- "Write unit tests for utils"
- "Write integration tests for API"
- "Test error cases"
- "Mock external dependencies"

- name: "Documentation"
pattern: "**/*"
rules:
- "Document public APIs"
- "Add JSDoc for complex functions"
- "Keep README up to date"
- "Document environment setup"

- name: "Code Quality"
pattern: "*.ts,*.tsx"
rules:
- "No while(true) loops - use explicit conditions"
- "No constant conditions in loops or conditionals"
- "Use proper loop termination conditions"
- "Avoid infinite loops"
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

NEXT_PUBLIC_API_KEY=your_public_api_key_here

NEXT_PUBLIC_OLLAMA_URL=http://localhost:11434

# Secret API keys for server-side use

API_KEY=your_secret_api_key_here
Expand Down
65 changes: 30 additions & 35 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: "module",
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
Expand All @@ -14,48 +14,43 @@ module.exports = {
es6: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"next/core-web-vitals",
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:prettier/recommended',
'next/core-web-vitals',
],
plugins: ["@typescript-eslint", "react", "jsx-a11y", "import", "prettier"],
plugins: ['@typescript-eslint', 'react', 'jsx-a11y', 'import', 'prettier'],
rules: {
"no-console": ["warn", { allow: ["warn", "error"] }],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-explicit-any": "error",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"jsx-a11y/anchor-is-valid": "off",
"import/order": [
"error",
// TypeScript specific rules
'@typescript-eslint/no-unused-vars': [
'warn',
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
"prettier/prettier": "error",
'no-console': ['warn', { allow: ['warn', 'error'] }],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'jsx-a11y/anchor-is-valid': 'off',
// Import rules
'import/order': 'off',
'prettier/prettier': 'error',
},
settings: {
react: {
version: "detect",
version: 'detect',
},
"import/resolver": {
'import/resolver': {
typescript: {},
},
},
Expand Down
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect"],
"program": "${workspaceFolder}/node_modules/.bin/next",
"args": ["dev"],
"skipFiles": ["<node_internals>/**"]
// "outFiles": ["${workspaceFolder}/.next/**/*.js"]
},
{
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ A Next.js application that uses a large language model to control a computer thr
> - ✅ Model selection
> - ✅ Model tracking
> - ✅ Message history
> - ✅ Local model support
> - ✅ Model download tracking
> - 🔳 Context management
> - 🔳 Function calling
> - ⬜ Streaming support
Expand Down Expand Up @@ -103,6 +105,7 @@ A Next.js application that uses a large language model to control a computer thr
- Node.js (LTS version)
- Docker
- Python 3.11.6 (for certain features)
- Ollama (for local models) - See [Ollama Setup](#ollama-setup) section

## Installation

Expand Down Expand Up @@ -159,6 +162,82 @@ The application includes a custom Docker environment with:
- Firefox ESR with pre-configured extensions
- Various utility applications

## Ollama Setup

### Installation

#### macOS

```bash
# Using Homebrew
brew install ollama

# Start Ollama service
ollama serve
```

#### Linux

```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

# Start Ollama service
systemctl start ollama
```

#### Windows

1. Install WSL2 if not already installed:

```bash
wsl --install
```

2. Install Ollama in WSL2:

```bash
curl -fsSL https://ollama.com/install.sh | sh
```

3. Start Ollama service in WSL2:

```bash
ollama serve
```

### Configuration

Add the following to your `.env` file:

```env
# Ollama Configuration
NEXT_PUBLIC_OLLAMA_URL=http://localhost:11434
```

### Troubleshooting

1. Check if Ollama is running:

```bash
curl http://localhost:11434/api/health
```

2. If not running, start the service:

```bash
# macOS/Linux
ollama serve

# Windows (in WSL2)
wsl -d Ubuntu -u root ollama serve
```

3. Common issues:
- Port 11434 is already in use
- Insufficient disk space
- GPU drivers not properly installed (for GPU acceleration)

## Contributing

1. Ensure you follow the project's coding standards:
Expand Down
Loading

0 comments on commit 090041c

Please sign in to comment.