From 1766dd5aa8935e28badc2d9051bbfa263c480146 Mon Sep 17 00:00:00 2001 From: Kofi <74067324+kofi-bhr@users.noreply.github.com> Date: Mon, 21 Oct 2024 07:06:23 -0500 Subject: [PATCH 01/28] Update README.md Fixed Readme to be up to date with prompting fixees --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 750833ada..4255c02b7 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This fork of bolt.new allows you to choose the LLM that you use for each prompt! - ✅ Autogenerate Ollama models from what is downloaded (@mosquet) - ✅ Filter models by provider (@jasonm23) - ✅ Download project as ZIP (@fabwaseem) +- ✅ Improvements to the main Bolt.new prompt in `app\lib\.server\llm\prompts.ts` (@kofi-bhr) - ⬜ LM Studio Integration - ⬜ DeepSeek API Integration - ⬜ Together Integration @@ -19,7 +20,6 @@ This fork of bolt.new allows you to choose the LLM that you use for each prompt! - ⬜ Run agents in the backend instead of a single model call - ⬜ Publish projects directly to GitHub - ⬜ Load local projects into the app -- ⬜ Improvements to the main Bolt.new prompt in `app\lib\.server\llm\prompts.ts` (there is definitely opportunity there) # Bolt.new: AI-Powered Full-Stack Web Development in the Browser From f9021d32c41d1d7f2b41a98e290ae78ae53c6fb2 Mon Sep 17 00:00:00 2001 From: Kofi <74067324+kofi-bhr@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:34:06 +0000 Subject: [PATCH 02/28] feat(prompt): add planning step + organize shell commands Adds structured planning phase before responses and reorganizes available shell commands by category. Planning helps catch edge cases early and shell categorization makes capabilities clearer. Main changes: - New chain-of-thought system for pre-response thinking - Grouped shell commands by function (files, sys, dev tools, misc) - Added brief cmd descriptions No breaking changes, just better organization + process. Should help reduce back-and-forth on PRs. Tested w/o cmd env :) - kofi --- app/lib/.server/llm/prompts.ts | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/app/lib/.server/llm/prompts.ts b/app/lib/.server/llm/prompts.ts index f78b41873..336bc0969 100644 --- a/app/lib/.server/llm/prompts.ts +++ b/app/lib/.server/llm/prompts.ts @@ -29,7 +29,32 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w IMPORTANT: When choosing databases or npm packages, prefer options that don't rely on native binaries. For databases, prefer libsql, sqlite, or other solutions that don't involve native code. WebContainer CANNOT execute arbitrary native binaries. - Available shell commands: cat, chmod, cp, echo, hostname, kill, ln, ls, mkdir, mv, ps, pwd, rm, rmdir, xxd, alias, cd, clear, curl, env, false, getconf, head, sort, tail, touch, true, uptime, which, code, jq, loadenv, node, python3, wasm, xdg-open, command, exit, export, source + Available shell commands: + File Operations: + - cat: Display file contents + - cp: Copy files/directories + - ls: List directory contents + - mkdir: Create directory + - mv: Move/rename files + - rm: Remove files + - rmdir: Remove empty directories + - touch: Create empty file/update timestamp + + System Information: + - hostname: Show system name + - ps: Display running processes + - pwd: Print working directory + - uptime: Show system uptime + - env: Environment variables + + Development Tools: + - node: Execute Node.js code + - python3: Run Python scripts + - code: VSCode operations + - jq: Process JSON + + Other Utilities: + - curl, head, sort, tail, clear, which, export, chmod, scho, hostname, kill, ln, xxd, alias, false, getconf, true, loadenv, wasm, xdg-open, command, exit, source @@ -84,6 +109,36 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w + + Before providing a solution, BRIEFLY outline your implementation steps using tags. This helps ensure systematic thinking and clear communication. Your planning should: + - List concrete steps you'll take + - Identify key components needed + - Note potential challenges + - Be concise (2-4 lines maximum) + + Example responses: + + User: "Create a todo list app with local storage" + Assistant: "Sure. I'll start by: + 1. Set up Vite + React + 2. Create TodoList and TodoItem components + 3. Implement localStorage for persistence + 4. Add CRUD operations + + Let's start now. + + [Rest of response...]" + + User: "Help debug why my API calls aren't working" + Assistant: "Great. My first steps will be: + 1. Check network requests + 2. Verify API endpoint format + 3. Examine error handling + + [Rest of response...]" + + + Bolt creates a SINGLE, comprehensive artifact for each project. The artifact contains all necessary steps and components, including: From 5b3521355a440420455c8538ac5278af238ae712 Mon Sep 17 00:00:00 2001 From: Kofi <74067324+kofi-bhr@users.noreply.github.com> Date: Mon, 21 Oct 2024 07:46:42 -0500 Subject: [PATCH 03/28] Update prompts.ts --- app/lib/.server/llm/prompts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/.server/llm/prompts.ts b/app/lib/.server/llm/prompts.ts index 336bc0969..4749553e6 100644 --- a/app/lib/.server/llm/prompts.ts +++ b/app/lib/.server/llm/prompts.ts @@ -110,7 +110,7 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w - Before providing a solution, BRIEFLY outline your implementation steps using tags. This helps ensure systematic thinking and clear communication. Your planning should: + Before providing a solution, BRIEFLY outline your implementation steps. This helps ensure systematic thinking and clear communication. Your planning should: - List concrete steps you'll take - Identify key components needed - Note potential challenges From f7615093dd3234890ba0c82f1361937927d4a1f8 Mon Sep 17 00:00:00 2001 From: fernsdavid25 <68889657+fernsdavid25@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:32:57 +0530 Subject: [PATCH 04/28] Update max_tokens in constants.ts max_tokens for llama 3.1 models must be less than or equal to 8000 but it is set to 8192. just change it to 8000 and the error is fixed. --- app/lib/.server/llm/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/.server/llm/constants.ts b/app/lib/.server/llm/constants.ts index b24acdf27..7b3a0f245 100644 --- a/app/lib/.server/llm/constants.ts +++ b/app/lib/.server/llm/constants.ts @@ -1,5 +1,5 @@ // see https://docs.anthropic.com/en/docs/about-claude/models -export const MAX_TOKENS = 8192; +export const MAX_TOKENS = 8000; // limits the number of model responses that can be returned in a single request export const MAX_RESPONSE_SEGMENTS = 2; From 0ef30967dd5c4ff4a4754693bbaf3603789eecac Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:10:08 +0100 Subject: [PATCH 05/28] Docker Additions Added Dockerfile and docker-compose.yml, also adjusted start command to listen for all IP's and on Port 3000 --- Dockerfile | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 23 +++++++++++++++++++++++ package.json | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..de88d11e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use an official Node.js runtime as the base image +FROM node:20.15.1 + +# Set the working directory in the container +WORKDIR /app + +# Install pnpm +RUN npm install -g pnpm@9.4.0 + +# Copy package.json and pnpm-lock.yaml (if available) +COPY package.json pnpm-lock.yaml* ./ + +# Install dependencies +RUN pnpm install + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN pnpm run build + +# Make sure bindings.sh is executable +RUN chmod +x bindings.sh + +# Expose the port the app runs on (adjust if you specified a different port) +EXPOSE 3000 + +# Start the application +CMD ["pnpm", "run", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..70b4fef07 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + bolt-app: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + - NODE_ENV=production + # Add any other environment variables your app needs + # - OPENAI_API_KEY=${OPENAI_API_KEY} + # - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} + # - GROQ_API_KEY=${GROQ_API_KEY} + volumes: + # This volume is for development purposes, allowing live code updates + # Comment out or remove for production + - .:/app + # This volume is to prevent node_modules from being overwritten by the above volume + - /app/node_modules + command: pnpm run start + +volumes: + node_modules: \ No newline at end of file diff --git a/package.json b/package.json index 737ca05cb..721588857 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test:watch": "vitest", "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .", "lint:fix": "npm run lint -- --fix", - "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings", + "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings --ip 0.0.0.0 --port 3000", "typecheck": "tsc", "typegen": "wrangler types", "preview": "pnpm run build && pnpm run start" From 059933a0c6d0e6468077468afcca1e237d702681 Mon Sep 17 00:00:00 2001 From: goncaloalves Date: Mon, 21 Oct 2024 20:14:35 +0100 Subject: [PATCH 06/28] Added GitHub push functionality --- app/components/workbench/Workbench.client.tsx | 25 ++++ app/lib/stores/workbench.ts | 106 ++++++++++++++ package.json | 2 + pnpm-lock.yaml | 136 +++++++++++++++++- 4 files changed, 263 insertions(+), 6 deletions(-) diff --git a/app/components/workbench/Workbench.client.tsx b/app/components/workbench/Workbench.client.tsx index 839e9a807..98f95ef74 100644 --- a/app/components/workbench/Workbench.client.tsx +++ b/app/components/workbench/Workbench.client.tsx @@ -141,6 +141,31 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
Toggle Terminal + { + const repoName = prompt("Please enter a name for your new GitHub repository:", "bolt-generated-project"); + if (!repoName) { + alert("Repository name is required. Push to GitHub cancelled."); + return; + } + const githubUsername = prompt("Please enter your GitHub username:"); + if (!githubUsername) { + alert("GitHub username is required. Push to GitHub cancelled."); + return; + } + const githubToken = prompt("Please enter your GitHub personal access token:"); + if (!githubToken) { + alert("GitHub token is required. Push to GitHub cancelled."); + return; + } + + workbenchStore.pushToGitHub(repoName, githubUsername, githubToken); + }} + > +
+ Push to GitHub + )} { + if (dirent?.type === 'file' && dirent.content) { + const { data: blob } = await octokit.git.createBlob({ + owner: repo.owner.login, + repo: repo.name, + content: Buffer.from(dirent.content).toString('base64'), + encoding: 'base64', + }); + return { path: filePath.replace(/^\/home\/project\//, ''), sha: blob.sha }; + } + }) + ); + + const validBlobs = blobs.filter(Boolean); // Filter out any undefined blobs + + if (validBlobs.length === 0) { + throw new Error('No valid files to push'); + } + + // Get the latest commit SHA (assuming main branch, update dynamically if needed) + const { data: ref } = await octokit.git.getRef({ + owner: repo.owner.login, + repo: repo.name, + ref: `heads/${repo.default_branch || 'main'}`, // Handle dynamic branch + }); + const latestCommitSha = ref.object.sha; + + // Create a new tree + const { data: newTree } = await octokit.git.createTree({ + owner: repo.owner.login, + repo: repo.name, + base_tree: latestCommitSha, + tree: validBlobs.map((blob) => ({ + path: blob!.path, + mode: '100644', + type: 'blob', + sha: blob!.sha, + })), + }); + + // Create a new commit + const { data: newCommit } = await octokit.git.createCommit({ + owner: repo.owner.login, + repo: repo.name, + message: 'Initial commit from your app', + tree: newTree.sha, + parents: [latestCommitSha], + }); + + // Update the reference + await octokit.git.updateRef({ + owner: repo.owner.login, + repo: repo.name, + ref: `heads/${repo.default_branch || 'main'}`, // Handle dynamic branch + sha: newCommit.sha, + }); + + alert(`Repository created and code pushed: ${repo.html_url}`); + } catch (error) { + console.error('Error pushing to GitHub:', error instanceof Error ? error.message : String(error)); + } + } } export const workbenchStore = new WorkbenchStore(); diff --git a/package.json b/package.json index 737ca05cb..e5595d70c 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,8 @@ "@iconify-json/svg-spinners": "^1.1.2", "@lezer/highlight": "^1.2.0", "@nanostores/react": "^0.7.2", + "@octokit/rest": "^21.0.2", + "@octokit/types": "^13.6.1", "@openrouter/ai-sdk-provider": "^0.0.5", "@radix-ui/react-dialog": "^1.1.1", "@radix-ui/react-dropdown-menu": "^2.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 46dc9dbfc..21dd5a1a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -77,6 +77,12 @@ importers: '@nanostores/react': specifier: ^0.7.2 version: 0.7.2(nanostores@0.10.3)(react@18.3.1) + '@octokit/rest': + specifier: ^21.0.2 + version: 21.0.2 + '@octokit/types': + specifier: ^13.6.1 + version: 13.6.1 '@openrouter/ai-sdk-provider': specifier: ^0.0.5 version: 0.0.5(zod@3.23.8) @@ -1230,6 +1236,58 @@ packages: resolution: {integrity: sha512-gGq0NJkIGSwdbUt4yhdF8ZrmkGKVz9vAdVzpOfnom+V8PLSmSOVhZwbNvZZS1EYcJN5hzzKBxmmVVAInM6HQLg==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + '@octokit/auth-token@5.1.1': + resolution: {integrity: sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==} + engines: {node: '>= 18'} + + '@octokit/core@6.1.2': + resolution: {integrity: sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==} + engines: {node: '>= 18'} + + '@octokit/endpoint@10.1.1': + resolution: {integrity: sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q==} + engines: {node: '>= 18'} + + '@octokit/graphql@8.1.1': + resolution: {integrity: sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg==} + engines: {node: '>= 18'} + + '@octokit/openapi-types@22.2.0': + resolution: {integrity: sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==} + + '@octokit/plugin-paginate-rest@11.3.5': + resolution: {integrity: sha512-cgwIRtKrpwhLoBi0CUNuY83DPGRMaWVjqVI/bGKsLJ4PzyWZNaEmhHroI2xlrVXkk6nFv0IsZpOp+ZWSWUS2AQ==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + + '@octokit/plugin-request-log@5.3.1': + resolution: {integrity: sha512-n/lNeCtq+9ofhC15xzmJCNKP2BWTv8Ih2TTy+jatNCCq/gQP/V7rK3fjIfuz0pDWDALO/o/4QY4hyOF6TQQFUw==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + + '@octokit/plugin-rest-endpoint-methods@13.2.6': + resolution: {integrity: sha512-wMsdyHMjSfKjGINkdGKki06VEkgdEldIGstIEyGX0wbYHGByOwN/KiM+hAAlUwAtPkP3gvXtVQA9L3ITdV2tVw==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + + '@octokit/request-error@6.1.5': + resolution: {integrity: sha512-IlBTfGX8Yn/oFPMwSfvugfncK2EwRLjzbrpifNaMY8o/HTEAFqCA1FZxjD9cWvSKBHgrIhc4CSBIzMxiLsbzFQ==} + engines: {node: '>= 18'} + + '@octokit/request@9.1.3': + resolution: {integrity: sha512-V+TFhu5fdF3K58rs1pGUJIDH5RZLbZm5BI+MNF+6o/ssFNT4vWlCh/tVpF3NxGtP15HUxTTMUbsG5llAuU2CZA==} + engines: {node: '>= 18'} + + '@octokit/rest@21.0.2': + resolution: {integrity: sha512-+CiLisCoyWmYicH25y1cDfCrv41kRSvTq6pPWtRroRJzhsCZWZyCqGyI8foJT5LmScADSwRAnr/xo+eewL04wQ==} + engines: {node: '>= 18'} + + '@octokit/types@13.6.1': + resolution: {integrity: sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==} + '@openrouter/ai-sdk-provider@0.0.5': resolution: {integrity: sha512-AfxXQhISpxQSeUjU/4jo9waM5GRNX6eIkfTFS9l7vHkD1TKDP81Y/dXrE0ttJeN/Kap3tPF3Jwh49me0gWwjSw==} engines: {node: '>=18'} @@ -2211,6 +2269,9 @@ packages: resolution: {integrity: sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==} engines: {node: '>= 0.8'} + before-after-hook@3.0.2: + resolution: {integrity: sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==} + binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} @@ -4970,9 +5031,6 @@ packages: engines: {node: '>=14.17'} hasBin: true - ufo@1.5.3: - resolution: {integrity: sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==} - ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} @@ -5053,6 +5111,9 @@ packages: unist-util-visit@5.0.0: resolution: {integrity: sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==} + universal-user-agent@7.0.2: + resolution: {integrity: sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==} + universalify@2.0.1: resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} engines: {node: '>= 10.0.0'} @@ -6363,6 +6424,67 @@ snapshots: dependencies: which: 3.0.1 + '@octokit/auth-token@5.1.1': {} + + '@octokit/core@6.1.2': + dependencies: + '@octokit/auth-token': 5.1.1 + '@octokit/graphql': 8.1.1 + '@octokit/request': 9.1.3 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.6.1 + before-after-hook: 3.0.2 + universal-user-agent: 7.0.2 + + '@octokit/endpoint@10.1.1': + dependencies: + '@octokit/types': 13.6.1 + universal-user-agent: 7.0.2 + + '@octokit/graphql@8.1.1': + dependencies: + '@octokit/request': 9.1.3 + '@octokit/types': 13.6.1 + universal-user-agent: 7.0.2 + + '@octokit/openapi-types@22.2.0': {} + + '@octokit/plugin-paginate-rest@11.3.5(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/types': 13.6.1 + + '@octokit/plugin-request-log@5.3.1(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + + '@octokit/plugin-rest-endpoint-methods@13.2.6(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/types': 13.6.1 + + '@octokit/request-error@6.1.5': + dependencies: + '@octokit/types': 13.6.1 + + '@octokit/request@9.1.3': + dependencies: + '@octokit/endpoint': 10.1.1 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.6.1 + universal-user-agent: 7.0.2 + + '@octokit/rest@21.0.2': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/plugin-paginate-rest': 11.3.5(@octokit/core@6.1.2) + '@octokit/plugin-request-log': 5.3.1(@octokit/core@6.1.2) + '@octokit/plugin-rest-endpoint-methods': 13.2.6(@octokit/core@6.1.2) + + '@octokit/types@13.6.1': + dependencies: + '@octokit/openapi-types': 22.2.0 + '@openrouter/ai-sdk-provider@0.0.5(zod@3.23.8)': dependencies: '@ai-sdk/provider': 0.0.12 @@ -7530,6 +7652,8 @@ snapshots: safe-buffer: 5.1.2 optional: true + before-after-hook@3.0.2: {} + binary-extensions@2.3.0: {} binaryextensions@6.11.0: @@ -9972,7 +10096,7 @@ snapshots: dependencies: destr: 2.0.3 node-fetch-native: 1.6.4 - ufo: 1.5.3 + ufo: 1.5.4 ollama-ai-provider@0.15.2(zod@3.23.8): dependencies: @@ -11002,8 +11126,6 @@ snapshots: typescript@5.5.2: {} - ufo@1.5.3: {} - ufo@1.5.4: {} unconfig@0.3.13: @@ -11122,6 +11244,8 @@ snapshots: unist-util-is: 6.0.0 unist-util-visit-parents: 6.0.1 + universal-user-agent@7.0.2: {} + universalify@2.0.1: {} unocss@0.61.3(postcss@8.4.38)(rollup@4.18.0)(vite@5.3.1(@types/node@20.14.9)(sass@1.77.6)): From 7424bff375cb89fbfede89adbaedbc934b13b1ad Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:16:16 +0100 Subject: [PATCH 07/28] Create github-build-push.yml --- .github/actions/github-build-push.yml | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/actions/github-build-push.yml diff --git a/.github/actions/github-build-push.yml b/.github/actions/github-build-push.yml new file mode 100644 index 000000000..56c707434 --- /dev/null +++ b/.github/actions/github-build-push.yml @@ -0,0 +1,50 @@ +name: Build and Push Container + +on: + push: + branches: + - main + paths: + - 'Dockerfile' + workflow_dispatch: +jobs: + build-and-push: + runs-on: [self-hosted] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Containers + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.sha }} + + - name: Build and Push Containers + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm + push: true + tags: | + registry.bukn.net/${{ github.event.repository.name }}:latest + registry.bukn.net/${{ github.event.repository.name }}:${{ github.sha }} From fc688ec038ba9e16780005b3470152cf3193301b Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:17:59 +0100 Subject: [PATCH 08/28] moved action --- .github/{actions => workflows}/github-build-push.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{actions => workflows}/github-build-push.yml (100%) diff --git a/.github/actions/github-build-push.yml b/.github/workflows/github-build-push.yml similarity index 100% rename from .github/actions/github-build-push.yml rename to .github/workflows/github-build-push.yml From 21a0a075f8259c932d819b77030a933399e47587 Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:19:16 +0100 Subject: [PATCH 09/28] Update github-build-push.yml --- .github/workflows/github-build-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-build-push.yml b/.github/workflows/github-build-push.yml index 56c707434..1d314b7a7 100644 --- a/.github/workflows/github-build-push.yml +++ b/.github/workflows/github-build-push.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: jobs: build-and-push: - runs-on: [self-hosted] + runs-on: [ubuntu-latest] steps: - name: Checkout code uses: actions/checkout@v4 From 8150f6f4596bc94a925dfc9bc99ce5c96cd52cdd Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:20:04 +0100 Subject: [PATCH 10/28] Update github-build-push.yml --- .github/workflows/github-build-push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-build-push.yml b/.github/workflows/github-build-push.yml index 1d314b7a7..c11b7ccd9 100644 --- a/.github/workflows/github-build-push.yml +++ b/.github/workflows/github-build-push.yml @@ -4,8 +4,8 @@ on: push: branches: - main - paths: - - 'Dockerfile' + # paths: + # - 'Dockerfile' workflow_dispatch: jobs: build-and-push: From 1799636ba26b957ecb63717df711853ce870265c Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:25:56 +0100 Subject: [PATCH 11/28] Update github-build-push.yml --- .github/workflows/github-build-push.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/github-build-push.yml b/.github/workflows/github-build-push.yml index c11b7ccd9..00177a03e 100644 --- a/.github/workflows/github-build-push.yml +++ b/.github/workflows/github-build-push.yml @@ -36,15 +36,4 @@ jobs: push: true tags: | ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:${{ github.sha }} - - - name: Build and Push Containers - uses: docker/build-push-action@v2 - with: - context: . - file: Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm - push: true - tags: | - registry.bukn.net/${{ github.event.repository.name }}:latest - registry.bukn.net/${{ github.event.repository.name }}:${{ github.sha }} + ghcr.io/${{ github.repository }}:${{ github.sha }} From 29f87974cf7ae7f202559fc212f3ceb037668cc4 Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Mon, 21 Oct 2024 20:29:01 +0100 Subject: [PATCH 12/28] Update github-build-push.yml --- .github/workflows/github-build-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-build-push.yml b/.github/workflows/github-build-push.yml index 00177a03e..4d4db05d8 100644 --- a/.github/workflows/github-build-push.yml +++ b/.github/workflows/github-build-push.yml @@ -32,7 +32,7 @@ jobs: with: context: . file: Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm + platforms: linux/amd64,linux/arm64 push: true tags: | ghcr.io/${{ github.repository }}:latest From 49217f246177a30bf99fdd2465beeafa014a92da Mon Sep 17 00:00:00 2001 From: muzafferkadir Date: Tue, 22 Oct 2024 01:27:29 +0300 Subject: [PATCH 13/28] feat: added sync files to selected local folder function is created. Yarn package manager fixes, styling fixes. Sass module fix. Added Claude model for open router. --- app/components/workbench/Workbench.client.tsx | 24 +++++++++++- app/lib/stores/workbench.ts | 38 +++++++++++++++++-- app/types/global.d.ts | 3 ++ app/utils/constants.ts | 2 + package.json | 2 +- vite.config.ts | 7 ++++ 6 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 app/types/global.d.ts diff --git a/app/components/workbench/Workbench.client.tsx b/app/components/workbench/Workbench.client.tsx index 839e9a807..4dd700dd1 100644 --- a/app/components/workbench/Workbench.client.tsx +++ b/app/components/workbench/Workbench.client.tsx @@ -1,7 +1,7 @@ import { useStore } from '@nanostores/react'; import { motion, type HTMLMotionProps, type Variants } from 'framer-motion'; import { computed } from 'nanostores'; -import { memo, useCallback, useEffect } from 'react'; +import { memo, useCallback, useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { type OnChangeCallback as OnEditorChange, @@ -55,6 +55,8 @@ const workbenchVariants = { export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) => { renderLogger.trace('Workbench'); + const [isSyncing, setIsSyncing] = useState(false); + const hasPreview = useStore(computed(workbenchStore.previews, (previews) => previews.length > 0)); const showWorkbench = useStore(workbenchStore.showWorkbench); const selectedFile = useStore(workbenchStore.selectedFile); @@ -99,6 +101,21 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) => workbenchStore.resetCurrentDocument(); }, []); + const handleSyncFiles = useCallback(async () => { + setIsSyncing(true); + + try { + const directoryHandle = await window.showDirectoryPicker(); + await workbenchStore.syncFiles(directoryHandle); + toast.success('Files synced successfully'); + } catch (error) { + console.error('Error syncing files:', error); + toast.error('Failed to sync files'); + } finally { + setIsSyncing(false); + } + }, []); + return ( chatStarted && (
Download Code + + {isSyncing ?
:
} + {isSyncing ? 'Syncing...' : 'Sync Files'} + { @@ -184,7 +205,6 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) => ) ); }); - interface ViewProps extends HTMLMotionProps<'div'> { children: JSX.Element; } diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index 4b85bc2e6..e9f726da7 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -280,21 +280,22 @@ export class WorkbenchStore { for (const [filePath, dirent] of Object.entries(files)) { if (dirent?.type === 'file' && !dirent.isBinary) { - // Remove '/home/project/' from the beginning of the path + // remove '/home/project/' from the beginning of the path const relativePath = filePath.replace(/^\/home\/project\//, ''); - // Split the path into segments + // split the path into segments const pathSegments = relativePath.split('/'); - // If there's more than one segment, we need to create folders + // if there's more than one segment, we need to create folders if (pathSegments.length > 1) { let currentFolder = zip; + for (let i = 0; i < pathSegments.length - 1; i++) { currentFolder = currentFolder.folder(pathSegments[i])!; } currentFolder.file(pathSegments[pathSegments.length - 1], dirent.content); } else { - // If there's only one segment, it's a file in the root + // if there's only one segment, it's a file in the root zip.file(relativePath, dirent.content); } } @@ -303,6 +304,35 @@ export class WorkbenchStore { const content = await zip.generateAsync({ type: 'blob' }); saveAs(content, 'project.zip'); } + + async syncFiles(targetHandle: FileSystemDirectoryHandle) { + const files = this.files.get(); + const syncedFiles = []; + + for (const [filePath, dirent] of Object.entries(files)) { + if (dirent?.type === 'file' && !dirent.isBinary) { + const relativePath = filePath.replace(/^\/home\/project\//, ''); + const pathSegments = relativePath.split('/'); + let currentHandle = targetHandle; + + for (let i = 0; i < pathSegments.length - 1; i++) { + currentHandle = await currentHandle.getDirectoryHandle(pathSegments[i], { create: true }); + } + + // create or get the file + const fileHandle = await currentHandle.getFileHandle(pathSegments[pathSegments.length - 1], { create: true }); + + // write the file content + const writable = await fileHandle.createWritable(); + await writable.write(dirent.content); + await writable.close(); + + syncedFiles.push(relativePath); + } + } + + return syncedFiles; + } } export const workbenchStore = new WorkbenchStore(); diff --git a/app/types/global.d.ts b/app/types/global.d.ts new file mode 100644 index 000000000..a1f6789de --- /dev/null +++ b/app/types/global.d.ts @@ -0,0 +1,3 @@ +interface Window { + showDirectoryPicker(): Promise; +} diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 6db860c53..eb7a6eb2d 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -10,6 +10,8 @@ export const DEFAULT_PROVIDER = 'Anthropic'; const staticModels: ModelInfo[] = [ { name: 'claude-3-5-sonnet-20240620', label: 'Claude 3.5 Sonnet', provider: 'Anthropic' }, { name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI' }, + { name: 'anthropic/claude-3.5-sonnet', label: 'Anthropic: Claude 3.5 Sonnet (OpenRouter)', provider: 'OpenRouter' }, + { name: 'anthropic/claude-3-haiku', label: 'Anthropic: Claude 3 Haiku (OpenRouter)', provider: 'OpenRouter' }, { name: 'deepseek/deepseek-coder', label: 'Deepseek-Coder V2 236B (OpenRouter)', provider: 'OpenRouter' }, { name: 'google/gemini-flash-1.5', label: 'Google Gemini Flash 1.5 (OpenRouter)', provider: 'OpenRouter' }, { name: 'google/gemini-pro-1.5', label: 'Google Gemini Pro 1.5 (OpenRouter)', provider: 'OpenRouter' }, diff --git a/package.json b/package.json index 737ca05cb..2bd517395 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "description": "StackBlitz AI Agent", "private": true, "license": "MIT", - "packageManager": "pnpm@9.4.0", "sideEffects": false, "type": "module", "scripts": { @@ -94,6 +93,7 @@ "is-ci": "^3.0.1", "node-fetch": "^3.3.2", "prettier": "^3.3.2", + "sass-embedded": "^1.80.3", "typescript": "^5.5.2", "unified": "^11.0.5", "unocss": "^0.61.3", diff --git a/vite.config.ts b/vite.config.ts index 58e76cde5..1c5a0a6ac 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -27,6 +27,13 @@ export default defineConfig((config) => { chrome129IssuePlugin(), config.mode === 'production' && optimizeCssModules({ apply: 'build' }), ], + css: { + preprocessorOptions: { + scss: { + api: 'modern-compiler', + }, + }, + }, }; }); From 5e8a0b077a47598f73bacffbeb0764ba13095662 Mon Sep 17 00:00:00 2001 From: ArulGandhi Date: Tue, 22 Oct 2024 09:22:36 +0530 Subject: [PATCH 14/28] add mistral models --- .env.example | 5 +++++ app/lib/.server/llm/api-key.ts | 2 ++ app/lib/.server/llm/model.ts | 12 ++++++++++++ app/utils/constants.ts | 2 ++ package.json | 1 + 5 files changed, 22 insertions(+) diff --git a/.env.example b/.env.example index 968e93484..15978eeb9 100644 --- a/.env.example +++ b/.env.example @@ -29,5 +29,10 @@ GOOGLE_GENERATIVE_AI_API_KEY= # EXAMPLE http://localhost:11434 OLLAMA_API_BASE_URL= +# Get your Mistral API Key by following these instructions - +# https://console.mistral.ai/api-keys/ +# You only need this environment variable set if you want to use Mistral models +MISTRAL_API_KEY= + # Include this environment variable if you want more logging for debugging locally VITE_LOG_LEVEL=debug diff --git a/app/lib/.server/llm/api-key.ts b/app/lib/.server/llm/api-key.ts index b1a47f428..17eeeef2d 100644 --- a/app/lib/.server/llm/api-key.ts +++ b/app/lib/.server/llm/api-key.ts @@ -19,6 +19,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string) { return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY; case 'OpenRouter': return env.OPEN_ROUTER_API_KEY || cloudflareEnv.OPEN_ROUTER_API_KEY; + case 'Mistral': + return env.MISTRAL_API_KEY || cloudflareEnv.MISTRAL_API_KEY; default: return ""; } diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 68983756d..e07fdc449 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -6,6 +6,8 @@ import { createOpenAI } from '@ai-sdk/openai'; import { createGoogleGenerativeAI } from '@ai-sdk/google'; import { ollama } from 'ollama-ai-provider'; import { createOpenRouter } from "@openrouter/ai-sdk-provider"; +import { mistral } from '@ai-sdk/mistral'; +import { createMistral } from '@ai-sdk/mistral'; export function getAnthropicModel(apiKey: string, model: string) { const anthropic = createAnthropic({ @@ -23,6 +25,14 @@ export function getOpenAIModel(apiKey: string, model: string) { return openai(model); } +export function getMistralModel(apiKey: string, model: string) { + const mistral = createMistral({ + apiKey + }); + + return mistral(model); +} + export function getGoogleModel(apiKey: string, model: string) { const google = createGoogleGenerativeAI( apiKey, @@ -67,6 +77,8 @@ export function getModel(provider: string, model: string, env: Env) { return getOpenRouterModel(apiKey, model); case 'Google': return getGoogleModel(apiKey, model) + case 'Mistral': + return getMistralModel(apiKey, model); default: return getOllamaModel(model); } diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 6db860c53..509566364 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -30,6 +30,8 @@ const staticModels: ModelInfo[] = [ { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, + { name: 'open-mistral-7b', label: 'Mistral', provider: 'Mistral' }, + ]; export let MODEL_LIST: ModelInfo[] = [...staticModels]; diff --git a/package.json b/package.json index 737ca05cb..a24fb033c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@ai-sdk/anthropic": "^0.0.39", "@ai-sdk/google": "^0.0.52", "@ai-sdk/openai": "^0.0.66", + "@ai-sdk/mistral": "^0.0.43", "@codemirror/autocomplete": "^6.17.0", "@codemirror/commands": "^6.6.0", "@codemirror/lang-cpp": "^6.0.2", From 1b1cd183f57d87750bc9c22c2de680ba78df51c1 Mon Sep 17 00:00:00 2001 From: ArulGandhi Date: Tue, 22 Oct 2024 09:47:30 +0530 Subject: [PATCH 15/28] mistral models added more mistral models added. some tested, rest assumed to be working --- app/utils/constants.ts | 12 ++++++++++-- pnpm-lock.yaml | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 509566364..19008ffda 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -30,8 +30,16 @@ const staticModels: ModelInfo[] = [ { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, - { name: 'open-mistral-7b', label: 'Mistral', provider: 'Mistral' }, - + { name: 'open-mistral-7b', label: 'Mistral 7B', provider: 'Mistral' }, + { name: 'open-mixtral-8x7b', label: 'Mistral 8x7B', provider: 'Mistral' }, + { name: 'open-mixtral-8x22b', label: 'Mistral 8x22B', provider: 'Mistral' }, + { name: 'open-codestral-mamba', label: 'Codestral Mamba', provider: 'Mistral' }, + { name: 'open-mistral-nemo', label: 'Mistral Nemo', provider: 'Mistral' }, + { name: 'pixtral-12b-2409', label: 'Pixtral 12B', provider: 'Mistral' }, + { name: 'ministral-8b-latest', label: 'Mistral 8B', provider: 'Mistral' }, + { name: 'ministral-small-latest', label: 'Mistral Small', provider: 'Mistral' }, + { name: 'codestral-latest', label: 'Codestral', provider: 'Mistral' }, + { name: 'ministral-large-latest', label: 'Mistral Large Latest', provider: 'Mistral' }, ]; export let MODEL_LIST: ModelInfo[] = [...staticModels]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 46dc9dbfc..1abbc9dd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@ai-sdk/google': specifier: ^0.0.52 version: 0.0.52(zod@3.23.8) + '@ai-sdk/mistral': + specifier: ^0.0.43 + version: 0.0.43(zod@3.23.8) '@ai-sdk/openai': specifier: ^0.0.66 version: 0.0.66(zod@3.23.8) @@ -264,6 +267,12 @@ packages: peerDependencies: zod: ^3.0.0 + '@ai-sdk/mistral@0.0.43': + resolution: {integrity: sha512-YcneVvO57bbmseUmnvQaj6OolMj7/q1W/oeiFj1h+CJZsXIOX8P9i2Cmo2B7HMBbt73NIcvtyPze3GjaczZRqw==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.0.0 + '@ai-sdk/openai@0.0.66': resolution: {integrity: sha512-V4XeDnlNl5/AY3GB3ozJUjqnBLU5pK3DacKTbCNH3zH8/MggJoH6B8wRGdLUPVFMcsMz60mtvh4DC9JsIVFrKw==} engines: {node: '>=18'} @@ -5387,6 +5396,12 @@ snapshots: json-schema: 0.4.0 zod: 3.23.8 + '@ai-sdk/mistral@0.0.43(zod@3.23.8)': + dependencies: + '@ai-sdk/provider': 0.0.24 + '@ai-sdk/provider-utils': 1.0.20(zod@3.23.8) + zod: 3.23.8 + '@ai-sdk/openai@0.0.66(zod@3.23.8)': dependencies: '@ai-sdk/provider': 0.0.24 From 285a95568f8f91d5cb511992a6f0bc51d6d7dab7 Mon Sep 17 00:00:00 2001 From: ArulGandhi Date: Tue, 22 Oct 2024 09:49:21 +0530 Subject: [PATCH 16/28] removed pixtral --- app/utils/constants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 19008ffda..8800424ea 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -35,7 +35,6 @@ const staticModels: ModelInfo[] = [ { name: 'open-mixtral-8x22b', label: 'Mistral 8x22B', provider: 'Mistral' }, { name: 'open-codestral-mamba', label: 'Codestral Mamba', provider: 'Mistral' }, { name: 'open-mistral-nemo', label: 'Mistral Nemo', provider: 'Mistral' }, - { name: 'pixtral-12b-2409', label: 'Pixtral 12B', provider: 'Mistral' }, { name: 'ministral-8b-latest', label: 'Mistral 8B', provider: 'Mistral' }, { name: 'ministral-small-latest', label: 'Mistral Small', provider: 'Mistral' }, { name: 'codestral-latest', label: 'Codestral', provider: 'Mistral' }, From 34ead80f6241ad81db3df096019c494a8b27dc49 Mon Sep 17 00:00:00 2001 From: TarekS93 <37110556+TarekS93@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:18:34 +0200 Subject: [PATCH 17/28] Update types.ts --- app/utils/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/types.ts b/app/utils/types.ts index 7ace4e64d..5fcd2de25 100644 --- a/app/utils/types.ts +++ b/app/utils/types.ts @@ -8,7 +8,7 @@ interface OllamaModelDetails { quantization_level: string; } -interface OllamaModel { +export interface OllamaModel { name: string; model: string; modified_at: string; From f70652305dbe41d8e9bcbe6287acc44ebd02110c Mon Sep 17 00:00:00 2001 From: TarekS93 <37110556+TarekS93@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:19:08 +0200 Subject: [PATCH 18/28] Update constants.ts --- app/utils/constants.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 6db860c53..bea5c82a3 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -1,4 +1,4 @@ -import type { ModelInfo } from './types'; +import type { ModelInfo, OllamaApiResponse, OllamaModel } from './types'; export const WORK_DIR_NAME = 'project'; export const WORK_DIR = `/home/${WORK_DIR_NAME}`; @@ -37,9 +37,9 @@ export let MODEL_LIST: ModelInfo[] = [...staticModels]; async function getOllamaModels(): Promise { try { const response = await fetch(`http://localhost:11434/api/tags`); - const data = await response.json(); + const data = await response.json() as OllamaApiResponse; - return data.models.map((model: any) => ({ + return data.models.map((model: OllamaModel) => ({ name: model.name, label: `${model.name} (${model.details.parameter_size})`, provider: 'Ollama', From 3b90afba48d6b47642368aa301fd104804ff081e Mon Sep 17 00:00:00 2001 From: zenith110 Date: Tue, 22 Oct 2024 18:19:27 -0400 Subject: [PATCH 19/28] Added deepseek models --- app/lib/.server/llm/api-key.ts | 2 ++ app/lib/.server/llm/model.ts | 10 ++++++++++ app/utils/constants.ts | 2 ++ worker-configuration.d.ts | 1 + 4 files changed, 15 insertions(+) diff --git a/app/lib/.server/llm/api-key.ts b/app/lib/.server/llm/api-key.ts index b1a47f428..54f7a3102 100644 --- a/app/lib/.server/llm/api-key.ts +++ b/app/lib/.server/llm/api-key.ts @@ -19,6 +19,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string) { return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY; case 'OpenRouter': return env.OPEN_ROUTER_API_KEY || cloudflareEnv.OPEN_ROUTER_API_KEY; + case 'Deepseek': + return env.DEEPSEEK_API_KEY || cloudflareEnv.DEEPSEEK_API_KEY default: return ""; } diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 68983756d..6d5e4be97 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -40,6 +40,14 @@ export function getGroqModel(apiKey: string, model: string) { return openai(model); } +export function getDeepseekModel(apiKey: string, model: string){ + const openai = createOpenAI({ + baseURL: 'https://api.deepseek.com/beta', + apiKey, + }); + + return openai(model); +} export function getOllamaModel(model: string) { return ollama(model); } @@ -67,6 +75,8 @@ export function getModel(provider: string, model: string, env: Env) { return getOpenRouterModel(apiKey, model); case 'Google': return getGoogleModel(apiKey, model) + case 'Deepseek': + return getDeepseekModel(apiKey, model) default: return getOllamaModel(model); } diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 6db860c53..c080423f8 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -30,6 +30,8 @@ const staticModels: ModelInfo[] = [ { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, + { name: 'deepseek-coder', label: 'Deepseek-Coder', provider: 'Deepseek'}, + { name: 'deepseek-chat', label: 'Deepseek-Chat', provider: 'Deepseek'}, ]; export let MODEL_LIST: ModelInfo[] = [...staticModels]; diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index f3259893e..2f7f64234 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -4,4 +4,5 @@ interface Env { GROQ_API_KEY: string; OPEN_ROUTER_API_KEY: string; OLLAMA_API_BASE_URL: string; + DEEPSEEK_API_KEY: string; } From 9ca017c40fda9b79291568b8faaf2b8e21d207af Mon Sep 17 00:00:00 2001 From: Aaron Bolton Date: Wed, 23 Oct 2024 14:57:53 +0100 Subject: [PATCH 20/28] Update docker-compose.yml --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 70b4fef07..21ef4c097 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: # - OPENAI_API_KEY=${OPENAI_API_KEY} # - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} # - GROQ_API_KEY=${GROQ_API_KEY} + # - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} volumes: # This volume is for development purposes, allowing live code updates # Comment out or remove for production From 30dfa4fda433069a88714d9b0abe0d60b80eff51 Mon Sep 17 00:00:00 2001 From: Gaoyao Massimo Hu Date: Wed, 23 Oct 2024 16:36:12 +0100 Subject: [PATCH 21/28] chore: Add environment variables for OpenAI API Like integration --- .env.example | 8 ++++++++ app/components/chat/BaseChat.tsx | 13 ++++++++----- app/lib/.server/llm/api-key.ts | 11 +++++++++++ app/lib/.server/llm/model.ts | 13 +++++++++++-- app/utils/constants.ts | 33 ++++++++++++++++++++++++++++++-- vite.config.ts | 1 + worker-configuration.d.ts | 2 ++ 7 files changed, 72 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 968e93484..2fa90e447 100644 --- a/.env.example +++ b/.env.example @@ -29,5 +29,13 @@ GOOGLE_GENERATIVE_AI_API_KEY= # EXAMPLE http://localhost:11434 OLLAMA_API_BASE_URL= +# You only need this environment variable set if you want to use OpenAI API Like models +# EXAMPLE https://xxx.xxxx.com/v1 +OPENAI_API_LIKE_BASE_URL= + +# Get your OpenAI API Like Key by following these instructions - +# https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key +OPENAI_API_LIKE_KEY= + # Include this environment variable if you want more logging for debugging locally VITE_LOG_LEVEL=debug diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index b7421349e..bb0670650 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -28,7 +28,7 @@ const ModelSelector = ({ model, setModel, modelList, providerList }) => { const [provider, setProvider] = useState(DEFAULT_PROVIDER); return (
-