From 4edcc5e3311f3f999eea833d27b7be0ada071a2b Mon Sep 17 00:00:00 2001 From: Karrot0 Date: Sun, 27 Oct 2024 23:16:07 -0400 Subject: [PATCH 01/23] LM Studio Integration --- .env.example | 5 + app/components/chat/BaseChat.tsx | 3 + app/lib/.server/llm/api-key.ts | 2 + app/lib/.server/llm/model.ts | 14 +- app/utils/constants.ts | 22 +- package-lock.json | 23450 +++++++++++++++++++++++++++++ vite.config.ts | 2 +- worker-configuration.d.ts | 1 + 8 files changed, 23494 insertions(+), 5 deletions(-) create mode 100644 package-lock.json diff --git a/.env.example b/.env.example index d5cfc5cb..53e157dd 100644 --- a/.env.example +++ b/.env.example @@ -40,5 +40,10 @@ OPENAI_LIKE_API_KEY= # You only need this environment variable set if you want to use Mistral models MISTRAL_API_KEY= +# Get LMStudio Base URL from LM Studio Developer Console +# Make sure to enable CORS +# Example: http://localhost:1234 +LMSTUDIO_API_BASE_URL= + # 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 c1175f70..68f852af 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -48,6 +48,9 @@ const ModelSelector = ({ model, setModel, modelList, providerList }) => { + { setProvider(e.target.value); - const firstModel = [...modelList].find(m => m.provider == e.target.value); + const firstModel = [...modelList].find((m) => m.provider == e.target.value); setModel(firstModel ? firstModel.name : ''); }} className="flex-1 p-2 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus transition-all" @@ -58,11 +58,13 @@ const ModelSelector = ({ model, setModel, provider, setProvider, modelList, prov onChange={(e) => setModel(e.target.value)} className="flex-1 p-2 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus transition-all" > - {[...modelList].filter(e => e.provider == provider && e.name).map((modelOption) => ( - - ))} + {[...modelList] + .filter((e) => e.provider == provider && e.name) + .map((modelOption) => ( + + ))} ); @@ -81,10 +83,10 @@ interface BaseChatProps { enhancingPrompt?: boolean; promptEnhanced?: boolean; input?: string; - model: string; - setModel: (model: string) => void; + model?: string; + setModel?: (model: string) => void; provider: string; - setProvider: (provider: string) => void; + setProvider?: (provider: string) => void; handleStop?: () => void; sendMessage?: (event: React.UIEvent, messageInput?: string) => void; handleInputChange?: (event: React.ChangeEvent) => void; @@ -144,7 +146,7 @@ export const BaseChat = React.forwardRef( expires: 30, // 30 days secure: true, // Only send over HTTPS sameSite: 'strict', // Protect against CSRF - path: '/' // Accessible across the site + path: '/', // Accessible across the site }); } catch (error) { console.error('Error saving API keys to cookies:', error); @@ -281,7 +283,9 @@ export const BaseChat = React.forwardRef( {input.length > 3 ? (
- Use Shift + Return for a new line + Use Shift +{' '} + Return for + a new line
) : null} @@ -315,4 +319,4 @@ export const BaseChat = React.forwardRef( ); }, -); \ No newline at end of file +); diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index 6a634897..8589391c 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -11,7 +11,7 @@ import { PreviewsStore } from './previews'; import { TerminalStore } from './terminal'; import JSZip from 'jszip'; import { saveAs } from 'file-saver'; -import { Octokit } from "@octokit/rest"; +import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest"; import * as nodePath from 'node:path'; import type { WebContainerProcess } from '@webcontainer/api'; @@ -382,9 +382,10 @@ export class WorkbenchStore { const octokit = new Octokit({ auth: githubToken }); // Check if the repository already exists before creating it - let repo + let repo: RestEndpointMethodTypes["repos"]["get"]["response"]['data'] try { - repo = await octokit.repos.get({ owner: owner, repo: repoName }); + let resp = await octokit.repos.get({ owner: owner, repo: repoName }); + repo = resp.data } catch (error) { if (error instanceof Error && 'status' in error && error.status === 404) { // Repository doesn't exist, so create a new one From 8c6e420546ac749f5ac71efced78b2bb873f06e6 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Wed, 13 Nov 2024 00:04:41 +0530 Subject: [PATCH 23/23] type fix --- app/components/chat/BaseChat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 0421de12..f7fe80a0 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -85,7 +85,7 @@ interface BaseChatProps { input?: string; model?: string; setModel?: (model: string) => void; - provider: string; + provider?: string; setProvider?: (provider: string) => void; handleStop?: () => void; sendMessage?: (event: React.UIEvent, messageInput?: string) => void;