Skip to content

Commit a861c7e

Browse files
committed
Merge branch 'develop' of https://github.com/codegen-sh/codegen-sdk into daemon-run
2 parents 45a9682 + 77150a8 commit a861c7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2747
-1139
lines changed

.codegen/.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ jupyter/
88
codegen-system-prompt.txt
99

1010
# Python cache files
11-
__pycache__/
11+
**/__pycache__/
1212
*.py[cod]
1313
*$py.class
1414
*.txt
1515
*.pyc
16-
17-
# Keep codemods
18-
!codemods/
19-
!codemods/**

.codegen/codemods/no_link_backticks/no_link_backticks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from codegen import Codebase
33

44

5-
@codegen.function("no-link-backticks")
5+
@codegen.function(name="no-link-backticks", subdirectories=["test/unit"])
66
def run(codebase: Codebase):
77
import re
88

@@ -12,6 +12,7 @@ def run(codebase: Codebase):
1212
# Iterate over all .mdx files in the codebase
1313
for file in codebase.files(extensions=["mdx"]):
1414
if file.extension == ".mdx":
15+
print(f"Processing {file.path}")
1516
new_content = file.content
1617

1718
# Find all markdown links with backticks in link text

.github/workflows/auto-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
- uses: actions/checkout@v4
4848
with:
4949
fetch-depth: 0
50+
token: ${{ secrets.GHA_TOKEN }}
5051

5152
- name: Setup backend
5253
uses: ./.github/actions/setup-environment
@@ -66,7 +67,6 @@ jobs:
6667
- name: Push changes
6768
uses: ad-m/github-push-action@master
6869
with:
69-
github_token: ${{ secrets.GHA_TOKEN }}
7070
branch: ${{ github.ref }}
7171

7272
release:

.github/workflows/generate-docs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ jobs:
1616
- uses: actions/checkout@v4
1717
with:
1818
fetch-depth: 0
19+
token: ${{ secrets.GHA_TOKEN }}
1920

2021
- name: Setup backend
2122
uses: ./.github/actions/setup-environment
2223

2324
- name: Generate API reference
2425
run: uv run python src/codegen/gscli/cli.py generate docs
2526

27+
- name: Generate System Prompt
28+
run: uv run python src/codegen/gscli/cli.py generate system-prompt
29+
2630
- name: Commit changes
2731
run: |
28-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
29-
git config --local user.name "github-actions[bot]"
30-
git add docs/
32+
git config --local user.email ${{ secrets.DOCS_USER_EMAIL }}
33+
git config --local user.name ${{ secrets.DOCS_USER_NAME }}
34+
git add docs/ src/codegen/sdk/system-prompt.txt
3135
git diff --staged --quiet || git commit -m "docs: updated API reference"
3236
3337
- name: Push changes
3438
uses: ad-m/github-push-action@master
3539
with:
36-
github_token: ${{ secrets.GHA_TOKEN }}
3740
branch: ${{ github.ref }}

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
unit-tests:
2424
needs: access-check
2525
runs-on: ubuntu-latest-8
26-
environment: testing
2726
steps:
2827
- uses: actions/checkout@v4
2928
with:
@@ -48,7 +47,6 @@ jobs:
4847
# TODO: re-enable when this check is a develop required check
4948
if: false
5049
runs-on: ubuntu-latest-32
51-
environment: testing
5250
strategy:
5351
matrix:
5452
sync_graph: [ true, false ]
@@ -90,7 +88,6 @@ jobs:
9088
needs: access-check
9189
if: contains(github.event.pull_request.labels.*.name, 'parse-tests') || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
9290
runs-on: ubuntu-latest-32
93-
environment: testing
9491
steps:
9592
- uses: actions/checkout@v4
9693
with:
@@ -161,7 +158,6 @@ jobs:
161158
integration-tests:
162159
needs: access-check
163160
runs-on: ubuntu-latest-16
164-
environment: testing
165161
steps:
166162
- uses: actions/checkout@v4
167163
with:

codegen-examples/examples/swebench_agent_run/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ OPENAI_API_KEY= # Your OpenAI API key
22
ANTHROPIC_API_KEY= # Your Anthropic API key
33
LANGSMITH_API_KEY= # Your Langsmith API key
44
LANGCHAIN_TRACING_V2= # `true` for tracing, `false` for no tracing
5+
LANGCHAIN_PROJECT= # Your Langchain project
6+
RELACE_API= # Your Relace API key

codegen-examples/examples/swebench_agent_run/entry_point.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from codegen.extensions.swebench.utils import SweBenchExample
22
from codegen.extensions.swebench.harness import run_agent_on_entry
33
import modal
4+
import sys
5+
from codegen.sdk.core.codebase import Codebase
46

57
image = (
68
modal.Image.debian_slim(python_version="3.13")
7-
.apt_install("git")
9+
.apt_install(["git", "ripgrep"])
810
.pip_install("fastapi[standard]")
911
.copy_local_dir("../../../", "/root/codegen", ignore=[".venv", "**/.venv", "tests", "**/tests"])
1012
.run_commands("pip install -e /root/codegen")
@@ -17,3 +19,22 @@
1719
async def run_agent_modal(entry: SweBenchExample):
1820
"""Modal function to process a single example from the SWE-bench dataset."""
1921
return run_agent_on_entry(entry)
22+
23+
24+
@app.cls(image=image, secrets=[modal.Secret.from_dotenv()], enable_memory_snapshot=True)
25+
class SwebenchAgentRun:
26+
repo_full_name: str = modal.parameter()
27+
commit: str = modal.parameter()
28+
codebase: Codebase | None = None
29+
30+
@modal.enter(snap=True)
31+
def load(self):
32+
self.codebase = Codebase.from_repo(repo_full_name=self.repo_full_name, commit=self.commit, language="python")
33+
34+
@modal.exit()
35+
def exit(self):
36+
sys.exit(0)
37+
38+
@modal.method()
39+
async def run(self, entry: SweBenchExample):
40+
return run_agent_on_entry(entry, codebase=self.codebase)

