-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into tom-cg-10888-wildcard-resolution-fix
- Loading branch information
Showing
59 changed files
with
3,108 additions
and
1,219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
TESTS_TO_RUN=$(uv run --frozen pytest --collect-only ${PYTEST_ARGS} -q --disable-warnings --no-summary --no-header) | ||
TESTS_TO_RUN=$(echo "${TESTS_TO_RUN}" | head -n -2) | ||
echo $TESTS_TO_RUN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ jobs: | |
with: | ||
fetch-depth: 0 | ||
ref: ${{ inputs.release-tag || github.event.pull_request.head.ref || github.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }} | ||
|
||
- name: Install UV | ||
uses: astral-sh/[email protected] | ||
|
@@ -64,6 +65,7 @@ jobs: | |
cache-suffix: 3.${{ matrix.python }} | ||
|
||
- name: Fetch tags | ||
if: ${{ inputs.release-tag || startsWith(github.ref, 'refs/tags/') }} | ||
run: | | ||
git branch | ||
git fetch --depth=1 origin +refs/tags/*:refs/tags/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim | ||
|
||
# Set environment variables to prevent interactive prompts during installation | ||
ENV NVM_DIR=/root/.nvm \ | ||
NODE_VERSION=18.17.0 \ | ||
DEBIAN_FRONTEND=noninteractive \ | ||
NODE_OPTIONS="--max-old-space-size=8192" \ | ||
PYTHONUNBUFFERED=1 \ | ||
COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \ | ||
PYTHONPATH="/usr/local/lib/python3.13/site-packages" \ | ||
IS_SANDBOX=True \ | ||
HATCH_BUILD_HOOKS_ENABLE=1 | ||
|
||
# Update packages lists and install git and curl | ||
RUN apt-get update && apt-get install -y \ | ||
git \ | ||
curl \ | ||
gcc \ | ||
build-essential \ | ||
python3-dev \ | ||
# Cleanup apt cache to reduce image size | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install nvm and Node.js | ||
SHELL ["/bin/bash", "-c"] | ||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \ | ||
&& source $NVM_DIR/nvm.sh \ | ||
&& nvm install $NODE_VERSION \ | ||
&& nvm use default \ | ||
&& npm install -g yarn pnpm \ | ||
&& corepack enable \ | ||
&& corepack prepare yarn@stable --activate \ | ||
&& corepack prepare pnpm@latest --activate \ | ||
&& uv pip install --system uvicorn[standard] | ||
|
||
# Add node and npm to PATH | ||
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH | ||
RUN node --version \ | ||
&& corepack --version \ | ||
&& npm --version \ | ||
&& yarn --version \ | ||
&& pnpm --version \ | ||
&& python --version | ||
|
||
# Build codegen | ||
WORKDIR /codegen-sdk | ||
COPY . . | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv venv && source .venv/bin/activate \ | ||
&& uv sync --frozen --no-dev --all-extras \ | ||
&& uv pip install --system -e . --no-deps \ | ||
&& uv pip install --system . | ||
RUN codegen --version | ||
|
||
# Create a non-root user for local development + debugging | ||
RUN useradd -m -s /bin/bash user | ||
USER root | ||
RUN chown -R user:user /home/user | ||
USER user | ||
|
||
WORKDIR /app | ||
ENTRYPOINT ["/bin/bash", "-c"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Codegen App | ||
|
||
Simple example of running a codegen app. | ||
|
||
## Run Locally | ||
|
||
Spin up the server: | ||
|
||
``` | ||
codegen serve | ||
``` | ||
|
||
Spin up ngrok | ||
|
||
``` | ||
ngrok http 8000 | ||
``` | ||
|
||
Go to Slack [app settings](https://api.slack.com/apps/A08CR9HUJ3W/event-subscriptions) and set the URL for event subscriptions | ||
|
||
``` | ||
{ngrok_url}/slack/events | ||
``` | ||
|
||
## Deploy to Modal | ||
|
||
This will deploy it as a function | ||
|
||
``` | ||
modal deploy app.py | ||
``` | ||
|
||
Then you can swap in the modal URL for slack etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import logging | ||
|
||
import modal | ||
from codegen import CodeAgent, CodegenApp | ||
from codegen.extensions.github.types.events.pull_request import PullRequestLabeledEvent | ||
from codegen.extensions.linear.types import LinearEvent | ||
from codegen.extensions.slack.types import SlackEvent | ||
from codegen.extensions.tools.github.create_pr_comment import create_pr_comment | ||
|
||
# Set up logging | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
######################################################################################################################## | ||
# EVENTS | ||
######################################################################################################################## | ||
|
||
# Create the cg_app | ||
cg = CodegenApp(name="codegen-test", repos=["codegen-sh/Kevin-s-Adventure-Game"]) | ||
|
||
|
||
@cg.slack.event("app_mention") | ||
async def handle_mention(event: SlackEvent): | ||
logger.info("[APP_MENTION] Received cg_app_mention event") | ||
logger.info(event) | ||
|
||
# Codebase | ||
logger.info("[CODEBASE] Initializing codebase") | ||
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game") | ||
|
||
# Code Agent | ||
logger.info("[CODE_AGENT] Initializing code agent") | ||
agent = CodeAgent(codebase=codebase) | ||
|
||
logger.info("[CODE_AGENT] Running code agent") | ||
response = agent.run(event.text) | ||
|
||
cg.slack.client.chat_postMessage(channel=event.channel, text=response, thread_ts=event.ts) | ||
return {"message": "Mentioned", "received_text": event.text, "response": response} | ||
|
||
|
||
@cg.github.event("pull_request:labeled") | ||
def handle_pr(event: PullRequestLabeledEvent): | ||
logger.info("PR labeled") | ||
logger.info(f"PR head sha: {event.pull_request.head.sha}") | ||
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game") | ||
|
||
# =====[ Check out commit ]===== | ||
# Might require fetch? | ||
logger.info("> Checking out commit") | ||
codebase.checkout(commit=event.pull_request.head.sha) | ||
|
||
logger.info("> Getting files") | ||
file = codebase.get_file("README.md") | ||
|
||
# =====[ Create PR comment ]===== | ||
create_pr_comment(codebase, event.pull_request.number, f"File content:\n```python\n{file.content}\n```") | ||
|
||
return {"message": "PR event handled", "num_files": len(codebase.files), "num_functions": len(codebase.functions)} | ||
|
||
|
||
@cg.linear.event("Issue") | ||
def handle_issue(event: LinearEvent): | ||
logger.info(f"Issue created: {event}") | ||
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game") | ||
return {"message": "Linear Issue event", "num_files": len(codebase.files), "num_functions": len(codebase.functions)} | ||
|
||
|
||
######################################################################################################################## | ||
# MODAL DEPLOYMENT | ||
######################################################################################################################## | ||
# This deploys the FastAPI app to Modal | ||
# TODO: link this up with memory snapshotting. | ||
|
||
# For deploying local package | ||
REPO_URL = "https://github.com/codegen-sh/codegen-sdk.git" | ||
COMMIT_ID = "26dafad2c319968e14b90806d42c6c7aaa627bb0" | ||
|
||
# Create the base image with dependencies | ||
base_image = ( | ||
modal.Image.debian_slim(python_version="3.13") | ||
.apt_install("git") | ||
.pip_install( | ||
# =====[ Codegen ]===== | ||
# "codegen", | ||
f"git+{REPO_URL}@{COMMIT_ID}", | ||
# =====[ Rest ]===== | ||
"openai>=1.1.0", | ||
"fastapi[standard]", | ||
"slack_sdk", | ||
) | ||
) | ||
|
||
app = modal.App("codegen-test") | ||
|
||
|
||
@app.function(image=base_image, secrets=[modal.Secret.from_dotenv()]) | ||
@modal.asgi_app() | ||
def fastapi_app(): | ||
return cg.app |
Oops, something went wrong.