Skip to content

Commit 84fdfda

Browse files
rushilpatel0github-actions[bot]
authored andcommitted
Automated pre-commit update
1 parent 7776b56 commit 84fdfda

32 files changed

+1398
-2851
lines changed

src/codegen/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from codegen.agents.agent import Agent
12
from codegen.cli.sdk.decorator import function
23
from codegen.cli.sdk.functions import Function
34
from codegen.extensions.events.codegen_app import CodegenApp
45
from codegen.sdk.core.codebase import Codebase
56
from codegen.shared.enums.programming_language import ProgrammingLanguage
6-
from codegen.agents.agent import Agent
77

88
__all__ = ["Agent", "Codebase", "CodegenApp", "Function", "ProgrammingLanguage", "function"]

src/codegen/agents/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from codegen.agents.agent import Agent
2121
agent = Agent(
2222
org_id="11", # Your organization ID
2323
token="your_api_token_here", # Your API authentication token
24-
base_url="https://codegen-sh-rest-api.modal.run" # Optional - defaults to this URL
24+
base_url="https://codegen-sh-rest-api.modal.run", # Optional - defaults to this URL
2525
)
2626

2727
# Run an agent with a prompt
@@ -50,6 +50,7 @@ Agent(token: str, org_id: Optional[int] = None, base_url: Optional[str] = CODEGE
5050
```
5151

5252
Parameters:
53+
5354
- `token` (required): Your API authentication token
5455
- `org_id` (optional): Your organization ID. If not provided, defaults to environment variable `CODEGEN_ORG_ID` or "1"
5556
- `base_url` (optional): API base URL. Defaults to "https://codegen-sh-rest-api.modal.run"
@@ -65,9 +66,11 @@ run(prompt: str) -> AgentTask
6566
Runs an agent with the given prompt.
6667

6768
Parameters:
69+
6870
- `prompt` (required): The instruction for the agent to execute
6971

7072
Returns:
73+
7174
- An `AgentTask` object representing the running task
7275

7376
#### get_status()
@@ -79,6 +82,7 @@ get_status() -> Optional[Dict[str, Any]]
7982
Gets the status of the current task.
8083

8184
Returns:
85+
8286
- A dictionary containing task status information (`id`, `status`, `result`), or `None` if no task has been run
8387

8488
### AgentTask Class

src/codegen/agents/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
Codegen Agent API module.
3-
"""
1+
"""Codegen Agent API module."""
2+
43
from codegen.agents.agent import Agent
54

6-
__all__ = ["Agent"]
5+
__all__ = ["Agent"]

src/codegen/agents/agent.py

+25-38
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from typing import Optional, Dict, Any
21
import os
2+
from typing import Any, Optional
33

44
from codegen.agents.client.openapi_client.api.agents_api import AgentsApi
55
from codegen.agents.client.openapi_client.api_client import ApiClient
6+
from codegen.agents.client.openapi_client.configuration import Configuration
67
from codegen.agents.client.openapi_client.models.agent_run_response import AgentRunResponse
78
from codegen.agents.client.openapi_client.models.create_agent_run_input import CreateAgentRunInput
8-
from codegen.agents.client.openapi_client.configuration import Configuration
99
from codegen.agents.constants import CODEGEN_BASE_API_URL
1010

1111

1212
class AgentTask:
1313
"""Represents an agent run job."""
14-
14+
1515
def __init__(self, task_data: AgentRunResponse, api_client: ApiClient, org_id: int):
1616
self.id = task_data.id
1717
self.org_id = org_id
@@ -20,88 +20,75 @@ def __init__(self, task_data: AgentRunResponse, api_client: ApiClient, org_id: i
2020
self.web_url = task_data.web_url
2121
self._api_client = api_client
2222
self._agents_api = AgentsApi(api_client)
23-
23+
2424
def refresh(self) -> None:
2525
"""Refresh the job status from the API."""
2626
if self.id is None:
2727
return
28-
28+
2929
job_data = self._agents_api.get_agent_run_v1_organizations_org_id_agent_run_agent_run_id_get(
30-
agent_run_id=int(self.id),
31-
org_id=int(self.org_id),
32-
authorization=f"Bearer {self._api_client.configuration.access_token}"
30+
agent_run_id=int(self.id), org_id=int(self.org_id), authorization=f"Bearer {self._api_client.configuration.access_token}"
3331
)
34-
32+
3533
# Convert API response to dict for attribute access
3634
job_dict = {}
37-
if hasattr(job_data, '__dict__'):
35+
if hasattr(job_data, "__dict__"):
3836
job_dict = job_data.__dict__
3937
elif isinstance(job_data, dict):
4038
job_dict = job_data
41-
39+
4240
self.status = job_dict.get("status")
4341
self.result = job_dict.get("result")
4442

4543

4644
class Agent:
4745
"""API client for interacting with Codegen AI agents."""
48-
46+
4947
def __init__(self, token: str, org_id: Optional[int] = None, base_url: Optional[str] = CODEGEN_BASE_API_URL):
50-
"""
51-
Initialize a new Agent client.
52-
48+
"""Initialize a new Agent client.
49+
5350
Args:
5451
token: API authentication token
5552
org_id: Optional organization ID. If not provided, default org will be used.
5653
"""
5754
self.token = token
5855
self.org_id = org_id or int(os.environ.get("CODEGEN_ORG_ID", "1")) # Default to org ID 1 if not specified
59-
56+
6057
# Configure API client
6158
config = Configuration(host=base_url, access_token=token)
6259
self.api_client = ApiClient(configuration=config)
6360
self.agents_api = AgentsApi(self.api_client)
64-
61+
6562
# Current job
6663
self.current_job = None
67-
64+
6865
def run(self, prompt: str) -> AgentTask:
69-
"""
70-
Run an agent with the given prompt.
71-
66+
"""Run an agent with the given prompt.
67+
7268
Args:
7369
prompt: The instruction for the agent to execute
74-
70+
7571
Returns:
7672
Job: A job object representing the agent run
7773
"""
7874
run_input = CreateAgentRunInput(prompt=prompt)
7975
agent_run_response = self.agents_api.create_agent_run_v1_organizations_org_id_agent_run_post(
80-
org_id=int(self.org_id),
81-
create_agent_run_input=run_input,
82-
authorization=f"Bearer {self.token}",
83-
_headers={"Content-Type": "application/json"}
76+
org_id=int(self.org_id), create_agent_run_input=run_input, authorization=f"Bearer {self.token}", _headers={"Content-Type": "application/json"}
8477
)
8578
# Convert API response to dict for Job initialization
86-
79+
8780
job = AgentTask(agent_run_response, self.api_client, self.org_id)
8881
self.current_job = job
8982
return job
90-
91-
def get_status(self) -> Optional[Dict[str, Any]]:
92-
"""
93-
Get the status of the current job.
94-
83+
84+
def get_status(self) -> Optional[dict[str, Any]]:
85+
"""Get the status of the current job.
86+
9587
Returns:
9688
dict: A dictionary containing job status information,
9789
or None if no job has been run.
9890
"""
9991
if self.current_job:
10092
self.current_job.refresh()
101-
return {
102-
"id": self.current_job.id,
103-
"status": self.current_job.status,
104-
"result": self.current_job.result,
105-
"web_url": self.current_job.web_url
106-
}
93+
return {"id": self.current_job.id, "status": self.current_job.status, "result": self.current_job.result, "web_url": self.current_job.web_url}
10794
return None

src/codegen/agents/client/README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# openapi-client
2+
23
API for application developers
34

45
This Python directory was automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project. However it the generated code was altered to make compatible with the rest of the project.
56

67
- API version: 1.0.0
78

8-
9-
109
### Steps to update client directory
1110

12-
1. Fetch the api schema from the API endpoint [https://codegen-sh--rest-api.modal.run/api/openapi.json](schema file)
13-
2. generate the client code with the following command:
11+
1. Fetch the api schema from the API endpoint \[https://codegen-sh--rest-api.modal.run/api/openapi.json\](schema file)
12+
1. generate the client code with the following command:
1413

1514
```bash
1615
openapi-generator generate -i openapi.yaml -g python -o ./client
1716
```
18-
3. This command will generate a lot of unused files we just need to include the files in the `openapi_client` directory to the project.
19-
20-
4. May need to fix the imports for `openapi_client` to be fully qualified import paths.
2117

18+
3. This command will generate a lot of unused files we just need to include the files in the `openapi_client` directory to the project.
2219

23-
5. TODO: make updates more streamlined. Ideally setup this api client as it's own package so all it takes is to generate the new code, no addtional manual steps are needed.
20+
1. May need to fix the imports for `openapi_client` to be fully qualified import paths.
2421

22+
1. TODO: make updates more streamlined. Ideally setup this api client as it's own package so all it takes is to generate the new code, no addtional manual steps are needed.

src/codegen/agents/client/openapi_client/__init__.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
# flake8: noqa
44

55
"""
6-
Developer API
6+
Developer API
77
8-
API for application developers
8+
API for application developers
99
10-
The version of the OpenAPI document: 1.0.0
11-
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
The version of the OpenAPI document: 1.0.0
11+
Generated by OpenAPI Generator (https://openapi-generator.tech)
1212
13-
Do not edit the class manually.
13+
Do not edit the class manually.
1414
""" # noqa: E501
1515

16-
1716
__version__ = "1.0.0"
1817

1918
# import apis into sdk package

src/codegen/agents/client/openapi_client/api/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
from codegen.agents.client.openapi_client.api.agents_api import AgentsApi
55
from codegen.agents.client.openapi_client.api.organizations_api import OrganizationsApi
66
from codegen.agents.client.openapi_client.api.users_api import UsersApi
7-

0 commit comments

Comments
 (0)