futurehouse-client 0.3.17.dev56__tar.gz → 0.3.18.dev25__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.3.17.dev56 → futurehouse_client-0.3.18.dev25}/PKG-INFO +143 -22
- futurehouse_client-0.3.18.dev25/README.md +273 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/docs/client_notebook.ipynb +24 -29
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/clients/rest_client.py +314 -35
- futurehouse_client-0.3.18.dev25/futurehouse_client/models/rest.py +36 -0
- futurehouse_client-0.3.18.dev25/futurehouse_client/utils/general.py +29 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client.egg-info/PKG-INFO +143 -22
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client.egg-info/SOURCES.txt +1 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client.egg-info/requires.txt +2 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/pyproject.toml +2 -0
- futurehouse_client-0.3.18.dev25/tests/test_rest.py +214 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/uv.lock +44 -9
- futurehouse_client-0.3.17.dev56/README.md +0 -154
- futurehouse_client-0.3.17.dev56/futurehouse_client/models/rest.py +0 -19
- futurehouse_client-0.3.17.dev56/tests/test_rest.py +0 -96
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/LICENSE +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/docs/__init__.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/__init__.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/clients/__init__.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/clients/job_client.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/models/__init__.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/models/app.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/models/client.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/utils/__init__.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/utils/module_utils.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client/utils/monitoring.py +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client.egg-info/dependency_links.txt +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/futurehouse_client.egg-info/top_level.txt +0 -0
- {futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: futurehouse-client
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.18.dev25
|
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
|
@@ -19,6 +19,7 @@ Requires-Dist: litellm==1.67.4.post1
|
|
19
19
|
Requires-Dist: pydantic
|
20
20
|
Requires-Dist: python-dotenv
|
21
21
|
Requires-Dist: tenacity
|
22
|
+
Requires-Dist: tqdm>=4.62
|
22
23
|
Provides-Extra: dev
|
23
24
|
Requires-Dist: black; extra == "dev"
|
24
25
|
Requires-Dist: jupyter; extra == "dev"
|
@@ -30,6 +31,7 @@ Requires-Dist: pylint; extra == "dev"
|
|
30
31
|
Requires-Dist: pylint-per-file-ignores; extra == "dev"
|
31
32
|
Requires-Dist: pylint-pydantic; extra == "dev"
|
32
33
|
Requires-Dist: pytest; extra == "dev"
|
34
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
33
35
|
Requires-Dist: pytest-rerunfailures; extra == "dev"
|
34
36
|
Requires-Dist: pytest-subtests; extra == "dev"
|
35
37
|
Requires-Dist: pytest-timeout; extra == "dev"
|
@@ -49,9 +51,9 @@ Documentation and tutorials for futurehouse-client, a client for interacting wit
|
|
49
51
|
- [Quickstart](#quickstart)
|
50
52
|
- [Functionalities](#functionalities)
|
51
53
|
- [Authentication](#authentication)
|
52
|
-
- [
|
54
|
+
- [Simple task running](#simple-task-running)
|
53
55
|
- [Task Continuation](#task-continuation)
|
54
|
-
- [
|
56
|
+
- [Asynchronous tasks](#asynchronous-tasks)
|
55
57
|
|
56
58
|
<!--TOC-->
|
57
59
|
|
@@ -78,19 +80,17 @@ task_data = {
|
|
78
80
|
"query": "Which neglected diseases had a treatment developed by artificial intelligence?",
|
79
81
|
}
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
task_status = client.get_task(task_run_id)
|
83
|
+
task_response = client.run_tasks_until_done(task_data)
|
84
84
|
```
|
85
85
|
|
86
|
-
A quickstart example can be found in the [client_notebook.ipynb](https://
|
86
|
+
A quickstart example can be found in the [client_notebook.ipynb](https://futurehouse.gitbook.io/futurehouse-cookbook/futurehouse-client/docs/client_notebook) 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.
|
87
87
|
|
88
88
|
## Functionalities
|
89
89
|
|
90
90
|
FutureHouse client implements a RestClient (called `FutureHouseClient`) with the following functionalities:
|
91
91
|
|
92
|
-
- [
|
93
|
-
- [
|
92
|
+
- [Simple task running](#simple-task-running): `run_tasks_until_done(TaskRequest)` or `await arun_tasks_until_done(TaskRequest)`
|
93
|
+
- [Asynchronous tasks](#asynchronous-tasks): `get_task(task_id)` or `aget_task(task_id)` and `create_task(TaskRequest)` or `acreate_task(TaskRequest)`
|
94
94
|
|
95
95
|
To create a `FutureHouseClient`, you need to pass an FutureHouse platform api key (see [Authentication](#authentication)):
|
96
96
|
|
@@ -106,9 +106,9 @@ client = FutureHouseClient(
|
|
106
106
|
|
107
107
|
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).
|
108
108
|
|
109
|
-
##
|
109
|
+
## Simple task running
|
110
110
|
|
111
|
-
In the
|
111
|
+
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.
|
112
112
|
`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.
|
113
113
|
Aiming to make the submission of tasks as simple as possible, we have created a `JobNames` `enum` that contains the available task types.
|
114
114
|
|
@@ -118,10 +118,10 @@ The available supported jobs are:
|
|
118
118
|
| `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). |
|
119
119
|
| `JobNames.FALCON` | `job-futurehouse-paperqa2-deep` | Deep Search | Use a plethora of sources to deeply research. Receive a detailed, structured report as a response. |
|
120
120
|
| `JobNames.OWL` | `job-futurehouse-hasanyone` | Precedent Search | Formerly known as HasAnyone, query if anyone has ever done something in science. |
|
121
|
+
| `JobNames.PHOENIX` | `job-futurehouse-phoenix` | Chemistry Tasks | A new iteration of ChemCrow, Phoenix uses cheminformatics tools to do chemistry. Good for planning synthesis and design of new molecules. |
|
121
122
|
| `JobNames.DUMMY` | `job-futurehouse-dummy` | Dummy Task | This is a dummy task. Mainly for testing purposes. |
|
122
123
|
|
123
|
-
Using `JobNames`, the
|
124
|
-
The task submission looks like this:
|
124
|
+
Using `JobNames`, the task submission looks like this:
|
125
125
|
|
126
126
|
```python
|
127
127
|
from futurehouse_client import FutureHouseClient, JobNames
|
@@ -135,10 +135,73 @@ task_data = {
|
|
135
135
|
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
136
136
|
}
|
137
137
|
|
138
|
-
|
138
|
+
task_response = client.run_tasks_until_done(task_data)
|
139
|
+
|
140
|
+
print(task_response.answer)
|
141
|
+
```
|
142
|
+
|
143
|
+
Or if running async code:
|
144
|
+
|
145
|
+
```python
|
146
|
+
import asyncio
|
147
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
148
|
+
|
149
|
+
|
150
|
+
async def main():
|
151
|
+
client = FutureHouseClient(
|
152
|
+
api_key="your_api_key",
|
153
|
+
)
|
154
|
+
|
155
|
+
task_data = {
|
156
|
+
"name": JobNames.OWL,
|
157
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
158
|
+
}
|
159
|
+
|
160
|
+
task_response = await client.arun_tasks_until_done(task_data)
|
161
|
+
print(task_response.answer)
|
162
|
+
return task_id
|
163
|
+
|
164
|
+
|
165
|
+
# For Python 3.7+
|
166
|
+
if __name__ == "__main__":
|
167
|
+
task_id = asyncio.run(main())
|
139
168
|
```
|
140
169
|
|
141
|
-
|
170
|
+
Note that in either the sync or the async code, collections of tasks can be given to the client to run them in a batch:
|
171
|
+
|
172
|
+
```python
|
173
|
+
import asyncio
|
174
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
175
|
+
|
176
|
+
|
177
|
+
async def main():
|
178
|
+
client = FutureHouseClient(
|
179
|
+
api_key="your_api_key",
|
180
|
+
)
|
181
|
+
|
182
|
+
task_data = [
|
183
|
+
{
|
184
|
+
"name": JobNames.OWL,
|
185
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"name": JobNames.CROW,
|
189
|
+
"query": "Are there any clinically validated therapeutic exerkines for humans?",
|
190
|
+
},
|
191
|
+
]
|
192
|
+
|
193
|
+
task_responses = await client.arun_tasks_until_done(task_data)
|
194
|
+
print(task_responses[0].answer)
|
195
|
+
print(task_responses[1].answer)
|
196
|
+
return task_id
|
197
|
+
|
198
|
+
|
199
|
+
# For Python 3.7+
|
200
|
+
if __name__ == "__main__":
|
201
|
+
task_id = asyncio.run(main())
|
202
|
+
```
|
203
|
+
|
204
|
+
`TaskRequest` can also be used to submit jobs and it has the following fields:
|
142
205
|
|
143
206
|
| Field | Type | Description |
|
144
207
|
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------- |
|
@@ -148,13 +211,67 @@ task_id = client.create_task(task_data)
|
|
148
211
|
| runtime_config | RuntimeConfig | Optional runtime parameters for the job |
|
149
212
|
|
150
213
|
`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.
|
151
|
-
|
214
|
+
|
215
|
+
```python
|
216
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
217
|
+
from futurehouse_client.models.app import TaskRequest
|
218
|
+
|
219
|
+
client = FutureHouseClient(
|
220
|
+
api_key="your_api_key",
|
221
|
+
)
|
222
|
+
|
223
|
+
task_response = client.run_tasks_until_done(
|
224
|
+
TaskRequest(
|
225
|
+
name=JobNames.OWL,
|
226
|
+
query="Has anyone tested therapeutic exerkines in humans or NHPs?",
|
227
|
+
)
|
228
|
+
)
|
229
|
+
|
230
|
+
print(task_response.answer)
|
231
|
+
```
|
232
|
+
|
233
|
+
A `TaskResponse` will be returned from using our agents. For Owl, Crow, and Falcon, we default to a subclass, `PQATaskResponse` which has some key attributes:
|
234
|
+
|
235
|
+
| Field | Type | Description |
|
236
|
+
| --------------------- | ---- | ------------------------------------------------------------------------------- |
|
237
|
+
| answer | str | Answer to your query. |
|
238
|
+
| formatted_answer | str | Specially formatted answer with references. |
|
239
|
+
| has_successful_answer | bool | Flag for whether the agent was able to find a good answer to your query or not. |
|
240
|
+
|
241
|
+
If using the `verbose` setting, much more data can be pulled down from your `TaskResponse`, which will exist across all agents (not just Owl, Crow, and Falcon).
|
242
|
+
|
243
|
+
```python
|
244
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
245
|
+
from futurehouse_client.models.app import TaskRequest
|
246
|
+
|
247
|
+
client = FutureHouseClient(
|
248
|
+
api_key="your_api_key",
|
249
|
+
)
|
250
|
+
|
251
|
+
task_response = client.run_tasks_until_done(
|
252
|
+
TaskRequest(
|
253
|
+
name=JobNames.OWL,
|
254
|
+
query="Has anyone tested therapeutic exerkines in humans or NHPs?",
|
255
|
+
),
|
256
|
+
verbose=True,
|
257
|
+
)
|
258
|
+
|
259
|
+
print(task_response.environment_frame)
|
260
|
+
```
|
261
|
+
|
262
|
+
In that case, a `TaskResponseVerbose` will have the following fields:
|
263
|
+
|
264
|
+
| Field | Type | Description |
|
265
|
+
| ----------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | --- |
|
266
|
+
| agent_state | dict | Large object with all agent states during the progress of your task. |
|
267
|
+
| environment_frame | dict | Large nested object with all environment data, for PQA environments it includes contexts, paper metadata, and answers. |
|
268
|
+
| metadata | dict | Extra metadata about your query. | |
|
152
269
|
|
153
270
|
## Task Continuation
|
154
271
|
|
155
272
|
Once a task is submitted and the answer is returned, FutureHouse platform allow you to ask follow-up questions to the previous task.
|
156
273
|
It is also possible through the platform API.
|
157
|
-
To accomplish that, we can use the `runtime_config` we discussed in the [
|
274
|
+
To accomplish that, we can use the `runtime_config` we discussed in the [Simple task running](#simple-task-running) section.
|
158
275
|
|
159
276
|
```python
|
160
277
|
from futurehouse_client import FutureHouseClient, JobNames
|
@@ -173,12 +290,12 @@ continued_task_data = {
|
|
173
290
|
"runtime_config": {"continued_task_id": task_id},
|
174
291
|
}
|
175
292
|
|
176
|
-
|
293
|
+
task_result = client.run_tasks_until_done(continued_task_data)
|
177
294
|
```
|
178
295
|
|
179
|
-
##
|
296
|
+
## Asynchronous tasks
|
180
297
|
|
181
|
-
|
298
|
+
Sometimes you may want to submit many jobs, while querying results at a later time. In this way you can do other things while waiting for a response. The platform API supports this as well rather than waiting for a result.
|
182
299
|
|
183
300
|
```python
|
184
301
|
from futurehouse_client import FutureHouseClient
|
@@ -187,9 +304,13 @@ client = FutureHouseClient(
|
|
187
304
|
api_key="your_api_key",
|
188
305
|
)
|
189
306
|
|
190
|
-
|
307
|
+
task_data = {"name": JobNames.CROW, "query": "How many species of birds are there?"}
|
308
|
+
|
309
|
+
task_id = client.create_task(task_data)
|
310
|
+
|
311
|
+
# move on to do other things
|
191
312
|
|
192
313
|
task_status = client.get_task(task_id)
|
193
314
|
```
|
194
315
|
|
195
|
-
`task_status` contains information about the task. For instance, its `status`, `task`, `environment_name` and `agent_name`, and other fields specific to the job.
|
316
|
+
`task_status` contains information about the task. For instance, its `status`, `task`, `environment_name` and `agent_name`, and other fields specific to the job. You can continually query the status until it's `success` before moving on.
|
@@ -0,0 +1,273 @@
|
|
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
|
+
- [Simple task running](#simple-task-running)
|
12
|
+
- [Task Continuation](#task-continuation)
|
13
|
+
- [Asynchronous tasks](#asynchronous-tasks)
|
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_response = client.run_tasks_until_done(task_data)
|
41
|
+
```
|
42
|
+
|
43
|
+
A quickstart example can be found in the [client_notebook.ipynb](https://futurehouse.gitbook.io/futurehouse-cookbook/futurehouse-client/docs/client_notebook) 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.
|
44
|
+
|
45
|
+
## Functionalities
|
46
|
+
|
47
|
+
FutureHouse client implements a RestClient (called `FutureHouseClient`) with the following functionalities:
|
48
|
+
|
49
|
+
- [Simple task running](#simple-task-running): `run_tasks_until_done(TaskRequest)` or `await arun_tasks_until_done(TaskRequest)`
|
50
|
+
- [Asynchronous tasks](#asynchronous-tasks): `get_task(task_id)` or `aget_task(task_id)` and `create_task(TaskRequest)` or `acreate_task(TaskRequest)`
|
51
|
+
|
52
|
+
To create a `FutureHouseClient`, you need to pass an FutureHouse platform api key (see [Authentication](#authentication)):
|
53
|
+
|
54
|
+
```python
|
55
|
+
from futurehouse_client import FutureHouseClient
|
56
|
+
|
57
|
+
client = FutureHouseClient(
|
58
|
+
api_key="your_api_key",
|
59
|
+
)
|
60
|
+
```
|
61
|
+
|
62
|
+
## Authentication
|
63
|
+
|
64
|
+
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).
|
65
|
+
|
66
|
+
## Simple task running
|
67
|
+
|
68
|
+
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.
|
69
|
+
`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.
|
70
|
+
Aiming to make the submission of tasks as simple as possible, we have created a `JobNames` `enum` that contains the available task types.
|
71
|
+
|
72
|
+
The available supported jobs are:
|
73
|
+
| Alias | Job Name | Task type | Description |
|
74
|
+
| --- | --- | --- | --- |
|
75
|
+
| `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). |
|
76
|
+
| `JobNames.FALCON` | `job-futurehouse-paperqa2-deep` | Deep Search | Use a plethora of sources to deeply research. Receive a detailed, structured report as a response. |
|
77
|
+
| `JobNames.OWL` | `job-futurehouse-hasanyone` | Precedent Search | Formerly known as HasAnyone, query if anyone has ever done something in science. |
|
78
|
+
| `JobNames.PHOENIX` | `job-futurehouse-phoenix` | Chemistry Tasks | A new iteration of ChemCrow, Phoenix uses cheminformatics tools to do chemistry. Good for planning synthesis and design of new molecules. |
|
79
|
+
| `JobNames.DUMMY` | `job-futurehouse-dummy` | Dummy Task | This is a dummy task. Mainly for testing purposes. |
|
80
|
+
|
81
|
+
Using `JobNames`, the task submission looks like this:
|
82
|
+
|
83
|
+
```python
|
84
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
85
|
+
|
86
|
+
client = FutureHouseClient(
|
87
|
+
api_key="your_api_key",
|
88
|
+
)
|
89
|
+
|
90
|
+
task_data = {
|
91
|
+
"name": JobNames.OWL,
|
92
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
93
|
+
}
|
94
|
+
|
95
|
+
task_response = client.run_tasks_until_done(task_data)
|
96
|
+
|
97
|
+
print(task_response.answer)
|
98
|
+
```
|
99
|
+
|
100
|
+
Or if running async code:
|
101
|
+
|
102
|
+
```python
|
103
|
+
import asyncio
|
104
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
105
|
+
|
106
|
+
|
107
|
+
async def main():
|
108
|
+
client = FutureHouseClient(
|
109
|
+
api_key="your_api_key",
|
110
|
+
)
|
111
|
+
|
112
|
+
task_data = {
|
113
|
+
"name": JobNames.OWL,
|
114
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
115
|
+
}
|
116
|
+
|
117
|
+
task_response = await client.arun_tasks_until_done(task_data)
|
118
|
+
print(task_response.answer)
|
119
|
+
return task_id
|
120
|
+
|
121
|
+
|
122
|
+
# For Python 3.7+
|
123
|
+
if __name__ == "__main__":
|
124
|
+
task_id = asyncio.run(main())
|
125
|
+
```
|
126
|
+
|
127
|
+
Note that in either the sync or the async code, collections of tasks can be given to the client to run them in a batch:
|
128
|
+
|
129
|
+
```python
|
130
|
+
import asyncio
|
131
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
132
|
+
|
133
|
+
|
134
|
+
async def main():
|
135
|
+
client = FutureHouseClient(
|
136
|
+
api_key="your_api_key",
|
137
|
+
)
|
138
|
+
|
139
|
+
task_data = [
|
140
|
+
{
|
141
|
+
"name": JobNames.OWL,
|
142
|
+
"query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
|
143
|
+
},
|
144
|
+
{
|
145
|
+
"name": JobNames.CROW,
|
146
|
+
"query": "Are there any clinically validated therapeutic exerkines for humans?",
|
147
|
+
},
|
148
|
+
]
|
149
|
+
|
150
|
+
task_responses = await client.arun_tasks_until_done(task_data)
|
151
|
+
print(task_responses[0].answer)
|
152
|
+
print(task_responses[1].answer)
|
153
|
+
return task_id
|
154
|
+
|
155
|
+
|
156
|
+
# For Python 3.7+
|
157
|
+
if __name__ == "__main__":
|
158
|
+
task_id = asyncio.run(main())
|
159
|
+
```
|
160
|
+
|
161
|
+
`TaskRequest` can also be used to submit jobs and it has the following fields:
|
162
|
+
|
163
|
+
| Field | Type | Description |
|
164
|
+
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------- |
|
165
|
+
| id | UUID | Optional job identifier. A UUID will be generated if not provided |
|
166
|
+
| name | str | Name of the job to execute eg. `job-futurehouse-paperqa2`, or using the `JobNames` for convenience: `JobNames.CROW` |
|
167
|
+
| query | str | Query or task to be executed by the job |
|
168
|
+
| runtime_config | RuntimeConfig | Optional runtime parameters for the job |
|
169
|
+
|
170
|
+
`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.
|
171
|
+
|
172
|
+
```python
|
173
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
174
|
+
from futurehouse_client.models.app import TaskRequest
|
175
|
+
|
176
|
+
client = FutureHouseClient(
|
177
|
+
api_key="your_api_key",
|
178
|
+
)
|
179
|
+
|
180
|
+
task_response = client.run_tasks_until_done(
|
181
|
+
TaskRequest(
|
182
|
+
name=JobNames.OWL,
|
183
|
+
query="Has anyone tested therapeutic exerkines in humans or NHPs?",
|
184
|
+
)
|
185
|
+
)
|
186
|
+
|
187
|
+
print(task_response.answer)
|
188
|
+
```
|
189
|
+
|
190
|
+
A `TaskResponse` will be returned from using our agents. For Owl, Crow, and Falcon, we default to a subclass, `PQATaskResponse` which has some key attributes:
|
191
|
+
|
192
|
+
| Field | Type | Description |
|
193
|
+
| --------------------- | ---- | ------------------------------------------------------------------------------- |
|
194
|
+
| answer | str | Answer to your query. |
|
195
|
+
| formatted_answer | str | Specially formatted answer with references. |
|
196
|
+
| has_successful_answer | bool | Flag for whether the agent was able to find a good answer to your query or not. |
|
197
|
+
|
198
|
+
If using the `verbose` setting, much more data can be pulled down from your `TaskResponse`, which will exist across all agents (not just Owl, Crow, and Falcon).
|
199
|
+
|
200
|
+
```python
|
201
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
202
|
+
from futurehouse_client.models.app import TaskRequest
|
203
|
+
|
204
|
+
client = FutureHouseClient(
|
205
|
+
api_key="your_api_key",
|
206
|
+
)
|
207
|
+
|
208
|
+
task_response = client.run_tasks_until_done(
|
209
|
+
TaskRequest(
|
210
|
+
name=JobNames.OWL,
|
211
|
+
query="Has anyone tested therapeutic exerkines in humans or NHPs?",
|
212
|
+
),
|
213
|
+
verbose=True,
|
214
|
+
)
|
215
|
+
|
216
|
+
print(task_response.environment_frame)
|
217
|
+
```
|
218
|
+
|
219
|
+
In that case, a `TaskResponseVerbose` will have the following fields:
|
220
|
+
|
221
|
+
| Field | Type | Description |
|
222
|
+
| ----------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | --- |
|
223
|
+
| agent_state | dict | Large object with all agent states during the progress of your task. |
|
224
|
+
| environment_frame | dict | Large nested object with all environment data, for PQA environments it includes contexts, paper metadata, and answers. |
|
225
|
+
| metadata | dict | Extra metadata about your query. | |
|
226
|
+
|
227
|
+
## Task Continuation
|
228
|
+
|
229
|
+
Once a task is submitted and the answer is returned, FutureHouse platform allow you to ask follow-up questions to the previous task.
|
230
|
+
It is also possible through the platform API.
|
231
|
+
To accomplish that, we can use the `runtime_config` we discussed in the [Simple task running](#simple-task-running) section.
|
232
|
+
|
233
|
+
```python
|
234
|
+
from futurehouse_client import FutureHouseClient, JobNames
|
235
|
+
|
236
|
+
client = FutureHouseClient(
|
237
|
+
api_key="your_api_key",
|
238
|
+
)
|
239
|
+
|
240
|
+
task_data = {"name": JobNames.CROW, "query": "How many species of birds are there?"}
|
241
|
+
|
242
|
+
task_id = client.create_task(task_data)
|
243
|
+
|
244
|
+
continued_task_data = {
|
245
|
+
"name": JobNames.CROW,
|
246
|
+
"query": "From the previous answer, specifically,how many species of crows are there?",
|
247
|
+
"runtime_config": {"continued_task_id": task_id},
|
248
|
+
}
|
249
|
+
|
250
|
+
task_result = client.run_tasks_until_done(continued_task_data)
|
251
|
+
```
|
252
|
+
|
253
|
+
## Asynchronous tasks
|
254
|
+
|
255
|
+
Sometimes you may want to submit many jobs, while querying results at a later time. In this way you can do other things while waiting for a response. The platform API supports this as well rather than waiting for a result.
|
256
|
+
|
257
|
+
```python
|
258
|
+
from futurehouse_client import FutureHouseClient
|
259
|
+
|
260
|
+
client = FutureHouseClient(
|
261
|
+
api_key="your_api_key",
|
262
|
+
)
|
263
|
+
|
264
|
+
task_data = {"name": JobNames.CROW, "query": "How many species of birds are there?"}
|
265
|
+
|
266
|
+
task_id = client.create_task(task_data)
|
267
|
+
|
268
|
+
# move on to do other things
|
269
|
+
|
270
|
+
task_status = client.get_task(task_id)
|
271
|
+
```
|
272
|
+
|
273
|
+
`task_status` contains information about the task. For instance, its `status`, `task`, `environment_name` and `agent_name`, and other fields specific to the job. You can continually query the status until it's `success` before moving on.
|
{futurehouse_client-0.3.17.dev56 → futurehouse_client-0.3.18.dev25}/docs/client_notebook.ipynb
RENAMED
@@ -25,8 +25,6 @@
|
|
25
25
|
"metadata": {},
|
26
26
|
"outputs": [],
|
27
27
|
"source": [
|
28
|
-
"import time\n",
|
29
|
-
"\n",
|
30
28
|
"from futurehouse_client import FutureHouseClient, JobNames\n",
|
31
29
|
"from futurehouse_client.models import (\n",
|
32
30
|
" AuthType,\n",
|
@@ -71,7 +69,7 @@
|
|
71
69
|
"cell_type": "markdown",
|
72
70
|
"metadata": {},
|
73
71
|
"source": [
|
74
|
-
"Submitting jobs is done by calling the `
|
72
|
+
"Submitting jobs is done by calling the `run_tasks_until_done` method, which receives a `TaskRequest` object."
|
75
73
|
]
|
76
74
|
},
|
77
75
|
{
|
@@ -80,24 +78,22 @@
|
|
80
78
|
"metadata": {},
|
81
79
|
"outputs": [],
|
82
80
|
"source": [
|
83
|
-
"
|
81
|
+
"task_data = TaskRequest(\n",
|
84
82
|
" name=JobNames.from_string(\"crow\"),\n",
|
85
83
|
" query=\"What is the molecule known to have the greatest solubility in water?\",\n",
|
86
84
|
")\n",
|
87
|
-
"client.
|
85
|
+
"task_response = client.run_tasks_until_done(task_data)\n",
|
88
86
|
"\n",
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"print(f\"Job status: {client.get_job().status}\")\n",
|
92
|
-
"print(f\"Job answer: \\n{client.get_job().formatted_answer}\")"
|
87
|
+
"print(f\"Job status: {task_response.status}\")\n",
|
88
|
+
"print(f\"Job answer: \\n{task_response.formatted_answer}\")"
|
93
89
|
]
|
94
90
|
},
|
95
91
|
{
|
96
92
|
"cell_type": "markdown",
|
97
93
|
"metadata": {},
|
98
94
|
"source": [
|
99
|
-
"You can also pass a `runtime_config` to the
|
100
|
-
"Here, we will define a agent configuration and pass it to the
|
95
|
+
"You can also pass a `runtime_config` to the task, which will be used to configure the agent on runtime.\n",
|
96
|
+
"Here, we will define a agent configuration and pass it to the task. This agent is used to decide the next action to take.\n",
|
101
97
|
"We will also use the `max_steps` parameter to limit the number of steps the agent will take."
|
102
98
|
]
|
103
99
|
},
|
@@ -114,17 +110,15 @@
|
|
114
110
|
" \"temperature\": 0.0,\n",
|
115
111
|
" },\n",
|
116
112
|
")\n",
|
117
|
-
"
|
113
|
+
"task_data = TaskRequest(\n",
|
118
114
|
" name=JobNames.CROW,\n",
|
119
115
|
" query=\"How many moons does earth have?\",\n",
|
120
116
|
" runtime_config=RuntimeConfig(agent=agent, max_steps=10),\n",
|
121
117
|
")\n",
|
122
|
-
"client.
|
118
|
+
"task_response = client.run_tasks_until_done(task_data)\n",
|
123
119
|
"\n",
|
124
|
-
"
|
125
|
-
"
|
126
|
-
"print(f\"Job status: {client.get_job().status}\")\n",
|
127
|
-
"print(f\"Job answer: \\n{client.get_job().formatted_answer}\")"
|
120
|
+
"print(f\"Job status: {task_response.status}\")\n",
|
121
|
+
"print(f\"Job answer: \\n{task_response.formatted_answer}\")"
|
128
122
|
]
|
129
123
|
},
|
130
124
|
{
|
@@ -145,13 +139,14 @@
|
|
145
139
|
"metadata": {},
|
146
140
|
"outputs": [],
|
147
141
|
"source": [
|
148
|
-
"
|
142
|
+
"task_data = TaskRequest(\n",
|
143
|
+
" name=JobNames.CROW, query=\"How many species of birds are there?\"\n",
|
144
|
+
")\n",
|
145
|
+
"\n",
|
146
|
+
"task_response = client.run_tasks_until_done(task_data)\n",
|
149
147
|
"\n",
|
150
|
-
"
|
151
|
-
"
|
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}\")"
|
148
|
+
"print(f\"First job status: {task_response.status}\")\n",
|
149
|
+
"print(f\"First job answer: \\n{task_response.formatted_answer}\")"
|
155
150
|
]
|
156
151
|
},
|
157
152
|
{
|
@@ -163,14 +158,14 @@
|
|
163
158
|
"continued_job_data = {\n",
|
164
159
|
" \"name\": JobNames.CROW,\n",
|
165
160
|
" \"query\": \"From the previous answer, specifically,how many species of crows are there?\",\n",
|
166
|
-
" \"runtime_config\": {\"continued_job_id\":
|
161
|
+
" \"runtime_config\": {\"continued_job_id\": task_response.task_id},\n",
|
167
162
|
"}\n",
|
168
163
|
"\n",
|
169
|
-
"
|
170
|
-
"
|
171
|
-
"
|
172
|
-
"print(f\"Continued job status: {
|
173
|
-
"print(f\"Continued job answer: \\n{
|
164
|
+
"continued_task_response = client.run_tasks_until_done(continued_job_data)\n",
|
165
|
+
"\n",
|
166
|
+
"\n",
|
167
|
+
"print(f\"Continued job status: {continued_task_response.status}\")\n",
|
168
|
+
"print(f\"Continued job answer: \\n{continued_task_response.formatted_answer}\")"
|
174
169
|
]
|
175
170
|
}
|
176
171
|
],
|