codegen-examples/examples/swebench_agent_run/run_eval.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import modal
77
import click
88
from datetime import datetime
9-
from codegen.extensions.swebench.utils import SWEBenchDataset, get_swe_bench_example, get_swe_bench_examples
9+
from codegen.extensions.swebench.utils import SWEBenchDataset, SweBenchExample, get_swe_bench_examples
1010
from codegen.extensions.swebench.report import generate_report
1111

1212
PREDS_DNAME = Path(__file__).parent / "predictions"
1313
LOG_DIR = Path(__file__).parent / "logs"
1414

15-
run_agent_modal = modal.Function.lookup("swebench-agent-run", "run_agent_modal")
15+
SwebenchAgentRun = modal.Cls.from_name(app_name="swebench-agent-run", name="SwebenchAgentRun")
1616

1717

18-
async def process_batch(examples, batch_size=10):
18+
async def process_batch(examples: list[SweBenchExample], batch_size=10):
1919
"""Process a batch of examples concurrently.
2020
2121
Args:
@@ -31,7 +31,7 @@ async def process_batch(examples, batch_size=10):
3131
batch = examples[i : i + batch_size]
3232

3333
# Create tasks for this batch
34-
batch_tasks = [run_agent_modal.remote.aio(example) for example in batch]
34+
batch_tasks = [SwebenchAgentRun(repo_full_name=example.repo, commit=example.base_commit).run.remote.aio(example) for example in batch]
3535

3636
# Wait for all tasks in this batch to complete
3737
print(f"Processing batch {i // batch_size + 1}/{len(examples) // batch_size + 1} (examples {i + 1}-{min(i + batch_size, len(examples))})")
@@ -92,10 +92,7 @@ async def run_eval(use_existing_preds: str | None, dataset: str, length: int, in
9292
run_id = use_existing_preds or str(uuid.uuid4())
9393
predictions_dir = PREDS_DNAME / f"results_{run_id}"
9494
dataset = SWEBenchDataset(dataset)
95-
if instance_id:
96-
examples = [get_swe_bench_example(instance_id, dataset=dataset)]
97-
else:
98-
examples = get_swe_bench_examples(dataset=dataset, length=length)
95+
examples = get_swe_bench_examples(dataset=dataset, length=length, instance_id=instance_id)
9996

10097
try:
10198
if use_existing_preds is None:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from codegen import Codebase
2+
import modal
3+
4+
image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]").run_commands("pip install codegen")
5+
6+
app = modal.App(name="codegen-examples", image=image, secrets=[modal.Secret.from_dotenv()])
7+
8+
9+
@app.function()
10+
def run_agent(AgentClass):
11+
codebase = Codebase.from_repo(repo_full_name="pallets/flask")
12+
agent = AgentClass(codebase)
13+
agent.run(prompt="Tell me about the codebase and the files in it.")
14+
return True

docs/api-reference/core/Class.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L53-L417" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L55-L419" />
1515

1616
### Inherits from
1717
[HasBlock](/api-reference/core/HasBlock), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName)
@@ -147,7 +147,7 @@ import {Attribute} from '/snippets/Attribute.mdx';
147147
<HorizontalDivider />
148148
### <span className="text-primary">add_attribute</span>
149149
Adds an attribute to a class from another class.
150-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L358-L381" />
150+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L360-L383" />
151151

152152
<ParameterWrapper>
153153
<Parameter
@@ -170,7 +170,7 @@ Adds an attribute to a class from another class.
170170

171171
### <span className="text-primary">add_attribute_from_source</span>
172172
Adds an attribute to a class from raw source code, placing it in a specific location
173-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L332-L355" />
173+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L334-L357" />
174174

175175
<ParameterWrapper>
176176
<Parameter
@@ -244,7 +244,7 @@ Insert a keyword in the appropriate place before this symbol if it doesn't alrea
244244

245245
### <span className="text-primary">add_source</span>
246246
Add a block of source code to the bottom of a class definition.
247-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L318-L329" />
247+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L320-L331" />
248248

249249
<ParameterWrapper>
250250
<Parameter
@@ -269,7 +269,7 @@ Find all ancestors of the node of the given type. Does not return itself
269269

270270
### <span className="text-primary">attributes</span>
271271
Retrieves all attributes from this Class including those from its superclasses up to a
272-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L272-L291" />
272+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L274-L293" />
273273

274274
<ParameterWrapper>
275275
<Parameter
@@ -404,7 +404,7 @@ Adds a visual flag comment to the end of this Editable's source text.
404404

405405
### <span className="text-primary">get_attribute</span>
406406
Returns a specific attribute by name.
407-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L294-L311" />
407+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L296-L313" />
408408

409409
<ParameterWrapper>
410410
<Parameter
@@ -421,7 +421,7 @@ Returns a specific attribute by name.
421421

422422
### <span className="text-primary">get_method</span>
423423
Returns a specific method by name from the class or any of its superclasses.
424-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L251-L268" />
424+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L253-L270" />
425425

426426
<ParameterWrapper>
427427
<Parameter
@@ -446,7 +446,7 @@ Returns the name node of the object.
446446

447447
### <span className="text-primary">get_nested_class</span>
448448
Returns a nested class by name from the current class.
449-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L234-L248" />
449+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L236-L250" />
450450

451451
<ParameterWrapper>
452452
<Parameter
@@ -514,7 +514,7 @@ Retrieves a parameter from the callable by its type.
514514

515515
### <span className="text-primary">get_parent_class</span>
516516
Returns the parent class node with the specified name.
517-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L111-L123" />
517+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L113-L125" />
518518

519519
<ParameterWrapper>
520520
<Parameter
@@ -642,7 +642,7 @@ Inserts text before the current symbol node in the Abstract Syntax Tree.
642642

643643
### <span className="text-primary">is_subclass_of</span>
644644
Checks if the class inherits from a specified parent class.
645-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L138-L152" />
645+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L140-L154" />
646646

647647
<ParameterWrapper>
648648
<Parameter
@@ -673,7 +673,7 @@ Check if this node is contained another node of the given class
673673

674674
### <span className="text-primary">methods</span>
675675
Retrieves all methods that exist on this Class, including methods from superclasses, with
676-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L203-L231" />
676+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L205-L233" />
677677

678678
<ParameterWrapper>
679679
<Parameter
@@ -937,7 +937,7 @@ Sets the name of a code element.
937937

938938
### <span className="text-primary">subclasses</span>
939939
Returns all classes which subclass this class.
940-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L156-L167" />
940+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L158-L169" />
941941

942942
<ParameterWrapper>
943943
<Parameter
@@ -954,7 +954,7 @@ Returns all classes which subclass this class.
954954

955955
### <span className="text-primary">superclasses</span>
956956
Returns a list of all classes that this class extends, up to max_depth.
957-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L77-L93" />
957+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/class_definition.py#L79-L95" />
958958

959959
<ParameterWrapper>
960960
<Parameter

0 commit comments

Comments
 (0)