Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add ask human tool [WIP]

Tomas Valenta811e97fc4059
diff --git a/api-service/app.py b/api-service/app.py
index 7a4925b64..0e6cf051f 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -65,8 +65,6 @@ def generate():
playground_tools=playground_tools,
database=db,
run_id=run_id,
- project_id=project_id,
- route_id=route_id,
playground=playground,
)
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index 3f46c3849..e5e14f809 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -86,8 +86,6 @@ class Codegen(BaseModel):
playground_tools: List[BaseTool],
database: Database,
run_id: str,
- project_id,
- route_id: str,
playground: NodeJSPlayground,
):
callback_manager = CallbackManager(
@@ -106,15 +104,13 @@ class Codegen(BaseModel):
# InvalidTool(),
# OutputFinalCode(),
*playground_tools,
- AskHuman(
- callback_manager=callback_manager,
- run_id=run_id,
- project_id=project_id,
- route_id=route_id,
- playground=playground,
- name="AskHuman",
- description="You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human.",
- ),
+ # AskHuman(
+ # callback_manager=callback_manager,
+ # run_id=run_id,
+ # playground=playground,
+ # name="AskHuman",
+ # description="You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human.",
+ # ),
# WriteCodeToFile(callback_manager=callback_manager),
# DeployCode(callback_manager=callback_manager),
]
diff --git a/api-service/codegen/tools/human/ask.py b/api-service/codegen/tools/human/ask.py
index 0fb68cb1a..4147d7a7f 100644
--- a/api-service/codegen/tools/human/ask.py
+++ b/api-service/codegen/tools/human/ask.py
@@ -1,53 +1,20 @@
-from time import sleep
-
-from langchain.callbacks.base import CallbackManager
from langchain.tools import BaseTool
from session.playground.base import Playground
-from session.session import Session
-
-# {
-# "id": "52b2b157-132f-47c6-be1e-3c203034fdfb",
-# "name": "InstallNPMDependencies",
-# "type": "tool",
-# "input": "\nexpress\n",
-# "output": "All dependencies installed",
-# "start_at": "2023-03-19 23:49:23.079327",
-# "finish_at": "2023-03-19 23:49:26.002323"
-# },
-
class AskHuman(BaseTool):
run_id: str
- route_id: str
- project_id: str
playground: Playground
name = "AskHuman"
description = "You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human."
def _run(self, question: str) -> str:
- # TODO: Save the question to DB (in logs? - should we still use callback manager)
-
print("Asking about")
response = self.playground.api.wait_for_human_response(
run_id=self.run_id,
- project_id=self.project_id,
- route_id=self.route_id,
)
return response.response
- # TODO: Wait until the question is answered -> timeout?
- # TODO: Parse and return the correct output from the logs
-
- # print(question)
- # sleep(60)
- # with open(
- # "/Users/vasekmlejnsky/Developer/ai-api/api-service/codegen/human_input.txt"
- # ) as f:
- # human_input = f.read()
- # print("human_input:", human_input)
- # return human_input
-
async def _arun(self, question: str) -> str:
raise NotImplementedError("AskHuman does not support async")
diff --git a/api-service/database/database.py b/api-service/database/database.py
index d9f1cb9ba..679a2d3cb 100644
--- a/api-service/database/database.py
+++ b/api-service/database/database.py
@@ -28,7 +28,6 @@ class Database:
).execute()
def push_logs(self, run_id: str, logs: List[Dict[str, str]]) -> None:
- print("LOGS")
if len(logs) > 0:
self.client.table(deploymentsTable).update(
{
@@ -37,7 +36,6 @@ class Database:
).eq("id", run_id).execute()
def push_raw_logs(self, run_id: str, logs_raw: str) -> None:
- print("RAW LOGS")
if logs_raw:
self.client.table(deploymentsTable).update(
{
diff --git a/api-service/playground/src/data/humanResponse.ts b/api-service/playground/src/data/humanResponse.ts
index d8ccd23f7..9e97f31f7 100644
--- a/api-service/playground/src/data/humanResponse.ts
+++ b/api-service/playground/src/data/humanResponse.ts
@@ -51,7 +51,6 @@ export async function waitForHumanResponse({ runID }: { runID: string }) {
resolve('Timeout')
}, 3600000)
-
console.log('runID', runID)
updateSub = client.channel('any-server')
.on('postgres_changes',
diff --git a/api-service/playground/src/data/toolsController.ts b/api-service/playground/src/data/toolsController.ts
index 12ba1a850..b6f7280fb 100644
--- a/api-service/playground/src/data/toolsController.ts
+++ b/api-service/playground/src/data/toolsController.ts
@@ -12,11 +12,9 @@ interface ToolsHumanResponse {
@Route('tools')
export class ToolsController extends Controller {
- @Get()
+ @Get('humanResponse')
public async waitForHumanResponse(
@Query() runID: string,
- @Query() projectID: string,
- @Query() routeID: string,
): Promise<ToolsHumanResponse> {
const response = await waitForHumanResponse({
runID,
diff --git a/api-service/playground/src/generated/routes.ts b/api-service/playground/src/generated/routes.ts
index 5f3ec4c22..694d62599 100644
--- a/api-service/playground/src/generated/routes.ts
+++ b/api-service/playground/src/generated/routes.ts
@@ -193,15 +193,13 @@ export function RegisterRoutes(app: Router) {
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
- app.get('/tools',
+ app.get('/tools/humanResponse',
...(fetchMiddlewares<RequestHandler>(ToolsController)),
...(fetchMiddlewares<RequestHandler>(ToolsController.prototype.waitForHumanResponse)),
function ToolsController_waitForHumanResponse(request: any, response: any, next: any) {
const args = {
runID: {"in":"query","name":"runID","required":true,"dataType":"string"},
- projectID: {"in":"query","name":"projectID","required":true,"dataType":"string"},
- routeID: {"in":"query","name":"routeID","required":true,"dataType":"string"},
};
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
diff --git a/api-service/playground/swagger.json b/api-service/playground/swagger.json
index c051259d4..b59e648c5 100644
--- a/api-service/playground/swagger.json
+++ b/api-service/playground/swagger.json
@@ -312,7 +312,7 @@
}
}
},
- "/tools": {
+ "/tools/humanResponse": {
"get": {
"operationId": "WaitForHumanResponse",
"responses": {
@@ -336,22 +336,6 @@
"schema": {
"type": "string"
}
- },
- {
- "in": "query",
- "name": "projectID",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "in": "query",
- "name": "routeID",
- "required": true,
- "schema": {
- "type": "string"
- }
}
]
}
diff --git a/api-service/playground_client/api/default_api.py b/api-service/playground_client/api/default_api.py
index 6e146b3e8..8763349d8 100644
--- a/api-service/playground_client/api/default_api.py
+++ b/api-service/playground_client/api/default_api.py
@@ -1841,21 +1841,17 @@ class DefaultApi(object):
_request_auth=_params.get('_request_auth'))
@validate_arguments
- def wait_for_human_response(self, run_id : StrictStr, project_id : StrictStr, route_id : StrictStr, **kwargs) -> ToolsHumanResponse: # noqa: E501
+ def wait_for_human_response(self, run_id : StrictStr, **kwargs) -> ToolsHumanResponse: # noqa: E501
"""wait_for_human_response # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
- >>> thread = api.wait_for_human_response(run_id, project_id, route_id, async_req=True)
+ >>> thread = api.wait_for_human_response(run_id, async_req=True)
>>> result = thread.get()
:param run_id: (required)
:type run_id: str
- :param project_id: (required)
- :type project_id: str
- :param route_id: (required)
- :type route_id: str
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
@@ -1872,24 +1868,20 @@ class DefaultApi(object):
:rtype: ToolsHumanResponse
"""
kwargs['_return_http_data_only'] = True
- return self.wait_for_human_response_with_http_info(run_id, project_id, route_id, **kwargs) # noqa: E501
+ return self.wait_for_human_response_with_http_info(run_id, **kwargs) # noqa: E501
@validate_arguments
- def wait_for_human_response_with_http_info(self, run_id : StrictStr, project_id : StrictStr, route_id : StrictStr, **kwargs): # noqa: E501
+ def wait_for_human_response_with_http_info(self, run_id : StrictStr, **kwargs): # noqa: E501
"""wait_for_human_response # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
- >>> thread = api.wait_for_human_response_with_http_info(run_id, project_id, route_id, async_req=True)
+ >>> thread = api.wait_for_human_response_with_http_info(run_id, async_req=True)
>>> result = thread.get()
:param run_id: (required)
:type run_id: str
- :param project_id: (required)
- :type project_id: str
- :param route_id: (required)
- :type route_id: str
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
@@ -1917,9 +1909,7 @@ class DefaultApi(object):
_params = locals()
_all_params = [
- 'run_id',
- 'project_id',
- 'route_id'
+ 'run_id'
]
_all_params.extend(
[
@@ -1952,10 +1942,6 @@ class DefaultApi(object):
_query_params = []
if _params.get('run_id') is not None: # noqa: E501
_query_params.append(('runID', _params['run_id']))
- if _params.get('project_id') is not None: # noqa: E501
- _query_params.append(('projectID', _params['project_id']))
- if _params.get('route_id') is not None: # noqa: E501
- _query_params.append(('routeID', _params['route_id']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
@@ -1979,7 +1965,7 @@ class DefaultApi(object):
}
return self.api_client.call_api(
- '/tools', 'GET',
+ '/tools/humanResponse', 'GET',
_path_params,
_query_params,
_header_params,
diff --git a/api-service/playground_client/docs/DefaultApi.md b/api-service/playground_client/docs/DefaultApi.md
index 6f2295031..5bdb69791 100644
--- a/api-service/playground_client/docs/DefaultApi.md
+++ b/api-service/playground_client/docs/DefaultApi.md
@@ -16,7 +16,7 @@ Method | HTTP request | Description
[**read_filesystem_file**](DefaultApi.md#read_filesystem_file) | **GET** /sessions/{sessionID}/filesystem/file |
[**start_process**](DefaultApi.md#start_process) | **POST** /sessions/{sessionID}/processes |
[**stop_process**](DefaultApi.md#stop_process) | **DELETE** /sessions/{sessionID}/processes/{processID} |
-[**wait_for_human_response**](DefaultApi.md#wait_for_human_response) | **GET** /tools |
+[**wait_for_human_response**](DefaultApi.md#wait_for_human_response) | **GET** /tools/humanResponse |
[**write_filesystem_file**](DefaultApi.md#write_filesystem_file) | **PUT** /sessions/{sessionID}/filesystem/file |
[**write_process_stdin**](DefaultApi.md#write_process_stdin) | **POST** /sessions/{sessionID}/processes/{processID}/stdin |
@@ -772,7 +772,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **wait_for_human_response**
-> ToolsHumanResponse wait_for_human_response(run_id, project_id, route_id)
+> ToolsHumanResponse wait_for_human_response(run_id)
@@ -797,11 +797,9 @@ with playground_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = playground_client.DefaultApi(api_client)
run_id = 'run_id_example' # str |
- project_id = 'project_id_example' # str |
- route_id = 'route_id_example' # str |
try:
- api_response = api_instance.wait_for_human_response(run_id, project_id, route_id)
+ api_response = api_instance.wait_for_human_response(run_id)
print("The response of DefaultApi->wait_for_human_response:\n")
pprint(api_response)
except Exception as e:
@@ -813,8 +811,6 @@ with playground_client.ApiClient(configuration) as api_client:
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**run_id** | **str**| |
- **project_id** | **str**| |
- **route_id** | **str**| |
### Return type
diff --git a/api-service/playground_client_README.md b/api-service/playground_client_README.md
index 0dace1db2..9b5bd20ca 100644
--- a/api-service/playground_client_README.md
+++ b/api-service/playground_client_README.md
@@ -78,7 +78,7 @@ Class | Method | HTTP request | Description
*DefaultApi* | [**read_filesystem_file**](playground_client/docs/DefaultApi.md#read_filesystem_file) | **GET** /sessions/{sessionID}/filesystem/file |
*DefaultApi* | [**start_process**](playground_client/docs/DefaultApi.md#start_process) | **POST** /sessions/{sessionID}/processes |
*DefaultApi* | [**stop_process**](playground_client/docs/DefaultApi.md#stop_process) | **DELETE** /sessions/{sessionID}/processes/{processID} |
-*DefaultApi* | [**wait_for_human_response**](playground_client/docs/DefaultApi.md#wait_for_human_response) | **GET** /tools |
+*DefaultApi* | [**wait_for_human_response**](playground_client/docs/DefaultApi.md#wait_for_human_response) | **GET** /tools/humanResponse |
*DefaultApi* | [**write_filesystem_file**](playground_client/docs/DefaultApi.md#write_filesystem_file) | **PUT** /sessions/{sessionID}/filesystem/file |
*DefaultApi* | [**write_process_stdin**](playground_client/docs/DefaultApi.md#write_process_stdin) | **POST** /sessions/{sessionID}/processes/{processID}/stdin |