From 315579e8da06feaef8a98ae4e28244281cdcb193 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:53:23 +0000 Subject: [PATCH 01/87] Create sweep.yaml --- sweep.yaml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sweep.yaml diff --git a/sweep.yaml b/sweep.yaml new file mode 100644 index 0000000..ada0e25 --- /dev/null +++ b/sweep.yaml @@ -0,0 +1,42 @@ +# Sweep AI turns bugs & feature requests into code changes (https://sweep.dev) +# For details on our config file, check out our docs at https://docs.sweep.dev/usage/config + +# This setting contains a list of rules that Sweep will check for. If any of these rules are broken in a new commit, Sweep will create an pull request to fix the broken rule. +rules: + - "All docstrings and comments should be up to date." +['All new business logic should have corresponding unit tests.', 'Refactor large functions to be more modular.', 'Add docstrings to all functions and file headers.'] + +# This is the branch that Sweep will develop from and make pull requests to. Most people use 'main' or 'master' but some users also use 'dev' or 'staging'. +branch: 'main' + +# By default Sweep will read the logs and outputs from your existing Github Actions. To disable this, set this to false. +gha_enabled: True + +# This is the description of your project. It will be used by sweep when creating PRs. You can tell Sweep what's unique about your project, what frameworks you use, or anything else you want. +# +# Example: +# +# description: sweepai/sweep is a python project. The main api endpoints are in sweepai/api.py. Write code that adheres to PEP8. +description: '' + +# This sets whether to create pull requests as drafts. If this is set to True, then all pull requests will be created as drafts and GitHub Actions will not be triggered. +draft: False + +# This is a list of directories that Sweep will not be able to edit. +blocked_dirs: [] + +# This is a list of documentation links that Sweep will use to help it understand your code. You can add links to documentation for any packages you use here. +# +# Example: +# +# docs: +# - PyGitHub: ["https://pygithub.readthedocs.io/en/latest/", "We use pygithub to interact with the GitHub API"] +docs: [] + +# Sandbox executes commands in a sandboxed environment to validate code changes after every edit to guarantee pristine code. For more details, see the [Sandbox](./sandbox) page. +sandbox: + install: + - trunk init + check: + - trunk fmt {file_path} || return 0 + - trunk check --fix --print-failures {file_path} From 6e699c7f72bc47a8a0f33ed9a3d3118918ee254e Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:53:24 +0000 Subject: [PATCH 02/87] Create sweep template --- .github/ISSUE_TEMPLATE/sweep-template.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/sweep-template.yml diff --git a/.github/ISSUE_TEMPLATE/sweep-template.yml b/.github/ISSUE_TEMPLATE/sweep-template.yml new file mode 100644 index 0000000..44116f5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/sweep-template.yml @@ -0,0 +1,15 @@ +name: Sweep Issue +title: 'Sweep: ' +description: For small bugs, features, refactors, and tests to be handled by Sweep, an AI-powered junior developer. +labels: sweep +body: + - type: textarea + id: description + attributes: + label: Details + description: Tell Sweep where and what to edit and provide enough context for a new developer to the codebase + placeholder: | + Unit Tests: Write unit tests for . Test each function in the file. Make sure to test edge cases. + Bugs: The bug might be in . Here are the logs: ... + Features: the new endpoint should use the ... class from because it contains ... logic. + Refactors: We are migrating this function to ... version because ... \ No newline at end of file From e69269d844b7089dec636516d6edb4f70911ebf6 Mon Sep 17 00:00:00 2001 From: Nothing1024 Date: Tue, 21 Nov 2023 16:05:23 +0800 Subject: [PATCH 03/87] Feat: OpenAI Base URL supported --- backend/image_generation.py | 12 ++++++------ backend/llm.py | 4 ++-- backend/main.py | 15 ++++++++++++++- frontend/src/App.tsx | 1 + frontend/src/components/SettingsDialog.tsx | 19 +++++++++++++++++++ frontend/src/types.ts | 1 + 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/backend/image_generation.py b/backend/image_generation.py index 080334f..ad21772 100644 --- a/backend/image_generation.py +++ b/backend/image_generation.py @@ -5,8 +5,8 @@ from openai import AsyncOpenAI from bs4 import BeautifulSoup -async def process_tasks(prompts, api_key): - tasks = [generate_image(prompt, api_key) for prompt in prompts] +async def process_tasks(prompts, api_key, base_url): + tasks = [generate_image(prompt, api_key, base_url) for prompt in prompts] results = await asyncio.gather(*tasks, return_exceptions=True) processed_results = [] @@ -20,8 +20,8 @@ async def process_tasks(prompts, api_key): return processed_results -async def generate_image(prompt, api_key): - client = AsyncOpenAI(api_key=api_key) +async def generate_image(prompt, api_key, base_url): + client = AsyncOpenAI(api_key=api_key, base_url=base_url) image_params = { "model": "dall-e-3", "quality": "standard", @@ -60,7 +60,7 @@ def create_alt_url_mapping(code): return mapping -async def generate_images(code, api_key, image_cache): +async def generate_images(code, api_key, base_url, image_cache): # Find all images soup = BeautifulSoup(code, "html.parser") images = soup.find_all("img") @@ -87,7 +87,7 @@ async def generate_images(code, api_key, image_cache): return code # Generate images - results = await process_tasks(prompts, api_key) + 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)) diff --git a/backend/llm.py b/backend/llm.py index b52c3c9..82a765e 100644 --- a/backend/llm.py +++ b/backend/llm.py @@ -6,9 +6,9 @@ MODEL_GPT_4_VISION = "gpt-4-vision-preview" async def stream_openai_response( - messages, api_key: str, callback: Callable[[str], Awaitable[None]] + messages, api_key: str, base_url:str, callback: Callable[[str], Awaitable[None]] ): - client = AsyncOpenAI(api_key=api_key) + client = AsyncOpenAI(api_key=api_key, base_url=base_url) model = MODEL_GPT_4_VISION diff --git a/backend/main.py b/backend/main.py index 4eb09fa..bd161c8 100644 --- a/backend/main.py +++ b/backend/main.py @@ -73,6 +73,13 @@ async def stream_code_test(websocket: WebSocket): openai_api_key = os.environ.get("OPENAI_API_KEY") if openai_api_key: print("Using OpenAI API key from environment variable") + if params["openAiBaseURL"]: + openai_base_url = params["openAiBaseURL"] + print("Using OpenAI Base URL from client-side settings dialog") + else: + openai_base_url = os.environ.get("OPENAI_BASE_URL") + if openai_base_url: + print("Using OpenAI Base URL from environment variable") if not openai_api_key: print("OpenAI API key not found") @@ -83,6 +90,11 @@ async def stream_code_test(websocket: WebSocket): } ) return + # openai_base_url="https://flag.smarttrot.com/v1" + if not openai_base_url: + openai_base_url = None + print("Using Offical OpenAI Base URL") + should_generate_images = ( params["isImageGenerationEnabled"] @@ -117,6 +129,7 @@ async def stream_code_test(websocket: WebSocket): completion = await stream_openai_response( prompt_messages, api_key=openai_api_key, + base_url = openai_base_url, callback=lambda x: process_chunk(x), ) @@ -129,7 +142,7 @@ async def stream_code_test(websocket: WebSocket): {"type": "status", "value": "Generating images..."} ) updated_html = await generate_images( - completion, api_key=openai_api_key, image_cache=image_cache + completion, api_key=openai_api_key, base_url=openai_base_url, image_cache=image_cache ) else: updated_html = completion diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c2ec3fe..7e89041 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -37,6 +37,7 @@ function App() { const [settings, setSettings] = usePersistedState( { openAiApiKey: null, + openAiBaseURL: null, screenshotOneApiKey: null, isImageGenerationEnabled: true, editorTheme: "cobalt", diff --git a/frontend/src/components/SettingsDialog.tsx b/frontend/src/components/SettingsDialog.tsx index f7004d3..411dad0 100644 --- a/frontend/src/components/SettingsDialog.tsx +++ b/frontend/src/components/SettingsDialog.tsx @@ -76,6 +76,25 @@ function SettingsDialog({ settings, setSettings }: Props) { } /> + + + + setSettings((s) => ({ + ...s, + openAiBaseURL: e.target.value, + })) + } + /> +