diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.py index e7186fc..3fb92f1 100644 --- a/backend/routes/generate_code.py +++ b/backend/routes/generate_code.py @@ -120,6 +120,17 @@ async def stream_code(websocket: WebSocket): ) return + # Get the Anthropic API key from the request. Fall back to environment variable if not provided. + # If neither is provided, we throw an error later only if Claude is used. + anthropic_api_key = None + if "anthropicApiKey" in params and params["anthropicApiKey"]: + anthropic_api_key = params["anthropicApiKey"] + print("Using Anthropic API key from client-side settings dialog") + else: + anthropic_api_key = ANTHROPIC_API_KEY + if anthropic_api_key: + print("Using Anthropic API key from environment variable") + # Get the OpenAI Base URL from the request. Fall back to environment variable if not provided. openai_base_url = None # Disable user-specified OpenAI Base URL in prod @@ -219,31 +230,31 @@ async def stream_code(websocket: WebSocket): else: try: if validated_input_mode == "video": - if not ANTHROPIC_API_KEY: + if not anthropic_api_key: await throw_error( - "Video only works with Anthropic models. No Anthropic API key found. Please add the environment variable ANTHROPIC_API_KEY to backend/.env" + "Video only works with Anthropic models. No Anthropic API key found. Please add the environment variable ANTHROPIC_API_KEY to backend/.env or in the settings dialog" ) raise Exception("No Anthropic key") completion = await stream_claude_response_native( system_prompt=VIDEO_PROMPT, messages=prompt_messages, # type: ignore - api_key=ANTHROPIC_API_KEY, + api_key=anthropic_api_key, callback=lambda x: process_chunk(x), model=Llm.CLAUDE_3_OPUS, include_thinking=True, ) exact_llm_version = Llm.CLAUDE_3_OPUS elif code_generation_model == Llm.CLAUDE_3_SONNET: - if not ANTHROPIC_API_KEY: + if not anthropic_api_key: await throw_error( - "No Anthropic API key found. Please add the environment variable ANTHROPIC_API_KEY to backend/.env" + "No Anthropic API key found. Please add the environment variable ANTHROPIC_API_KEY to backend/.env or in the settings dialog" ) raise Exception("No Anthropic key") completion = await stream_claude_response( prompt_messages, # type: ignore - api_key=ANTHROPIC_API_KEY, + api_key=anthropic_api_key, callback=lambda x: process_chunk(x), ) exact_llm_version = code_generation_model diff --git a/frontend/package.json b/frontend/package.json index 92bebfc..4652dc7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -46,7 +46,8 @@ "tailwindcss-animate": "^1.0.7", "thememirror": "^2.0.1", "vite-plugin-checker": "^0.6.2", - "webm-duration-fix": "^1.0.4" + "webm-duration-fix": "^1.0.4", + "zustand": "^4.5.2" }, "devDependencies": { "@types/jest": "^29.5.12", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ce68c53..f0d86fc 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -59,6 +59,7 @@ function App() { { openAiApiKey: null, openAiBaseURL: null, + anthropicApiKey: null, screenshotOneApiKey: null, isImageGenerationEnabled: true, editorTheme: EditorTheme.COBALT, @@ -378,7 +379,10 @@ function App() { /> )}
-
+

Screenshot to Code

diff --git a/frontend/src/components/SettingsDialog.tsx b/frontend/src/components/SettingsDialog.tsx index 2e7814b..97d8f38 100644 --- a/frontend/src/components/SettingsDialog.tsx +++ b/frontend/src/components/SettingsDialog.tsx @@ -49,7 +49,7 @@ function SettingsDialog({ settings, setSettings }: Props) {