hyperforge-generate 1.0.0.post24__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_generate/__init__.py +0 -0
- hyperforge_generate/agent.py +101 -0
- hyperforge_generate/config.py +26 -0
- hyperforge_generate-1.0.0.post24.dist-info/METADATA +19 -0
- hyperforge_generate-1.0.0.post24.dist-info/RECORD +7 -0
- hyperforge_generate-1.0.0.post24.dist-info/WHEEL +5 -0
- hyperforge_generate-1.0.0.post24.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from time import time
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
from hyperforge.agent import Agent
|
|
5
|
+
from hyperforge.configure import agent
|
|
6
|
+
from hyperforge.manager import Manager
|
|
7
|
+
from hyperforge.memory import QuestionMemory
|
|
8
|
+
from hyperforge.trace import trace_agent
|
|
9
|
+
from nuclia.lib.nua_responses import ChatModel, UserPrompt
|
|
10
|
+
|
|
11
|
+
from hyperforge import PROMPT_ENVIRONMENT
|
|
12
|
+
from hyperforge_generate.config import GenerateAgentConfig
|
|
13
|
+
|
|
14
|
+
GENERATE_PROMPT = """
|
|
15
|
+
Generate the following request using **only** the provided context. Refrain from incorporating any outside knowledge. If the context is insufficient to answer the question comprehensively, respond with: "Not enough data to generate this."
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
{% if rules -%}
|
|
19
|
+
# Generation Rules
|
|
20
|
+
{% for rule in rules -%}
|
|
21
|
+
- {{rule}}
|
|
22
|
+
{% endfor -%}
|
|
23
|
+
{% endif -%}
|
|
24
|
+
|
|
25
|
+
{{prompt}}
|
|
26
|
+
|
|
27
|
+
{{context}}
|
|
28
|
+
|
|
29
|
+
MAIN QUESTION: {{question}}
|
|
30
|
+
|
|
31
|
+
# Notes
|
|
32
|
+
- Use the context provided without being overly selective.
|
|
33
|
+
- Please try to generate if possible, even if it requires to make a bit of a deduction.
|
|
34
|
+
- If they are images attached, look through them carefully.
|
|
35
|
+
- For rules related to charts or images, pay extra attention to extracting details and interpreting data presented visually. Think about it carefully before giving inaccurate interpretations
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
GENERATE_PROMPT_TEMPLATE = PROMPT_ENVIRONMENT.from_string(GENERATE_PROMPT)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@agent(
|
|
43
|
+
id="generate",
|
|
44
|
+
agent_type="generation",
|
|
45
|
+
title="Generate Answer",
|
|
46
|
+
description="Generate answers based on provided context.",
|
|
47
|
+
config_schema=GenerateAgentConfig,
|
|
48
|
+
)
|
|
49
|
+
class GenerateAgent(Agent[GenerateAgentConfig]):
|
|
50
|
+
__root_agent__ = True
|
|
51
|
+
|
|
52
|
+
@trace_agent
|
|
53
|
+
async def __call__(
|
|
54
|
+
self,
|
|
55
|
+
memory: QuestionMemory,
|
|
56
|
+
manager: Manager,
|
|
57
|
+
):
|
|
58
|
+
# For each context in memory add context query, summary and answer onto a text and the initial question
|
|
59
|
+
prompt = GENERATE_PROMPT_TEMPLATE.render(
|
|
60
|
+
question=memory.original_question,
|
|
61
|
+
context=memory.contexts_minimal(),
|
|
62
|
+
prompt=self.config.prompt,
|
|
63
|
+
rules=memory.generation_rules,
|
|
64
|
+
)
|
|
65
|
+
t0 = time()
|
|
66
|
+
|
|
67
|
+
chat_model = ChatModel(
|
|
68
|
+
user_id="generate",
|
|
69
|
+
question="",
|
|
70
|
+
user_prompt=UserPrompt(prompt=prompt),
|
|
71
|
+
format_prompt=False,
|
|
72
|
+
generative_model=self.config.model,
|
|
73
|
+
max_tokens=2000,
|
|
74
|
+
tracking=memory.get_tracking_info(),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
agent_path = f"/generation/{self.config.id if self.config.id else 'default'}"
|
|
78
|
+
resp, input_tokens, output_tokens = await manager.execute_raw(
|
|
79
|
+
chat_model, memory=memory, module="generate", agent_path=agent_path
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
generated_text = resp.answer or ""
|
|
83
|
+
|
|
84
|
+
memory.generated_texts[uuid4().hex] = generated_text
|
|
85
|
+
|
|
86
|
+
await memory.add_generated_text(
|
|
87
|
+
self.config.id if self.config.id else "default", generated_text
|
|
88
|
+
)
|
|
89
|
+
# We assume that JSON generation always produces an answer
|
|
90
|
+
memory.is_answered = True
|
|
91
|
+
|
|
92
|
+
await memory.add_step(
|
|
93
|
+
step_module=self.config.module,
|
|
94
|
+
step_title=self.step_title("Generate"),
|
|
95
|
+
step_value="",
|
|
96
|
+
step_reason="",
|
|
97
|
+
step_agent_path=agent_path,
|
|
98
|
+
timeit=time() - t0,
|
|
99
|
+
input_nuclia_tokens=input_tokens,
|
|
100
|
+
output_nuclia_tokens=output_tokens,
|
|
101
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
3
|
+
from hyperforge.agent import AgentConfig
|
|
4
|
+
from hyperforge.utils import WidgetType
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from pydantic.config import ConfigDict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GenerateAgentConfig(AgentConfig):
|
|
10
|
+
model_config = ConfigDict(title="Generate")
|
|
11
|
+
module: Literal["generate"] = "generate"
|
|
12
|
+
prompt: Optional[str] = Field(
|
|
13
|
+
None,
|
|
14
|
+
json_schema_extra={
|
|
15
|
+
"show_in_node": True,
|
|
16
|
+
"widget": WidgetType.EXPANDABLE_TEXTAREA,
|
|
17
|
+
},
|
|
18
|
+
)
|
|
19
|
+
model: str = Field(
|
|
20
|
+
default="chatgpt-azure-4o-mini",
|
|
21
|
+
title="Generative model",
|
|
22
|
+
description="Model used to generate the response",
|
|
23
|
+
json_schema_extra={"widget": WidgetType.MODEL_SELECT},
|
|
24
|
+
)
|
|
25
|
+
images: bool = False
|
|
26
|
+
generate_image: bool = False
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyperforge_generate
|
|
3
|
+
Version: 1.0.0.post24
|
|
4
|
+
Summary: External 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
|
+
# Generate Hyperforge agents
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
hyperforge_generate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
hyperforge_generate/agent.py,sha256=OuMnJ1BpB5JO-KsP0dLgxuZvFe2wIMn8bJow7QW6sic,3317
|
|
3
|
+
hyperforge_generate/config.py,sha256=rREyYti3JU4wqur8fRz5vvJHgDIAYdRlkI1VVpyI9ng,787
|
|
4
|
+
hyperforge_generate-1.0.0.post24.dist-info/METADATA,sha256=Z_XuDciZ7POQZC_UJa42jskRcnwfmUshxwxUTTp4jFI,728
|
|
5
|
+
hyperforge_generate-1.0.0.post24.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
hyperforge_generate-1.0.0.post24.dist-info/top_level.txt,sha256=D83iCWoSgtfse_skPmV0EYOvF384aM1z_ti317LBiic,20
|
|
7
|
+
hyperforge_generate-1.0.0.post24.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyperforge_generate
|