hyperforge-http 1.0.0.post19__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.
- hyperforge_http-1.0.0.post19/PKG-INFO +19 -0
- hyperforge_http-1.0.0.post19/README.md +1 -0
- hyperforge_http-1.0.0.post19/pyproject.toml +40 -0
- hyperforge_http-1.0.0.post19/setup.cfg +4 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http/__init__.py +3 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http/agent.py +104 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http/config.py +36 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http.egg-info/PKG-INFO +19 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http.egg-info/SOURCES.txt +11 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http.egg-info/dependency_links.txt +1 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http.egg-info/requires.txt +1 -0
- hyperforge_http-1.0.0.post19/src/hyperforge_http.egg-info/top_level.txt +1 -0
- hyperforge_http-1.0.0.post19/tests/test_http_static.py +76 -0
|
@@ -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 @@
|
|
|
1
|
+
# HTTP Static Hyperforge agents
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hyperforge_http"
|
|
7
|
+
version = "1.0.0.post19"
|
|
8
|
+
license = "Apache-2.0"
|
|
9
|
+
description = "HTTP Hyperforge agent"
|
|
10
|
+
authors = [{ name = "Nuclia", email = "nucliadb@nuclia.com" }]
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python",
|
|
14
|
+
"Programming Language :: Python :: 3.10",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.10, <4"
|
|
21
|
+
dependencies = ["hyperforge"]
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
dev = [
|
|
25
|
+
"pytest",
|
|
26
|
+
"pytest-benchmark",
|
|
27
|
+
"pytest-docker-fixtures>=1.4.2",
|
|
28
|
+
"pytest-lazy-fixtures",
|
|
29
|
+
"pytest-recording",
|
|
30
|
+
"pytest-asyncio",
|
|
31
|
+
"pytest-cov",
|
|
32
|
+
"pytest-mock",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://progress.com"
|
|
37
|
+
Repository = "https://github.com/nuclia/forge"
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
asyncio_mode = "auto"
|
|
@@ -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,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/hyperforge_http/__init__.py
|
|
4
|
+
src/hyperforge_http/agent.py
|
|
5
|
+
src/hyperforge_http/config.py
|
|
6
|
+
src/hyperforge_http.egg-info/PKG-INFO
|
|
7
|
+
src/hyperforge_http.egg-info/SOURCES.txt
|
|
8
|
+
src/hyperforge_http.egg-info/dependency_links.txt
|
|
9
|
+
src/hyperforge_http.egg-info/requires.txt
|
|
10
|
+
src/hyperforge_http.egg-info/top_level.txt
|
|
11
|
+
tests/test_http_static.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyperforge
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyperforge_http
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
from hyperforge.engine import main as arag_main
|
|
6
|
+
from hyperforge.interaction import AragAnswer
|
|
7
|
+
from hyperforge.minimal_fixtures import cassette_nua_key
|
|
8
|
+
|
|
9
|
+
NUA_KEY = os.environ.get(
|
|
10
|
+
"NUA_KEY",
|
|
11
|
+
) or cassette_nua_key("https://europe-1.nuclia.cloud/")
|
|
12
|
+
|
|
13
|
+
CONFIG = {
|
|
14
|
+
"drivers": [],
|
|
15
|
+
"rules": {
|
|
16
|
+
"rules": [
|
|
17
|
+
{"prompt": "Be polite"},
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"memory": {},
|
|
21
|
+
"workflow": {
|
|
22
|
+
"id": "default",
|
|
23
|
+
"name": "Default workflow",
|
|
24
|
+
"description": "Default workflow for testing",
|
|
25
|
+
"parameters": {},
|
|
26
|
+
},
|
|
27
|
+
"preprocess": [],
|
|
28
|
+
"context": [
|
|
29
|
+
{
|
|
30
|
+
"module": "http",
|
|
31
|
+
"title": "HTTP Context",
|
|
32
|
+
"url": "https://example.com/context",
|
|
33
|
+
"method": "GET",
|
|
34
|
+
"question_query_param": "q",
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"generation": [
|
|
38
|
+
{"module": "summarize", "title": "Summarize agent"},
|
|
39
|
+
],
|
|
40
|
+
"postprocess": [],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.vcr
|
|
45
|
+
@pytest.mark.asyncio
|
|
46
|
+
async def test_http_static_get(mocker):
|
|
47
|
+
answers = []
|
|
48
|
+
|
|
49
|
+
mock_response = MagicMock()
|
|
50
|
+
mock_response.status_code = 200
|
|
51
|
+
mock_response.content = b"Experts from the University of Nuclia have found that waking up relaxed can be achieved by following a consistent sleep schedule, creating a calming bedtime routine, and ensuring a comfortable sleep environment. Also, if your alarm is a an BetterStack call, it will help you clear your mind"
|
|
52
|
+
|
|
53
|
+
mock_client = AsyncMock()
|
|
54
|
+
mock_client.get = AsyncMock(return_value=mock_response)
|
|
55
|
+
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
|
|
56
|
+
mock_client.__aexit__ = AsyncMock(return_value=None)
|
|
57
|
+
|
|
58
|
+
async def callback(obj: AragAnswer):
|
|
59
|
+
answers.append(obj)
|
|
60
|
+
|
|
61
|
+
mocker.patch(
|
|
62
|
+
"hyperforge.utils.http.safe_http_client",
|
|
63
|
+
return_value=mock_client,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
question_memory = await arag_main(
|
|
67
|
+
agent_id="default",
|
|
68
|
+
internal_nua=False,
|
|
69
|
+
external_nua_api_key=NUA_KEY,
|
|
70
|
+
question="What is the best way to wake up relaxed?",
|
|
71
|
+
config=CONFIG,
|
|
72
|
+
callback=callback,
|
|
73
|
+
loaded_modules=["hyperforge_http", "hyperforge_summarize"],
|
|
74
|
+
)
|
|
75
|
+
assert "BetterStack" in question_memory.final_answer
|
|
76
|
+
assert question_memory.final_answer is not None
|