futurehouse-client 0.0.3__tar.gz → 0.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/PKG-INFO +48 -81
- futurehouse_client-0.0.5/README.md +154 -0
- futurehouse_client-0.0.5/docs/client_notebook.ipynb +197 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/clients/rest_client.py +1 -1
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client.egg-info/PKG-INFO +48 -81
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client.egg-info/SOURCES.txt +0 -2
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/pyproject.toml +1 -1
- futurehouse_client-0.0.3/README.md +0 -187
- futurehouse_client-0.0.3/docs/client_notebook.ipynb +0 -349
- futurehouse_client-0.0.3/docs/client_notebook.md +0 -116
- futurehouse_client-0.0.3/docs/crow_client_notebook_w_deployment.ipynb +0 -226
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/LICENSE +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/docs/__init__.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/__init__.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/clients/__init__.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/clients/job_client.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/models/__init__.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/models/app.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/models/client.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/models/rest.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/utils/__init__.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client/utils/module_utils.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client.egg-info/dependency_links.txt +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client.egg-info/requires.txt +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/futurehouse_client.egg-info/top_level.txt +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/setup.cfg +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/tests/test_rest.py +0 -0
- {futurehouse_client-0.0.3 → futurehouse_client-0.0.5}/uv.lock +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: futurehouse-client
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
4
4
|
Summary: A client for interacting with endpoints of the FutureHouse service.
|
5
5
|
Author-email: FutureHouse technical staff <hello@futurehouse.org>
|
6
6
|
Classifier: Operating System :: OS Independent
|
@@ -38,101 +38,76 @@ Requires-Dist: setuptools_scm; extra == "dev"
|
|
38
38
|
|
39
39
|
# FutureHouse Platform API Documentation
|
40
40
|
|
41
|
-
Documentation and tutorials for
|
42
|
-
|
43
|
-
> FutureHouse's mascot is the crow. Therefore, some objects are named after the crow as a homage.
|
41
|
+
Documentation and tutorials for futurehouse-client, a client for interacting with endpoints of the FutureHouse platform.
|
44
42
|
|
45
43
|
<!--TOC-->
|
46
44
|
|
47
45
|
- [Installation](#installation)
|
48
46
|
- [Quickstart](#quickstart)
|
49
47
|
- [Functionalities](#functionalities)
|
50
|
-
- [Stages](#stages)
|
51
48
|
- [Authentication](#authentication)
|
52
|
-
- [
|
53
|
-
- [
|
54
|
-
- [
|
49
|
+
- [Task submission](#task-submission)
|
50
|
+
- [Task Continuation](#task-continuation)
|
51
|
+
- [Task retrieval](#task-retrieval)
|
55
52
|
|
56
53
|
<!--TOC-->
|
57
54
|
|
58
55
|
## Installation
|
59
56
|
|
60
57
|
```bash
|
61
|
-
uv pip install
|
58
|
+
uv pip install futurehouse-client
|
62
59
|
```
|
63
60
|
|
64
61
|
## Quickstart
|
65
62
|
|
66
63
|
```python
|
67
|
-
from
|
64
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
68
65
|
from pathlib import Path
|
69
66
|
from aviary.core import DummyEnv
|
70
67
|
import ldp
|
71
68
|
|
72
|
-
client =
|
73
|
-
stage=Stage.PROD,
|
74
|
-
auth_type=AuthType.API_KEY,
|
69
|
+
client = FutureHouseClient(
|
75
70
|
api_key="your_api_key",
|
76
71
|
)
|
77
72
|
|
78
|
-
|
73
|
+
task_data = {
|
79
74
|
"name": JobNames.CROW,
|
80
|
-
"query": "
|
75
|
+
"query": "Which neglected diseases had a treatment developed by artificial intelligence?",
|
81
76
|
}
|
82
77
|
|
83
|
-
|
78
|
+
task_run_id = client.create_task(task_data)
|
84
79
|
|
85
|
-
|
80
|
+
task_status = client.get_task(task_run_id)
|
86
81
|
```
|
87
82
|
|
88
|
-
A quickstart example can be found in the [
|
83
|
+
A quickstart example can be found in the [client_notebook.ipynb](https://github.com/Future-House/futurehouse-client-docs/blob/main/docs/client_notebook.ipynb) file, where we show how to submit and retrieve a job task, pass runtime configuration to the agent, and ask follow-up questions to the previous job.
|
89
84
|
|
90
85
|
## Functionalities
|
91
86
|
|
92
|
-
|
87
|
+
FutureHouse client implements a RestClient (called `FutureHouseClient`) with the following functionalities:
|
93
88
|
|
94
|
-
- [
|
95
|
-
- [
|
96
|
-
- [Job status](#job-status): `get_job(job_id)`
|
97
|
-
|
98
|
-
To create a `CrowClient`, you need to pass the following parameters:
|
99
|
-
| Parameter | Type | Default | Description |
|
100
|
-
| --- | --- | --- | --- |
|
101
|
-
| stage | Stage | Stage.DEV | Where the job will be submitted? |
|
102
|
-
| organization | str \| None | None | Which organization to use? |
|
103
|
-
| auth_type | AuthType | AuthType.API_KEY | Which authentication method to use? |
|
104
|
-
| api_key | str \| None | None | The API key to use for authentication, if using auth_type=AuthType.API_KEY. |
|
89
|
+
- [Task submission](#task-submission): `create_task(TaskRequest)`
|
90
|
+
- [Task status](#task-status): `get_task(task_id)`
|
105
91
|
|
106
|
-
To
|
92
|
+
To create a `FutureHouseClient`, you need to pass an FutureHouse platform api key (see [Authentication](#authentication)):
|
107
93
|
|
108
94
|
```python
|
109
|
-
from
|
110
|
-
from crow_client.models import Stage, AuthType
|
95
|
+
from futurehouse_client import FutureHouseClient
|
111
96
|
|
112
|
-
client =
|
113
|
-
stage=Stage.PROD,
|
114
|
-
organization="your_organization",
|
115
|
-
auth_type=AuthType.API_KEY,
|
97
|
+
client = FutureHouseClient(
|
116
98
|
api_key="your_api_key",
|
117
99
|
)
|
118
100
|
```
|
119
101
|
|
120
|
-
### Stages
|
121
|
-
|
122
|
-
The stage is where your job will be submitted. This parameter can be one of the following:
|
123
|
-
| Name | Description |
|
124
|
-
| --- | --- |
|
125
|
-
| Stage.DEV | Development environment at https://dev.api.platform.futurehouse.org |
|
126
|
-
| Stage.PROD | Production environment at https://api.platform.futurehouse.org |
|
127
|
-
|
128
102
|
## Authentication
|
129
103
|
|
130
|
-
In order to use the `
|
104
|
+
In order to use the `FutureHouseClient`, you need to authenticate yourself. Authentication is done by providing an API key, which can be obtained directly from your [profile page in the FutureHouse platform](https://platform.futurehouse.org/profile).
|
131
105
|
|
132
|
-
##
|
106
|
+
## Task submission
|
133
107
|
|
134
|
-
|
135
|
-
|
108
|
+
In the futurehouse platform, we define the deployed combination of an agent and an environment as a `job`. To invoke a job, we need to submit a `task` (also called a `query`) to it.
|
109
|
+
`FutureHouseClient` can be used to submit tasks/queries to available jobs in the FutureHouse platform. Using a `FutureHouseClient` instance, you can submit tasks to the platform by calling the `create_task` method, which receives a `TaskRequest` (or a dictionary with `kwargs`) and returns the task id.
|
110
|
+
Aiming to make the submission of tasks as simple as possible, we have created a `JobNames` `enum` that contains the available task types.
|
136
111
|
|
137
112
|
The available supported jobs are:
|
138
113
|
| Alias | Job Name | Task type | Description |
|
@@ -143,27 +118,24 @@ The available supported jobs are:
|
|
143
118
|
| `JobNames.DUMMY` | `job-futurehouse-dummy` | Dummy Task | This is a dummy task. Mainly for testing purposes. |
|
144
119
|
|
145
120
|
Using `JobNames`, the client automatically adapts the job name to the current stage.
|
146
|
-
The
|
121
|
+
The task submission looks like this:
|
147
122
|
|
148
123
|
```python
|
149
|
-
from
|
150
|
-
from crow_client.models import AuthType, Stage
|
124
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
151
125
|
|
152
|
-
client =
|
153
|
-
stage=Stage.PROD,
|
154
|
-
auth_type=AuthType.API_KEY,
|
126
|
+
client = FutureHouseClient(
|
155
127
|
api_key="your_api_key",
|
156
128
|
)
|
157
129
|
|
158
|
-
|
159
|
-
"name": JobNames.
|
130
|
+
task_data = {
|
131
|
+
"name": JobNames.OWL,
|
160
132
|
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
161
133
|
}
|
162
134
|
|
163
|
-
|
135
|
+
task_id = client.create_task(task_data)
|
164
136
|
```
|
165
137
|
|
166
|
-
`
|
138
|
+
`TaskRequest` has the following fields:
|
167
139
|
|
168
140
|
| Field | Type | Description |
|
169
141
|
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------- |
|
@@ -175,51 +147,46 @@ job_id = client.create_job(job_data)
|
|
175
147
|
`runtime_config` can receive a `AgentConfig` object with the desired kwargs. Check the available `AgentConfig` fields in the [LDP documentation](https://github.com/Future-House/ldp/blob/main/src/ldp/agent/agent.py#L87). Besides the `AgentConfig` object, we can also pass `timeout` and `max_steps` to limit the execution time and the number of steps the agent can take.
|
176
148
|
Other especialised configurations are also available but are outside the scope of this documentation.
|
177
149
|
|
178
|
-
##
|
150
|
+
## Task Continuation
|
179
151
|
|
180
|
-
Once a
|
152
|
+
Once a task is submitted and the answer is returned, FutureHouse platform allow you to ask follow-up questions to the previous task.
|
181
153
|
It is also possible through the platform API.
|
182
|
-
To accomplish that, we can use the `runtime_config` we discussed in the [
|
154
|
+
To accomplish that, we can use the `runtime_config` we discussed in the [Task submission](#task-submission) section.
|
183
155
|
|
184
156
|
```python
|
185
|
-
from
|
186
|
-
from crow_client.models import AuthType, Stage
|
157
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
187
158
|
|
188
|
-
client =
|
189
|
-
stage=Stage.PROD,
|
190
|
-
auth_type=AuthType.API_KEY,
|
159
|
+
client = FutureHouseClient(
|
191
160
|
api_key="your_api_key",
|
192
161
|
)
|
193
162
|
|
194
|
-
|
163
|
+
task_data = {"name": JobNames.CROW, "query": "How many species of birds are there?"}
|
195
164
|
|
196
|
-
|
165
|
+
task_id = client.create_task(task_data)
|
197
166
|
|
198
|
-
|
167
|
+
continued_task_data = {
|
199
168
|
"name": JobNames.CROW,
|
200
169
|
"query": "From the previous answer, specifically,how many species of crows are there?",
|
201
|
-
"runtime_config": {"
|
170
|
+
"runtime_config": {"continued_task_id": task_id},
|
202
171
|
}
|
203
172
|
|
204
|
-
|
173
|
+
continued_task_id = client.create_task(continued_task_data)
|
205
174
|
```
|
206
175
|
|
207
|
-
##
|
176
|
+
## Task retrieval
|
208
177
|
|
209
|
-
Once a
|
178
|
+
Once a task is submitted, you can retrieve it by calling the `get_task` method, which receives a task id and returns a `TaskResponse` object.
|
210
179
|
|
211
180
|
```python
|
212
|
-
from
|
213
|
-
from crow_client.models import AuthType
|
181
|
+
from futurehouse_client import FutureHouseClient
|
214
182
|
|
215
|
-
client =
|
216
|
-
auth_type=AuthType.API_KEY,
|
183
|
+
client = FutureHouseClient(
|
217
184
|
api_key="your_api_key",
|
218
185
|
)
|
219
186
|
|
220
|
-
|
187
|
+
task_id = "task_id"
|
221
188
|
|
222
|
-
|
189
|
+
task_status = client.get_task(task_id)
|
223
190
|
```
|
224
191
|
|
225
|
-
`
|
192
|
+
`task_status` contains information about the task. For instance, its `status`, `task`, `environment_name` and `agent_name`, and other fields specific to the job.
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# FutureHouse Platform API Documentation
|
2
|
+
|
3
|
+
Documentation and tutorials for futurehouse-client, a client for interacting with endpoints of the FutureHouse platform.
|
4
|
+
|
5
|
+
<!--TOC-->
|
6
|
+
|
7
|
+
- [Installation](#installation)
|
8
|
+
- [Quickstart](#quickstart)
|
9
|
+
- [Functionalities](#functionalities)
|
10
|
+
- [Authentication](#authentication)
|
11
|
+
- [Task submission](#task-submission)
|
12
|
+
- [Task Continuation](#task-continuation)
|
13
|
+
- [Task retrieval](#task-retrieval)
|
14
|
+
|
15
|
+
<!--TOC-->
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
```bash
|
20
|
+
uv pip install futurehouse-client
|
21
|
+
```
|
22
|
+
|
23
|
+
## Quickstart
|
24
|
+
|
25
|
+
```python
|
26
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
27
|
+
from pathlib import Path
|
28
|
+
from aviary.core import DummyEnv
|
29
|
+
import ldp
|
30
|
+
|
31
|
+
client = FutureHouseClient(
|
32
|
+
api_key="your_api_key",
|
33
|
+
)
|
34
|
+
|
35
|
+
task_data = {
|
36
|
+
"name": JobNames.CROW,
|
37
|
+
"query": "Which neglected diseases had a treatment developed by artificial intelligence?",
|
38
|
+
}
|
39
|
+
|
40
|
+
task_run_id = client.create_task(task_data)
|
41
|
+
|
42
|
+
task_status = client.get_task(task_run_id)
|
43
|
+
```
|
44
|
+
|
45
|
+
A quickstart example can be found in the [client_notebook.ipynb](https://github.com/Future-House/futurehouse-client-docs/blob/main/docs/client_notebook.ipynb) file, where we show how to submit and retrieve a job task, pass runtime configuration to the agent, and ask follow-up questions to the previous job.
|
46
|
+
|
47
|
+
## Functionalities
|
48
|
+
|
49
|
+
FutureHouse client implements a RestClient (called `FutureHouseClient`) with the following functionalities:
|
50
|
+
|
51
|
+
- [Task submission](#task-submission): `create_task(TaskRequest)`
|
52
|
+
- [Task status](#task-status): `get_task(task_id)`
|
53
|
+
|
54
|
+
To create a `FutureHouseClient`, you need to pass an FutureHouse platform api key (see [Authentication](#authentication)):
|
55
|
+
|
56
|
+
```python
|
57
|
+
from futurehouse_client import FutureHouseClient
|
58
|
+
|
59
|
+
client = FutureHouseClient(
|
60
|
+
api_key="your_api_key",
|
61
|
+
)
|
62
|
+
```
|
63
|
+
|
64
|
+
## Authentication
|
65
|
+
|
66
|
+
In order to use the `FutureHouseClient`, you need to authenticate yourself. Authentication is done by providing an API key, which can be obtained directly from your [profile page in the FutureHouse platform](https://platform.futurehouse.org/profile).
|
67
|
+
|
68
|
+
## Task submission
|
69
|
+
|
70
|
+
In the futurehouse platform, we define the deployed combination of an agent and an environment as a `job`. To invoke a job, we need to submit a `task` (also called a `query`) to it.
|
71
|
+
`FutureHouseClient` can be used to submit tasks/queries to available jobs in the FutureHouse platform. Using a `FutureHouseClient` instance, you can submit tasks to the platform by calling the `create_task` method, which receives a `TaskRequest` (or a dictionary with `kwargs`) and returns the task id.
|
72
|
+
Aiming to make the submission of tasks as simple as possible, we have created a `JobNames` `enum` that contains the available task types.
|
73
|
+
|
74
|
+
The available supported jobs are:
|
75
|
+
| Alias | Job Name | Task type | Description |
|
76
|
+
| --- | --- | --- | --- |
|
77
|
+
| `JobNames.CROW` | `job-futurehouse-paperqa2` | Fast Search | Ask a question of scientific data sources, and receive a high-accuracy, cited response. Built with [PaperQA2](https://github.com/Future-House/paper-qa). |
|
78
|
+
| `JobNames.FALCON` | `job-futurehouse-paperqa2-deep` | Deep Search | Use a plethora of sources to deeply research. Receive a detailed, structured report as a response. |
|
79
|
+
| `JobNames.OWL` | `job-futurehouse-hasanyone` | Precedent Search | Formerly known as HasAnyone, query if anyone has ever done something in science. |
|
80
|
+
| `JobNames.DUMMY` | `job-futurehouse-dummy` | Dummy Task | This is a dummy task. Mainly for testing purposes. |
|
81
|
+
|
82
|
+
Using `JobNames`, the client automatically adapts the job name to the current stage.
|
83
|
+
The task submission looks like this:
|
84
|
+
|
85
|
+
```python
|
86
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
87
|
+
|
88
|
+
client = FutureHouseClient(
|
89
|
+
api_key="your_api_key",
|
90
|
+
)
|
91
|
+
|
92
|
+
task_data = {
|
93
|
+
"name": JobNames.OWL,
|
94
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
95
|
+
}
|
96
|
+
|
97
|
+
task_id = client.create_task(task_data)
|
98
|
+
```
|
99
|
+
|
100
|
+
`TaskRequest` has the following fields:
|
101
|
+
|
102
|
+
| Field | Type | Description |
|
103
|
+
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------- |
|
104
|
+
| id | UUID | Optional job identifier. A UUID will be generated if not provided |
|
105
|
+
| name | str | Name of the job to execute eg. `job-futurehouse-paperqa2`, or using the `JobNames` for convenience: `JobNames.CROW` |
|
106
|
+
| query | str | Query or task to be executed by the job |
|
107
|
+
| runtime_config | RuntimeConfig | Optional runtime parameters for the job |
|
108
|
+
|
109
|
+
`runtime_config` can receive a `AgentConfig` object with the desired kwargs. Check the available `AgentConfig` fields in the [LDP documentation](https://github.com/Future-House/ldp/blob/main/src/ldp/agent/agent.py#L87). Besides the `AgentConfig` object, we can also pass `timeout` and `max_steps` to limit the execution time and the number of steps the agent can take.
|
110
|
+
Other especialised configurations are also available but are outside the scope of this documentation.
|
111
|
+
|
112
|
+
## Task Continuation
|
113
|
+
|
114
|
+
Once a task is submitted and the answer is returned, FutureHouse platform allow you to ask follow-up questions to the previous task.
|
115
|
+
It is also possible through the platform API.
|
116
|
+
To accomplish that, we can use the `runtime_config` we discussed in the [Task submission](#task-submission) section.
|
117
|
+
|
118
|
+
```python
|
119
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
120
|
+
|
121
|
+
client = FutureHouseClient(
|
122
|
+
api_key="your_api_key",
|
123
|
+
)
|
124
|
+
|
125
|
+
task_data = {"name": JobNames.CROW, "query": "How many species of birds are there?"}
|
126
|
+
|
127
|
+
task_id = client.create_task(task_data)
|
128
|
+
|
129
|
+
continued_task_data = {
|
130
|
+
"name": JobNames.CROW,
|
131
|
+
"query": "From the previous answer, specifically,how many species of crows are there?",
|
132
|
+
"runtime_config": {"continued_task_id": task_id},
|
133
|
+
}
|
134
|
+
|
135
|
+
continued_task_id = client.create_task(continued_task_data)
|
136
|
+
```
|
137
|
+
|
138
|
+
## Task retrieval
|
139
|
+
|
140
|
+
Once a task is submitted, you can retrieve it by calling the `get_task` method, which receives a task id and returns a `TaskResponse` object.
|
141
|
+
|
142
|
+
```python
|
143
|
+
from futurehouse_client import FutureHouseClient
|
144
|
+
|
145
|
+
client = FutureHouseClient(
|
146
|
+
api_key="your_api_key",
|
147
|
+
)
|
148
|
+
|
149
|
+
task_id = "task_id"
|
150
|
+
|
151
|
+
task_status = client.get_task(task_id)
|
152
|
+
```
|
153
|
+
|
154
|
+
`task_status` contains information about the task. For instance, its `status`, `task`, `environment_name` and `agent_name`, and other fields specific to the job.
|
@@ -0,0 +1,197 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"metadata": {},
|
6
|
+
"source": [
|
7
|
+
"# FutureHouse platform client usage example"
|
8
|
+
]
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"cell_type": "code",
|
12
|
+
"execution_count": null,
|
13
|
+
"metadata": {},
|
14
|
+
"outputs": [],
|
15
|
+
"source": [
|
16
|
+
"import sys\n",
|
17
|
+
"from pathlib import Path\n",
|
18
|
+
"\n",
|
19
|
+
"sys.path.insert(0, str(Path(\"..\").resolve()))"
|
20
|
+
]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"cell_type": "code",
|
24
|
+
"execution_count": null,
|
25
|
+
"metadata": {},
|
26
|
+
"outputs": [],
|
27
|
+
"source": [
|
28
|
+
"import time\n",
|
29
|
+
"\n",
|
30
|
+
"from futurehouse_client import Client, JobNames\n",
|
31
|
+
"from futurehouse_client.models import (\n",
|
32
|
+
" AuthType,\n",
|
33
|
+
" JobRequest,\n",
|
34
|
+
" RuntimeConfig,\n",
|
35
|
+
" Stage,\n",
|
36
|
+
")\n",
|
37
|
+
"from ldp.agent import AgentConfig"
|
38
|
+
]
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"cell_type": "markdown",
|
42
|
+
"metadata": {},
|
43
|
+
"source": [
|
44
|
+
"## Client instantiation\n",
|
45
|
+
"\n",
|
46
|
+
"Here we use `auth_type=AuthType.API_KEY` to authenticate with the platform.\n",
|
47
|
+
"Please log in to the platform and go to your user settings to get your API key."
|
48
|
+
]
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"cell_type": "code",
|
52
|
+
"execution_count": null,
|
53
|
+
"metadata": {},
|
54
|
+
"outputs": [],
|
55
|
+
"source": [
|
56
|
+
"client = Client(\n",
|
57
|
+
" stage=Stage.PROD,\n",
|
58
|
+
" auth_type=AuthType.API_KEY,\n",
|
59
|
+
" api_key=\"your-api-key\",\n",
|
60
|
+
")"
|
61
|
+
]
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"cell_type": "markdown",
|
65
|
+
"metadata": {},
|
66
|
+
"source": [
|
67
|
+
"## Submit a job"
|
68
|
+
]
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"cell_type": "markdown",
|
72
|
+
"metadata": {},
|
73
|
+
"source": [
|
74
|
+
"Submitting jobs is done by calling the `create_job` method, which receives a `JobRequest` object."
|
75
|
+
]
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"cell_type": "code",
|
79
|
+
"execution_count": null,
|
80
|
+
"metadata": {},
|
81
|
+
"outputs": [],
|
82
|
+
"source": [
|
83
|
+
"job_data = JobRequest(\n",
|
84
|
+
" name=JobNames.from_string(\"crow\"),\n",
|
85
|
+
" query=\"What is the molecule known to have the greatest solubility in water?\",\n",
|
86
|
+
")\n",
|
87
|
+
"client.create_job(job_data)\n",
|
88
|
+
"\n",
|
89
|
+
"while client.get_job().status != \"success\":\n",
|
90
|
+
" time.sleep(5)\n",
|
91
|
+
"print(f\"Job status: {client.get_job().status}\")\n",
|
92
|
+
"print(f\"Job answer: \\n{client.get_job().formatted_answer}\")"
|
93
|
+
]
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"cell_type": "markdown",
|
97
|
+
"metadata": {},
|
98
|
+
"source": [
|
99
|
+
"You can also pass a `runtime_config` to the job, which will be used to configure the agent on runtime.\n",
|
100
|
+
"Here, we will define a agent configuration and pass it to the job. This agent is used to decide the next action to take.\n",
|
101
|
+
"We will also use the `max_steps` parameter to limit the number of steps the agent will take."
|
102
|
+
]
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"cell_type": "code",
|
106
|
+
"execution_count": null,
|
107
|
+
"metadata": {},
|
108
|
+
"outputs": [],
|
109
|
+
"source": [
|
110
|
+
"agent = AgentConfig(\n",
|
111
|
+
" agent_type=\"SimpleAgent\",\n",
|
112
|
+
" agent_kwargs={\n",
|
113
|
+
" \"model\": \"gpt-4o\",\n",
|
114
|
+
" \"temperature\": 0.0,\n",
|
115
|
+
" },\n",
|
116
|
+
")\n",
|
117
|
+
"job_data = JobRequest(\n",
|
118
|
+
" name=JobNames.CROW,\n",
|
119
|
+
" query=\"How many moons does earth have?\",\n",
|
120
|
+
" runtime_config=RuntimeConfig(agent=agent, max_steps=10),\n",
|
121
|
+
")\n",
|
122
|
+
"client.create_job(job_data)\n",
|
123
|
+
"\n",
|
124
|
+
"while client.get_job().status != \"success\":\n",
|
125
|
+
" time.sleep(5)\n",
|
126
|
+
"print(f\"Job status: {client.get_job().status}\")\n",
|
127
|
+
"print(f\"Job answer: \\n{client.get_job().formatted_answer}\")"
|
128
|
+
]
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"cell_type": "markdown",
|
132
|
+
"metadata": {},
|
133
|
+
"source": [
|
134
|
+
"# Continue a job\n",
|
135
|
+
"\n",
|
136
|
+
"The platform allows to keep asking follow-up questions to the previous job.\n",
|
137
|
+
"To accomplish that, we can use the `runtime_config` to pass the `job_id` of the previous job.\n",
|
138
|
+
"\n",
|
139
|
+
"Notice that `create_job` accepts both a `JobRequest` object and a dictionary with keywords arguments."
|
140
|
+
]
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"cell_type": "code",
|
144
|
+
"execution_count": null,
|
145
|
+
"metadata": {},
|
146
|
+
"outputs": [],
|
147
|
+
"source": [
|
148
|
+
"job_data = JobRequest(name=JobNames.CROW, query=\"How many species of birds are there?\")\n",
|
149
|
+
"\n",
|
150
|
+
"job_id = client.create_job(job_data)\n",
|
151
|
+
"while client.get_job().status != \"success\":\n",
|
152
|
+
" time.sleep(5)\n",
|
153
|
+
"print(f\"First job status: {client.get_job().status}\")\n",
|
154
|
+
"print(f\"First job answer: \\n{client.get_job().formatted_answer}\")"
|
155
|
+
]
|
156
|
+
},
|
157
|
+
{
|
158
|
+
"cell_type": "code",
|
159
|
+
"execution_count": null,
|
160
|
+
"metadata": {},
|
161
|
+
"outputs": [],
|
162
|
+
"source": [
|
163
|
+
"continued_job_data = {\n",
|
164
|
+
" \"name\": JobNames.CROW,\n",
|
165
|
+
" \"query\": \"From the previous answer, specifically,how many species of crows are there?\",\n",
|
166
|
+
" \"runtime_config\": {\"continued_job_id\": job_id},\n",
|
167
|
+
"}\n",
|
168
|
+
"\n",
|
169
|
+
"continued_job_id = client.create_job(continued_job_data)\n",
|
170
|
+
"while client.get_job().status != \"success\":\n",
|
171
|
+
" time.sleep(5)\n",
|
172
|
+
"print(f\"Continued job status: {client.get_job().status}\")\n",
|
173
|
+
"print(f\"Continued job answer: \\n{client.get_job().formatted_answer}\")"
|
174
|
+
]
|
175
|
+
}
|
176
|
+
],
|
177
|
+
"metadata": {
|
178
|
+
"kernelspec": {
|
179
|
+
"display_name": ".venv",
|
180
|
+
"language": "python",
|
181
|
+
"name": "python3"
|
182
|
+
},
|
183
|
+
"language_info": {
|
184
|
+
"codemirror_mode": {
|
185
|
+
"name": "ipython",
|
186
|
+
"version": 3
|
187
|
+
},
|
188
|
+
"file_extension": ".py",
|
189
|
+
"mimetype": "text/x-python",
|
190
|
+
"name": "python",
|
191
|
+
"nbconvert_exporter": "python",
|
192
|
+
"pygments_lexer": "ipython3"
|
193
|
+
}
|
194
|
+
},
|
195
|
+
"nbformat": 4,
|
196
|
+
"nbformat_minor": 4
|
197
|
+
}
|