From 06a022a8c013f2826b6d134ce8bd0ed8941495bd Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 30 Apr 2024 16:32:38 -0700 Subject: [PATCH 01/19] changed node version from 20.9 to 22 --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index b176926..b779dd2 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.9-bullseye-slim +FROM node:22-bullseye-slim # Set the working directory in the container WORKDIR /app From ac8198e5ba9c29b7ec15e7f612623e9aa8f343ef Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Fri, 17 May 2024 12:30:26 -0400 Subject: [PATCH 02/19] Add field for Anthropic API key in settings --- frontend/src/components/SettingsDialog.tsx | 20 ++++++++++++++++++++ frontend/src/types.ts | 1 + 2 files changed, 21 insertions(+) diff --git a/frontend/src/components/SettingsDialog.tsx b/frontend/src/components/SettingsDialog.tsx index 2e7814b..1a9c5a6 100644 --- a/frontend/src/components/SettingsDialog.tsx +++ b/frontend/src/components/SettingsDialog.tsx @@ -108,6 +108,26 @@ function SettingsDialog({ settings, setSettings }: Props) { )} + + + + setSettings((s) => ({ + ...s, + anthropicApiKey: e.target.value, + })) + } + /> + Screenshot by URL Config diff --git a/frontend/src/types.ts b/frontend/src/types.ts index bbabeff..dbe10ad 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -16,6 +16,7 @@ export interface Settings { codeGenerationModel: CodeGenerationModel; // Only relevant for hosted version isTermOfServiceAccepted: boolean; + anthropicApiKey: string | null; // Added property for anthropic API key } export enum AppState { From 1f9c5b2c80a52c285323350581d4cd605bda3097 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Fri, 17 May 2024 14:47:54 -0400 Subject: [PATCH 03/19] set initial value --- frontend/src/App.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index fd1576e..c05c44f 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, From d31ebcaa27eaf882bc57e84bba6ce301d042638e Mon Sep 17 00:00:00 2001 From: Naman <1608naman@gmail.com> Date: Wed, 29 May 2024 07:11:03 +0530 Subject: [PATCH 04/19] types fix in image generation file --- backend/image_generation.py | 26 ++++++++++++++------------ backend/routes/generate_code.py | 4 ++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/image_generation.py b/backend/image_generation.py index b93792c..a1c4629 100644 --- a/backend/image_generation.py +++ b/backend/image_generation.py @@ -11,16 +11,16 @@ async def process_tasks(prompts: List[str], api_key: str, base_url: str): processed_results: List[Union[str, None]] = [] for result in results: - if isinstance(result, Exception): + if isinstance(result, BaseException): print(f"An exception occurred: {result}") processed_results.append(None) else: - processed_results.append(result) # type: ignore + processed_results.append(result) return processed_results -async def generate_image(prompt: str, api_key: str, base_url: str): +async def generate_image(prompt: str, api_key: str, base_url: str) -> Union[str, None]: client = AsyncOpenAI(api_key=api_key, base_url=base_url) image_params: Dict[str, Union[str, int]] = { "model": "dall-e-3", @@ -63,13 +63,15 @@ def create_alt_url_mapping(code: str) -> Dict[str, str]: async def generate_images( code: str, api_key: str, base_url: Union[str, None], image_cache: Dict[str, str] -): +) -> Union[str, None]: + if base_url is None: + return code # Find all images soup = BeautifulSoup(code, "html.parser") images = soup.find_all("img") # Extract alt texts as image prompts - alts = [] + alts: List[str | None] = [] for img in images: # Only include URL if the image starts with https://placehold.co # and it's not already in the image_cache @@ -77,26 +79,26 @@ async def generate_images( img["src"].startswith("https://placehold.co") and image_cache.get(img.get("alt")) is None ): - alts.append(img.get("alt", None)) # type: ignore + alts.append(img.get("alt", None)) # Exclude images with no alt text - alts = [alt for alt in alts if alt is not None] # type: ignore + filtered_alts: List[str] = [alt for alt in alts if alt is not None] # Remove duplicates - prompts = list(set(alts)) # type: ignore + prompts = list(set(filtered_alts)) # Return early if there are no images to replace - if len(prompts) == 0: # type: ignore + if len(prompts) == 0: return code # Generate images - results = await process_tasks(prompts, api_key, base_url) # type: ignore + results = await process_tasks(prompts, api_key, base_url) # Create a dict mapping alt text to image URL - mapped_image_urls = dict(zip(prompts, results)) # type: ignore + mapped_image_urls = dict(zip(prompts, results)) # Merge with image_cache - mapped_image_urls = {**mapped_image_urls, **image_cache} # type: ignore + mapped_image_urls = {**mapped_image_urls, **image_cache} # Replace old image URLs with the generated URLs for img in images: diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.py index e7186fc..fc7330e 100644 --- a/backend/routes/generate_code.py +++ b/backend/routes/generate_code.py @@ -13,7 +13,7 @@ from llm import ( ) from openai.types.chat import ChatCompletionMessageParam from mock_llm import mock_completion -from typing import Dict, List, cast, get_args +from typing import Dict, List, Union, cast, get_args from image_generation import create_alt_url_mapping, generate_images from prompts import assemble_imported_code_prompt, assemble_prompt from datetime import datetime @@ -121,7 +121,7 @@ async def stream_code(websocket: WebSocket): return # Get the OpenAI Base URL from the request. Fall back to environment variable if not provided. - openai_base_url = None + openai_base_url: Union[str, None] = None # Disable user-specified OpenAI Base URL in prod if not os.environ.get("IS_PROD"): if "openAiBaseURL" in params and params["openAiBaseURL"]: From c5695975c710a6dd5d3f8c311c53857ca7f73d4a Mon Sep 17 00:00:00 2001 From: Naman <1608naman@gmail.com> Date: Sat, 25 May 2024 00:32:13 +0530 Subject: [PATCH 05/19] handle none type in llm.py --- backend/llm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/llm.py b/backend/llm.py index e541046..44f97e1 100644 --- a/backend/llm.py +++ b/backend/llm.py @@ -59,9 +59,10 @@ async def stream_openai_response( full_response = "" async for chunk in stream: # type: ignore assert isinstance(chunk, ChatCompletionChunk) - content = chunk.choices[0].delta.content or "" - full_response += content - await callback(content) + if chunk.choices and chunk.choices[0].delta.content: + content = chunk.choices[0].delta.content or "" + full_response += content + await callback(content) await client.close() From f0ee68666092b2579147aabfc5846f2568c983a3 Mon Sep 17 00:00:00 2001 From: Naman <1608naman@gmail.com> Date: Sat, 25 May 2024 07:02:02 +0530 Subject: [PATCH 06/19] null check for chunk.choices --- backend/llm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/llm.py b/backend/llm.py index 44f97e1..e32051c 100644 --- a/backend/llm.py +++ b/backend/llm.py @@ -59,7 +59,7 @@ async def stream_openai_response( full_response = "" async for chunk in stream: # type: ignore assert isinstance(chunk, ChatCompletionChunk) - if chunk.choices and chunk.choices[0].delta.content: + if chunk.choices and len(chunk.choices) > 0 and chunk.choices[0].delta and chunk.choices[0].delta.content: content = chunk.choices[0].delta.content or "" full_response += content await callback(content) From 8e579e425ee0bb12baf19186b71ee8a7b840d266 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Fri, 31 May 2024 13:51:43 -0400 Subject: [PATCH 07/19] clean up settings dialog look --- frontend/src/components/SettingsDialog.tsx | 84 +++++++++++----------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/frontend/src/components/SettingsDialog.tsx b/frontend/src/components/SettingsDialog.tsx index 1a9c5a6..97d8f38 100644 --- a/frontend/src/components/SettingsDialog.tsx +++ b/frontend/src/components/SettingsDialog.tsx @@ -49,7 +49,7 @@ function SettingsDialog({ settings, setSettings }: Props) {