Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API via e2b SDK #123

Merged
merged 2 commits into from
Jul 26, 2023
Merged

Add API via e2b SDK #123

merged 2 commits into from
Jul 26, 2023

Conversation

jakubno
Copy link
Contributor

@jakubno jakubno commented Jul 23, 2023

API mode

This PR adds an API to the smol_developer by using the e2b agent protocol SDK that implements the Agent Communication Protocol.

Here is a short preview how to use the API that I also added to the README

To start the server run:

python smol_dev/api.py

and then you can call the API using the following commands:

To create a task run:

curl --request POST \
  --url http://localhost:8000/agent/tasks \
  --header 'Content-Type: application/json' \
  --data '{
	"input": "Write simple script in Python. It should write '\''Hello world!'\'' to hi.txt"
}'

You will get a response like this:

{"input":"Write simple script in Python. It should write 'Hello world!' to hi.txt","task_id":"e6d768bb-4c50-4007-9853-aeffb46c77be","artifacts":[]}

Then to execute one step of the task copy the task_id you got from the previous request and run:

curl --request POST \
  --url http://localhost:8000/agent/tasks/<task-id>/steps

or you can use Python client library:

from agent_protocol_client import AgentApi, ApiClient, TaskRequestBody

... 

prompt = "Write simple script in Python. It should write 'Hello world!' to hi.txt"

async with ApiClient() as api_client:
    # Create an instance of the API class
    api_instance = AgentApi(api_client)
    task_request_body = TaskRequestBody(input=prompt)

    task = await api_instance.create_agent_task(
        task_request_body=task_request_body
    )
    task_id = task.task_id
    response = await api_instance.execute_agent_task_step(task_id=task_id)

...

@swyxio swyxio merged commit 91b3ab3 into smol-ai:main Jul 26, 2023
@jakubno jakubno deleted the api-mode branch August 9, 2023 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants