hyperforge-http 1.0.0.post19__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.
- hyperforge_http/__init__.py +3 -0
- hyperforge_http/agent.py +104 -0
- hyperforge_http/config.py +36 -0
- hyperforge_http-1.0.0.post19.dist-info/METADATA +19 -0
- hyperforge_http-1.0.0.post19.dist-info/RECORD +7 -0
- hyperforge_http-1.0.0.post19.dist-info/WHEEL +5 -0
- hyperforge_http-1.0.0.post19.dist-info/top_level.txt +1 -0
hyperforge_http/agent.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from time import time
|
|
2
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from hyperforge.agent import Agent
|
|
6
|
+
from hyperforge.configure import agent
|
|
7
|
+
from hyperforge.context.agent import ContextAgent
|
|
8
|
+
from hyperforge.manager import Manager
|
|
9
|
+
from hyperforge.memory import Chunk, Context, QuestionMemory
|
|
10
|
+
from hyperforge.utils import check_dns
|
|
11
|
+
from hyperforge.utils.http import safe_http_client
|
|
12
|
+
|
|
13
|
+
from hyperforge_http.config import HTTPStaticAgentConfig
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@agent(
|
|
17
|
+
id="http",
|
|
18
|
+
agent_type="context",
|
|
19
|
+
title="HTTP Static",
|
|
20
|
+
description="Use HTTP Static to get information from the internet to answer questions.",
|
|
21
|
+
config_schema=HTTPStaticAgentConfig,
|
|
22
|
+
)
|
|
23
|
+
class HTTPStaticAgent(ContextAgent, Agent[HTTPStaticAgentConfig]):
|
|
24
|
+
async def _get_question_context(
|
|
25
|
+
self,
|
|
26
|
+
memory: QuestionMemory,
|
|
27
|
+
manager: Manager,
|
|
28
|
+
question_uuid: str,
|
|
29
|
+
question: str,
|
|
30
|
+
flow_id: str,
|
|
31
|
+
extra_context: Optional[Dict[str, Any]] = None,
|
|
32
|
+
) -> List[Tuple[str, str]]:
|
|
33
|
+
t0 = time()
|
|
34
|
+
error = None
|
|
35
|
+
|
|
36
|
+
url = await check_dns(self.config.url)
|
|
37
|
+
|
|
38
|
+
async with safe_http_client() as client:
|
|
39
|
+
if self.config.method == "GET":
|
|
40
|
+
response = await client.get(
|
|
41
|
+
url,
|
|
42
|
+
headers=self.config.headers,
|
|
43
|
+
timeout=self.config.timeout,
|
|
44
|
+
params={self.config.question_query_param: question}
|
|
45
|
+
if self.config.question_query_param
|
|
46
|
+
else None,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
elif self.config.method == "POST":
|
|
50
|
+
response = await client.post(
|
|
51
|
+
url,
|
|
52
|
+
headers=self.config.headers,
|
|
53
|
+
timeout=self.config.timeout,
|
|
54
|
+
params={self.config.question_query_param: question}
|
|
55
|
+
if self.config.question_query_param
|
|
56
|
+
else None,
|
|
57
|
+
data={self.config.question_post_field: question}
|
|
58
|
+
if self.config.question_post_field
|
|
59
|
+
else None,
|
|
60
|
+
)
|
|
61
|
+
else:
|
|
62
|
+
raise ValueError(f"Unsupported HTTP method: {self.config.method}")
|
|
63
|
+
|
|
64
|
+
if response.status_code != 200:
|
|
65
|
+
error = f"HTTP request failed with status code {response.status_code}"
|
|
66
|
+
context_text = ""
|
|
67
|
+
else:
|
|
68
|
+
context_text = response.content.decode("utf-8")
|
|
69
|
+
|
|
70
|
+
context = Context(
|
|
71
|
+
agent_id=self.config.id if self.config.id else "http",
|
|
72
|
+
original_question_uuid=memory.original_question_uuid,
|
|
73
|
+
actual_question_uuid=question_uuid,
|
|
74
|
+
question=question,
|
|
75
|
+
source="http",
|
|
76
|
+
agent="http",
|
|
77
|
+
title=self.config.title if self.config.title else "HTTP Call",
|
|
78
|
+
)
|
|
79
|
+
context.chunks.append(
|
|
80
|
+
Chunk(
|
|
81
|
+
chunk_id=uuid4().hex,
|
|
82
|
+
text=context_text,
|
|
83
|
+
origin_agent=self.config.module,
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
await memory.add_step(
|
|
88
|
+
step_module=self.config.module,
|
|
89
|
+
step_title=self.step_title("HTTP request"),
|
|
90
|
+
step_agent_path=f"/context/{self.config.id if self.config.id else 'default'}",
|
|
91
|
+
step_value=f" HTTP {self.config.method} to {url}",
|
|
92
|
+
timeit=time() - t0,
|
|
93
|
+
input_nuclia_tokens=0,
|
|
94
|
+
output_nuclia_tokens=0,
|
|
95
|
+
error=error,
|
|
96
|
+
)
|
|
97
|
+
missing = await self.save_ctx_and_return_missing(
|
|
98
|
+
context=context,
|
|
99
|
+
question=question,
|
|
100
|
+
memory=memory,
|
|
101
|
+
manager=manager,
|
|
102
|
+
flow_id=flow_id,
|
|
103
|
+
)
|
|
104
|
+
return [missing] if missing is not None else []
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
3
|
+
from hyperforge.context.agent import ContextAgentConfig
|
|
4
|
+
from hyperforge.utils import WidgetType, sync_dns_validation
|
|
5
|
+
from pydantic import Field, field_validator
|
|
6
|
+
from pydantic.config import ConfigDict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HTTPStaticAgentConfig(ContextAgentConfig):
|
|
10
|
+
model_config = ConfigDict(title="HTTP call")
|
|
11
|
+
module: Literal["http"] = "http"
|
|
12
|
+
method: Literal["GET", "POST"] = Field(
|
|
13
|
+
default="GET", description="HTTP method to use for the request"
|
|
14
|
+
)
|
|
15
|
+
url: str = Field(..., description="The URL to fetch context from")
|
|
16
|
+
|
|
17
|
+
headers: dict[str, str] = Field(
|
|
18
|
+
default_factory=dict,
|
|
19
|
+
description="Optional headers to include in the HTTP request",
|
|
20
|
+
json_schema_extra={"widget": WidgetType.KEY_VALUE_FIELD},
|
|
21
|
+
)
|
|
22
|
+
question_query_param: Optional[str] = Field(
|
|
23
|
+
None,
|
|
24
|
+
description="Optional query parameter to include the question in the request",
|
|
25
|
+
)
|
|
26
|
+
question_post_field: Optional[str] = Field(
|
|
27
|
+
None,
|
|
28
|
+
description="Optional POST field id to include the question in the request body",
|
|
29
|
+
)
|
|
30
|
+
timeout: int = Field(
|
|
31
|
+
default=10, description="Timeout for the HTTP request in seconds"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
@field_validator("url")
|
|
35
|
+
def validate_url(cls, v):
|
|
36
|
+
return sync_dns_validation(v)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyperforge_http
|
|
3
|
+
Version: 1.0.0.post19
|
|
4
|
+
Summary: HTTP Hyperforge agent
|
|
5
|
+
Author-email: Nuclia <nucliadb@nuclia.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://progress.com
|
|
8
|
+
Project-URL: Repository, https://github.com/nuclia/forge
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: <4,>=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: hyperforge
|
|
18
|
+
|
|
19
|
+
# HTTP Static Hyperforge agents
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
hyperforge_http/__init__.py,sha256=vWIsEjujY8mKH3jhBJz6UKjHM3aHVyq1TBkn_iQxlCM,66
|
|
2
|
+
hyperforge_http/agent.py,sha256=TiTCN6znoXlwycjc5VWyCzBQIChhzcSZ3w4wKQxk4q4,3692
|
|
3
|
+
hyperforge_http/config.py,sha256=1vidNJAJGR_xVgk32Jv48jGX_zAvSlXNdhtnQXgfH0o,1296
|
|
4
|
+
hyperforge_http-1.0.0.post19.dist-info/METADATA,sha256=TAabWU3-9hIgHfZk0StaYUNHf87nx2gmka_31-_MZCE,723
|
|
5
|
+
hyperforge_http-1.0.0.post19.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
hyperforge_http-1.0.0.post19.dist-info/top_level.txt,sha256=L2wPsat-N3TFvF5N5ePV5_OlYXEs9yjT76DemW67wCE,16
|
|
7
|
+
hyperforge_http-1.0.0.post19.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyperforge_http
|