futurehouse-client 0.3.17.dev56__py3-none-any.whl → 0.3.18__py3-none-any.whl
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/clients/job_client.py +1 -0
- futurehouse_client/clients/rest_client.py +393 -190
- futurehouse_client/models/__init__.py +10 -0
- futurehouse_client/models/app.py +96 -0
- futurehouse_client/models/rest.py +17 -0
- futurehouse_client/utils/auth.py +92 -0
- futurehouse_client/utils/general.py +29 -0
- {futurehouse_client-0.3.17.dev56.dist-info → futurehouse_client-0.3.18.dist-info}/METADATA +143 -22
- futurehouse_client-0.3.18.dist-info/RECORD +17 -0
- {futurehouse_client-0.3.17.dev56.dist-info → futurehouse_client-0.3.18.dist-info}/WHEEL +1 -1
- futurehouse_client-0.3.17.dev56.dist-info/RECORD +0 -15
- {futurehouse_client-0.3.17.dev56.dist-info → futurehouse_client-0.3.18.dist-info}/top_level.txt +0 -0
@@ -3,10 +3,15 @@ from .app import (
|
|
3
3
|
DockerContainerConfiguration,
|
4
4
|
FramePath,
|
5
5
|
JobDeploymentConfig,
|
6
|
+
PQATaskResponse,
|
6
7
|
RuntimeConfig,
|
7
8
|
Stage,
|
8
9
|
Step,
|
10
|
+
TaskQueue,
|
11
|
+
TaskQueuesConfig,
|
9
12
|
TaskRequest,
|
13
|
+
TaskResponse,
|
14
|
+
TaskResponseVerbose,
|
10
15
|
)
|
11
16
|
|
12
17
|
__all__ = [
|
@@ -14,8 +19,13 @@ __all__ = [
|
|
14
19
|
"DockerContainerConfiguration",
|
15
20
|
"FramePath",
|
16
21
|
"JobDeploymentConfig",
|
22
|
+
"PQATaskResponse",
|
17
23
|
"RuntimeConfig",
|
18
24
|
"Stage",
|
19
25
|
"Step",
|
26
|
+
"TaskQueue",
|
27
|
+
"TaskQueuesConfig",
|
20
28
|
"TaskRequest",
|
29
|
+
"TaskResponse",
|
30
|
+
"TaskResponseVerbose",
|
21
31
|
]
|
futurehouse_client/models/app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
import copy
|
1
2
|
import json
|
2
3
|
import os
|
3
4
|
import re
|
5
|
+
from collections.abc import Mapping
|
6
|
+
from datetime import datetime
|
4
7
|
from enum import StrEnum, auto
|
5
8
|
from pathlib import Path
|
6
9
|
from typing import TYPE_CHECKING, Any, ClassVar, Self, cast
|
@@ -646,3 +649,96 @@ class TaskRequest(BaseModel):
|
|
646
649
|
runtime_config: RuntimeConfig | None = Field(
|
647
650
|
default=None, description="All optional runtime parameters for the job"
|
648
651
|
)
|
652
|
+
|
653
|
+
|
654
|
+
class SimpleOrganization(BaseModel):
|
655
|
+
id: int
|
656
|
+
name: str
|
657
|
+
display_name: str
|
658
|
+
|
659
|
+
|
660
|
+
class TaskResponse(BaseModel):
|
661
|
+
"""Base class for task responses. This holds attributes shared over all futurehouse jobs."""
|
662
|
+
|
663
|
+
model_config = ConfigDict(extra="ignore")
|
664
|
+
|
665
|
+
status: str
|
666
|
+
query: str
|
667
|
+
user: str | None = None
|
668
|
+
created_at: datetime
|
669
|
+
job_name: str
|
670
|
+
public: bool
|
671
|
+
shared_with: list[SimpleOrganization] | None = None
|
672
|
+
build_owner: str | None = None
|
673
|
+
environment_name: str | None = None
|
674
|
+
agent_name: str | None = None
|
675
|
+
task_id: UUID | None = None
|
676
|
+
|
677
|
+
@model_validator(mode="before")
|
678
|
+
@classmethod
|
679
|
+
def validate_fields(cls, original_data: Mapping[str, Any]) -> Mapping[str, Any]:
|
680
|
+
data = copy.deepcopy(original_data) # Avoid mutating the original data
|
681
|
+
# Extract fields from environment frame state
|
682
|
+
if not isinstance(data, dict):
|
683
|
+
return data
|
684
|
+
# TODO: We probably want to remove these two once we define the final names.
|
685
|
+
data["job_name"] = data.get("crow")
|
686
|
+
data["query"] = data.get("task")
|
687
|
+
data["task_id"] = cast(UUID, data.get("id")) if data.get("id") else None
|
688
|
+
if not (metadata := data.get("metadata", {})):
|
689
|
+
return data
|
690
|
+
data["environment_name"] = metadata.get("environment_name")
|
691
|
+
data["agent_name"] = metadata.get("agent_name")
|
692
|
+
return data
|
693
|
+
|
694
|
+
|
695
|
+
class PQATaskResponse(TaskResponse):
|
696
|
+
model_config = ConfigDict(extra="ignore")
|
697
|
+
|
698
|
+
answer: str | None = None
|
699
|
+
formatted_answer: str | None = None
|
700
|
+
answer_reasoning: str | None = None
|
701
|
+
has_successful_answer: bool | None = None
|
702
|
+
total_cost: float | None = None
|
703
|
+
total_queries: int | None = None
|
704
|
+
|
705
|
+
@model_validator(mode="before")
|
706
|
+
@classmethod
|
707
|
+
def validate_pqa_fields(cls, original_data: Mapping[str, Any]) -> Mapping[str, Any]:
|
708
|
+
data = copy.deepcopy(original_data) # Avoid mutating the original data
|
709
|
+
if not isinstance(data, dict):
|
710
|
+
return data
|
711
|
+
if not (env_frame := data.get("environment_frame", {})):
|
712
|
+
return data
|
713
|
+
state = env_frame.get("state", {}).get("state", {})
|
714
|
+
response = state.get("response", {})
|
715
|
+
answer = response.get("answer", {})
|
716
|
+
usage = state.get("info", {}).get("usage", {})
|
717
|
+
|
718
|
+
# Add additional PQA specific fields to data so that pydantic can validate the model
|
719
|
+
data["answer"] = answer.get("answer")
|
720
|
+
data["formatted_answer"] = answer.get("formatted_answer")
|
721
|
+
data["answer_reasoning"] = answer.get("answer_reasoning")
|
722
|
+
data["has_successful_answer"] = answer.get("has_successful_answer")
|
723
|
+
data["total_cost"] = cast(float, usage.get("total_cost"))
|
724
|
+
data["total_queries"] = cast(int, usage.get("total_queries"))
|
725
|
+
|
726
|
+
return data
|
727
|
+
|
728
|
+
def clean_verbose(self) -> "TaskResponse":
|
729
|
+
"""Clean the verbose response from the server."""
|
730
|
+
self.request = None
|
731
|
+
self.response = None
|
732
|
+
return self
|
733
|
+
|
734
|
+
|
735
|
+
class TaskResponseVerbose(TaskResponse):
|
736
|
+
"""Class for responses to include all the fields of a task response."""
|
737
|
+
|
738
|
+
model_config = ConfigDict(extra="allow")
|
739
|
+
|
740
|
+
public: bool
|
741
|
+
agent_state: list[dict[str, Any]] | None = None
|
742
|
+
environment_frame: dict[str, Any] | None = None
|
743
|
+
metadata: dict[str, Any] | None = None
|
744
|
+
shared_with: list[SimpleOrganization] | None = None
|
@@ -1,3 +1,5 @@
|
|
1
|
+
from enum import StrEnum, auto
|
2
|
+
|
1
3
|
from pydantic import BaseModel, JsonValue
|
2
4
|
|
3
5
|
|
@@ -17,3 +19,18 @@ class StoreEnvironmentFrameRequest(BaseModel):
|
|
17
19
|
current_agent_step: str
|
18
20
|
state: JsonValue
|
19
21
|
trajectory_timestep: int
|
22
|
+
|
23
|
+
|
24
|
+
class ExecutionStatus(StrEnum):
|
25
|
+
QUEUED = auto()
|
26
|
+
IN_PROGRESS = "in progress"
|
27
|
+
FAIL = auto()
|
28
|
+
SUCCESS = auto()
|
29
|
+
CANCELLED = auto()
|
30
|
+
|
31
|
+
def is_terminal_state(self) -> bool:
|
32
|
+
return self in self.terminal_states()
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def terminal_states(cls) -> set["ExecutionStatus"]:
|
36
|
+
return {cls.SUCCESS, cls.FAIL, cls.CANCELLED}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import logging
|
2
|
+
from collections.abc import Collection, Generator
|
3
|
+
from typing import ClassVar, Final
|
4
|
+
|
5
|
+
import httpx
|
6
|
+
|
7
|
+
from futurehouse_client.models.app import APIKeyPayload, AuthType
|
8
|
+
|
9
|
+
logger = logging.getLogger(__name__)
|
10
|
+
|
11
|
+
INVALID_REFRESH_TYPE_MSG: Final[str] = (
|
12
|
+
"API key auth is required to refresh auth tokens."
|
13
|
+
)
|
14
|
+
JWT_TOKEN_CACHE_EXPIRY: int = 300 # seconds
|
15
|
+
|
16
|
+
|
17
|
+
def _run_auth(
|
18
|
+
client: httpx.Client,
|
19
|
+
auth_type: AuthType = AuthType.API_KEY,
|
20
|
+
api_key: str | None = None,
|
21
|
+
jwt: str | None = None,
|
22
|
+
) -> str:
|
23
|
+
auth_payload: APIKeyPayload | None
|
24
|
+
if auth_type == AuthType.API_KEY:
|
25
|
+
auth_payload = APIKeyPayload(api_key=api_key)
|
26
|
+
elif auth_type == AuthType.JWT:
|
27
|
+
auth_payload = None
|
28
|
+
try:
|
29
|
+
if auth_payload:
|
30
|
+
response = client.post("/auth/login", json=auth_payload.model_dump())
|
31
|
+
response.raise_for_status()
|
32
|
+
token_data = response.json()
|
33
|
+
elif jwt:
|
34
|
+
token_data = {"access_token": jwt, "expires_in": JWT_TOKEN_CACHE_EXPIRY}
|
35
|
+
else:
|
36
|
+
raise ValueError("JWT token required for JWT authentication.")
|
37
|
+
|
38
|
+
return token_data["access_token"]
|
39
|
+
except Exception as e:
|
40
|
+
raise Exception("Failed to authenticate") from e # noqa: TRY002
|
41
|
+
|
42
|
+
|
43
|
+
class RefreshingJWT(httpx.Auth):
|
44
|
+
"""Automatically (re-)inject a JWT and transparently retry exactly once when we hit a 401/403."""
|
45
|
+
|
46
|
+
RETRY_STATUSES: ClassVar[Collection[httpx.codes]] = {
|
47
|
+
httpx.codes.UNAUTHORIZED,
|
48
|
+
httpx.codes.FORBIDDEN,
|
49
|
+
}
|
50
|
+
|
51
|
+
def __init__(
|
52
|
+
self,
|
53
|
+
auth_client: httpx.Client,
|
54
|
+
auth_type: AuthType = AuthType.API_KEY,
|
55
|
+
api_key: str | None = None,
|
56
|
+
jwt: str | None = None,
|
57
|
+
):
|
58
|
+
self.auth_type = auth_type
|
59
|
+
self.auth_client = auth_client
|
60
|
+
self.api_key = api_key
|
61
|
+
self._jwt = _run_auth(
|
62
|
+
client=auth_client,
|
63
|
+
jwt=jwt,
|
64
|
+
auth_type=auth_type,
|
65
|
+
api_key=api_key,
|
66
|
+
)
|
67
|
+
|
68
|
+
def refresh_token(self) -> None:
|
69
|
+
if self.auth_type == AuthType.JWT:
|
70
|
+
logger.error(INVALID_REFRESH_TYPE_MSG)
|
71
|
+
raise ValueError(INVALID_REFRESH_TYPE_MSG)
|
72
|
+
self._jwt = _run_auth(
|
73
|
+
client=self.auth_client,
|
74
|
+
auth_type=self.auth_type,
|
75
|
+
api_key=self.api_key,
|
76
|
+
)
|
77
|
+
|
78
|
+
def auth_flow(
|
79
|
+
self, request: httpx.Request
|
80
|
+
) -> Generator[httpx.Request, httpx.Response, None]:
|
81
|
+
request.headers["Authorization"] = f"Bearer {self._jwt}"
|
82
|
+
response = yield request
|
83
|
+
|
84
|
+
# If it failed, refresh once and replay the request
|
85
|
+
if response.status_code in self.RETRY_STATUSES:
|
86
|
+
logger.info(
|
87
|
+
"Received %s, refreshing token and retrying …",
|
88
|
+
response.status_code,
|
89
|
+
)
|
90
|
+
self.refresh_token()
|
91
|
+
request.headers["Authorization"] = f"Bearer {self._jwt}"
|
92
|
+
yield request # second (and final) attempt, again or use a while loop
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import asyncio
|
2
|
+
from collections.abc import Awaitable, Iterable
|
3
|
+
from typing import TypeVar
|
4
|
+
|
5
|
+
from tqdm.asyncio import tqdm
|
6
|
+
|
7
|
+
T = TypeVar("T")
|
8
|
+
|
9
|
+
|
10
|
+
async def gather_with_concurrency(
|
11
|
+
n: int | asyncio.Semaphore, coros: Iterable[Awaitable[T]], progress: bool = False
|
12
|
+
) -> list[T]:
|
13
|
+
"""
|
14
|
+
Run asyncio.gather with a concurrency limit.
|
15
|
+
|
16
|
+
SEE: https://stackoverflow.com/a/61478547/2392535
|
17
|
+
"""
|
18
|
+
semaphore = asyncio.Semaphore(n) if isinstance(n, int) else n
|
19
|
+
|
20
|
+
async def sem_coro(coro: Awaitable[T]) -> T:
|
21
|
+
async with semaphore:
|
22
|
+
return await coro
|
23
|
+
|
24
|
+
if progress:
|
25
|
+
return await tqdm.gather(
|
26
|
+
*(sem_coro(c) for c in coros), desc="Gathering", ncols=0
|
27
|
+
)
|
28
|
+
|
29
|
+
return await asyncio.gather(*(sem_coro(c) for c in coros))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: futurehouse-client
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.18
|
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,17 @@
|
|
1
|
+
futurehouse_client/__init__.py,sha256=ddxO7JE97c6bt7LjNglZZ2Ql8bYCGI9laSFeh9MP6VU,344
|
2
|
+
futurehouse_client/clients/__init__.py,sha256=tFWqwIAY5PvwfOVsCje4imjTpf6xXNRMh_UHIKVI1_0,320
|
3
|
+
futurehouse_client/clients/job_client.py,sha256=uNkqQbeZw7wbA0qDWcIOwOykrosza-jev58paJZ_mbA,11150
|
4
|
+
futurehouse_client/clients/rest_client.py,sha256=CwgyjYj-i6U0aVXb1GkxP6KSxR5tVrlXIDE9WIHYtds,43435
|
5
|
+
futurehouse_client/models/__init__.py,sha256=5x-f9AoM1hGzJBEHcHAXSt7tPeImST5oZLuMdwp0mXc,554
|
6
|
+
futurehouse_client/models/app.py,sha256=24lCnpOtxQNzvcc1HJyP62wfertvTuZ30sX_vrBCUnk,26611
|
7
|
+
futurehouse_client/models/client.py,sha256=n4HD0KStKLm6Ek9nL9ylP-bkK10yzAaD1uIDF83Qp_A,1828
|
8
|
+
futurehouse_client/models/rest.py,sha256=lgwkMIXz0af-49BYSkKeS7SRqvN3motqnAikDN4YGTc,789
|
9
|
+
futurehouse_client/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
futurehouse_client/utils/auth.py,sha256=tgWELjKfg8eWme_qdcRmc8TjQN9DVZuHHaVXZNHLchk,2960
|
11
|
+
futurehouse_client/utils/general.py,sha256=A_rtTiYW30ELGEZlWCIArO7q1nEmqi8hUlmBRYkMQ_c,767
|
12
|
+
futurehouse_client/utils/module_utils.py,sha256=aFyd-X-pDARXz9GWpn8SSViUVYdSbuy9vSkrzcVIaGI,4955
|
13
|
+
futurehouse_client/utils/monitoring.py,sha256=UjRlufe67kI3VxRHOd5fLtJmlCbVA2Wqwpd4uZhXkQM,8728
|
14
|
+
futurehouse_client-0.3.18.dist-info/METADATA,sha256=AJVzzXq77PTe-Hg31YXy-KWFAb5IXiZhyC08YlbRec4,12760
|
15
|
+
futurehouse_client-0.3.18.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
16
|
+
futurehouse_client-0.3.18.dist-info/top_level.txt,sha256=TRuLUCt_qBnggdFHCX4O_BoCu1j2X43lKfIZC-ElwWY,19
|
17
|
+
futurehouse_client-0.3.18.dist-info/RECORD,,
|
@@ -1,15 +0,0 @@
|
|
1
|
-
futurehouse_client/__init__.py,sha256=ddxO7JE97c6bt7LjNglZZ2Ql8bYCGI9laSFeh9MP6VU,344
|
2
|
-
futurehouse_client/clients/__init__.py,sha256=tFWqwIAY5PvwfOVsCje4imjTpf6xXNRMh_UHIKVI1_0,320
|
3
|
-
futurehouse_client/clients/job_client.py,sha256=Fi3YvN4k82AuXCe8vlwxhkK8CXS164NQrs7paj9qIek,11096
|
4
|
-
futurehouse_client/clients/rest_client.py,sha256=OBJeRSQezd2BSJGHKQZ4Cg1uhThtOKwgBOSEDI4n0go,36181
|
5
|
-
futurehouse_client/models/__init__.py,sha256=ta3jFLM_LsDz1rKDmx8rja8sT7WtSKoFvMgLF0yFpvA,342
|
6
|
-
futurehouse_client/models/app.py,sha256=yfZ9tyw4VATVAfYrU7aTdCNPSljLEho09_nIbh8oZDY,23174
|
7
|
-
futurehouse_client/models/client.py,sha256=n4HD0KStKLm6Ek9nL9ylP-bkK10yzAaD1uIDF83Qp_A,1828
|
8
|
-
futurehouse_client/models/rest.py,sha256=W-wNFTN7HALYFFphw-RQYRMm6_TSa1cl4T-mZ1msk90,393
|
9
|
-
futurehouse_client/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
futurehouse_client/utils/module_utils.py,sha256=aFyd-X-pDARXz9GWpn8SSViUVYdSbuy9vSkrzcVIaGI,4955
|
11
|
-
futurehouse_client/utils/monitoring.py,sha256=UjRlufe67kI3VxRHOd5fLtJmlCbVA2Wqwpd4uZhXkQM,8728
|
12
|
-
futurehouse_client-0.3.17.dev56.dist-info/METADATA,sha256=KZWJ9eKHsx4-VjrG_O-dB__TqrIK-jeU5kcNHfKPoaI,8181
|
13
|
-
futurehouse_client-0.3.17.dev56.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
14
|
-
futurehouse_client-0.3.17.dev56.dist-info/top_level.txt,sha256=TRuLUCt_qBnggdFHCX4O_BoCu1j2X43lKfIZC-ElwWY,19
|
15
|
-
futurehouse_client-0.3.17.dev56.dist-info/RECORD,,
|
{futurehouse_client-0.3.17.dev56.dist-info → futurehouse_client-0.3.18.dist-info}/top_level.txt
RENAMED
File without changes
|