Skip to content

Commit 05756d0

Browse files
rushilpatel0github-actions[bot]
authored andcommitted
Automated pre-commit update
1 parent bd89500 commit 05756d0

27 files changed

+1216
-2603
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/__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

+26-38
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,94 @@
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
1818
self.status = task_data.status
1919
self.result = task_data.result
2020
self._api_client = api_client
2121
self._agents_api = AgentsApi(api_client)
22-
22+
2323
def refresh(self) -> None:
2424
"""Refresh the job status from the API."""
2525
if self.id is None:
2626
return
27-
27+
2828
job_data = self._agents_api.get_agent_run_v1_organizations_org_id_agent_run_agent_run_id_get(
29-
agent_run_id=int(self.id),
30-
org_id=int(self.org_id),
31-
authorization=f"Bearer {self._api_client.configuration.access_token}"
29+
agent_run_id=int(self.id), org_id=int(self.org_id), authorization=f"Bearer {self._api_client.configuration.access_token}"
3230
)
33-
31+
3432
# Convert API response to dict for attribute access
3533
job_dict = {}
36-
if hasattr(job_data, '__dict__'):
34+
if hasattr(job_data, "__dict__"):
3735
job_dict = job_data.__dict__
3836
elif isinstance(job_data, dict):
3937
job_dict = job_data
40-
38+
4139
self.status = job_dict.get("status")
4240
self.result = job_dict.get("result")
4341

4442

4543
class Agent:
4644
"""API client for interacting with Codegen AI agents."""
47-
45+
4846
def __init__(self, token: str, org_id: Optional[int] = None, base_url: Optional[str] = CODEGEN_BASE_API_URL):
49-
"""
50-
Initialize a new Agent client.
51-
47+
"""Initialize a new Agent client.
48+
5249
Args:
5350
token: API authentication token
5451
org_id: Optional organization ID. If not provided, default org will be used.
5552
"""
5653
self.token = token
5754
self.org_id = org_id or int(os.environ.get("CODEGEN_ORG_ID", "1")) # Default to org ID 1 if not specified
58-
55+
5956
# Configure API client
6057
config = Configuration(host=base_url, access_token=token)
6158
self.api_client = ApiClient(configuration=config)
6259
self.agents_api = AgentsApi(self.api_client)
63-
60+
6461
# Current job
6562
self.current_job = None
66-
63+
6764
def run(self, prompt: str) -> AgentTask:
68-
"""
69-
Run an agent with the given prompt.
70-
65+
"""Run an agent with the given prompt.
66+
7167
Args:
7268
prompt: The instruction for the agent to execute
73-
69+
7470
Returns:
7571
Job: A job object representing the agent run
7672
"""
7773
run_input = CreateAgentRunInput(prompt=prompt)
7874
agent_run_response = self.agents_api.create_agent_run_v1_organizations_org_id_agent_run_post(
79-
org_id=int(self.org_id),
80-
create_agent_run_input=run_input,
81-
authorization=f"Bearer {self.token}",
82-
_headers={"Content-Type": "application/json"}
75+
org_id=int(self.org_id), create_agent_run_input=run_input, authorization=f"Bearer {self.token}", _headers={"Content-Type": "application/json"}
8376
)
84-
77+
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-
}
93+
return {"id": self.current_job.id, "status": self.current_job.status, "result": self.current_job.result}
10694
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)