naas-abi 1.0.0__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.
- naas_abi/__init__.py +35 -0
- naas_abi/agents/AbiAgent.py +442 -0
- naas_abi/agents/AbiAgent_test.py +157 -0
- naas_abi/agents/EntitytoSPARQLAgent.py +952 -0
- naas_abi/agents/EntitytoSPARQLAgent_test.py +66 -0
- naas_abi/agents/KnowledgeGraphBuilderAgent.py +321 -0
- naas_abi/agents/KnowledgeGraphBuilderAgent_test.py +86 -0
- naas_abi/agents/OntologyEngineerAgent.py +115 -0
- naas_abi/agents/OntologyEngineerAgent_test.py +42 -0
- naas_abi/apps/oxigraph_admin/main.py +392 -0
- naas_abi/apps/oxigraph_admin/terminal_style.py +151 -0
- naas_abi/apps/sparql_terminal/main.py +68 -0
- naas_abi/apps/sparql_terminal/terminal_style.py +236 -0
- naas_abi/apps/terminal_agent/main.py +553 -0
- naas_abi/apps/terminal_agent/terminal_style.py +175 -0
- naas_abi/cli.py +714 -0
- naas_abi/mappings.py +83 -0
- naas_abi/models/airgap_gemma.py +220 -0
- naas_abi/models/airgap_qwen.py +24 -0
- naas_abi/models/default.py +23 -0
- naas_abi/models/gpt_4_1.py +25 -0
- naas_abi/pipelines/AIAgentOntologyGenerationPipeline.py +635 -0
- naas_abi/pipelines/AIAgentOntologyGenerationPipeline_test.py +133 -0
- naas_abi/pipelines/AddIndividualPipeline.py +215 -0
- naas_abi/pipelines/AddIndividualPipeline_test.py +66 -0
- naas_abi/pipelines/InsertDataSPARQLPipeline.py +197 -0
- naas_abi/pipelines/InsertDataSPARQLPipeline_test.py +96 -0
- naas_abi/pipelines/MergeIndividualsPipeline.py +245 -0
- naas_abi/pipelines/MergeIndividualsPipeline_test.py +98 -0
- naas_abi/pipelines/RemoveIndividualPipeline.py +166 -0
- naas_abi/pipelines/RemoveIndividualPipeline_test.py +58 -0
- naas_abi/pipelines/UpdateCommercialOrganizationPipeline.py +198 -0
- naas_abi/pipelines/UpdateDataPropertyPipeline.py +175 -0
- naas_abi/pipelines/UpdateLegalNamePipeline.py +107 -0
- naas_abi/pipelines/UpdateLinkedInPagePipeline.py +179 -0
- naas_abi/pipelines/UpdatePersonPipeline.py +184 -0
- naas_abi/pipelines/UpdateSkillPipeline.py +118 -0
- naas_abi/pipelines/UpdateTickerPipeline.py +104 -0
- naas_abi/pipelines/UpdateWebsitePipeline.py +106 -0
- naas_abi/triggers.py +131 -0
- naas_abi/workflows/AgentRecommendationWorkflow.py +321 -0
- naas_abi/workflows/AgentRecommendationWorkflow_test.py +160 -0
- naas_abi/workflows/ArtificialAnalysisWorkflow.py +337 -0
- naas_abi/workflows/ArtificialAnalysisWorkflow_test.py +57 -0
- naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow.py +210 -0
- naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow_test.py +78 -0
- naas_abi/workflows/CreateClassOntologyYamlWorkflow.py +208 -0
- naas_abi/workflows/CreateClassOntologyYamlWorkflow_test.py +65 -0
- naas_abi/workflows/CreateIndividualOntologyYamlWorkflow.py +183 -0
- naas_abi/workflows/CreateIndividualOntologyYamlWorkflow_test.py +86 -0
- naas_abi/workflows/ExportGraphInstancesToExcelWorkflow.py +450 -0
- naas_abi/workflows/ExportGraphInstancesToExcelWorkflow_test.py +33 -0
- naas_abi/workflows/GetObjectPropertiesFromClassWorkflow.py +385 -0
- naas_abi/workflows/GetObjectPropertiesFromClassWorkflow_test.py +57 -0
- naas_abi/workflows/GetSubjectGraphWorkflow.py +84 -0
- naas_abi/workflows/GetSubjectGraphWorkflow_test.py +71 -0
- naas_abi/workflows/SearchIndividualWorkflow.py +190 -0
- naas_abi/workflows/SearchIndividualWorkflow_test.py +98 -0
- naas_abi-1.0.0.dist-info/METADATA +9 -0
- naas_abi-1.0.0.dist-info/RECORD +62 -0
- naas_abi-1.0.0.dist-info/WHEEL +5 -0
- naas_abi-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.markdown import Markdown
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
from rich.syntax import Syntax
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
from rich.box import ROUNDED
|
|
7
|
+
from PIL import Image
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def set_terminal_title():
|
|
16
|
+
"""Set the terminal title to 'ABI'"""
|
|
17
|
+
if platform.system() == "Windows":
|
|
18
|
+
os.system("title ABI")
|
|
19
|
+
else: # For Unix-like systems (Linux, macOS)
|
|
20
|
+
print("\33]0;ABI\a", end="", flush=True)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def print_agent_response(text, agent_label):
|
|
24
|
+
console.print() # Add a blank line before the assistant's response
|
|
25
|
+
console.print(f"[bold green]{agent_label}:[/bold green] ", end="")
|
|
26
|
+
md = Markdown(text)
|
|
27
|
+
console.print(md)
|
|
28
|
+
console.print() # Add a blank line after the assistant's response
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def print_system_message(text):
|
|
32
|
+
console.print() # Add a blank line before the system message
|
|
33
|
+
system_text = Text(text, style="yellow")
|
|
34
|
+
console.print(
|
|
35
|
+
Panel(
|
|
36
|
+
system_text,
|
|
37
|
+
border_style="yellow",
|
|
38
|
+
box=ROUNDED,
|
|
39
|
+
expand=False,
|
|
40
|
+
title="System",
|
|
41
|
+
title_align="left",
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
console.print() # Add a blank line after the system message
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def print_code(code, language="python"):
|
|
48
|
+
syntax = Syntax(code, language, theme="monokai", line_numbers=True)
|
|
49
|
+
console.print(
|
|
50
|
+
Panel(
|
|
51
|
+
syntax,
|
|
52
|
+
border_style="red",
|
|
53
|
+
box=ROUNDED,
|
|
54
|
+
expand=False,
|
|
55
|
+
title=f"Code ({language})",
|
|
56
|
+
title_align="left",
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def dict_to_equal_string(d: dict) -> str:
|
|
62
|
+
return "\n".join([f'-{key}="{value}"' for key, value in d.items()])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def print_tool_usage(message):
|
|
66
|
+
print_message = ""
|
|
67
|
+
tool_name = message.tool_calls[0]["name"]
|
|
68
|
+
arguments = ""
|
|
69
|
+
if (
|
|
70
|
+
"args" in message.tool_calls[0]
|
|
71
|
+
and len(message.tool_calls[0]["args"].values()) > 0
|
|
72
|
+
):
|
|
73
|
+
arguments += dict_to_equal_string(message.tool_calls[0]["args"])
|
|
74
|
+
|
|
75
|
+
if tool_name.startswith("transfer_to_"):
|
|
76
|
+
tool_label = " ".join(
|
|
77
|
+
word.capitalize()
|
|
78
|
+
for word in tool_name.split("transfer_to_")[1].replace("_", " ").split()
|
|
79
|
+
)
|
|
80
|
+
print_message = f"\n🧞 [bold blue]Delegated to [/bold blue]{tool_label}"
|
|
81
|
+
else:
|
|
82
|
+
tool_label = tool_name.capitalize().replace("_", " ")
|
|
83
|
+
print_message = f"\n[bold blue]Tool Used:[/bold blue] {tool_label}\n{arguments}"
|
|
84
|
+
console.print(print_message)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def print_tool_response(response):
|
|
88
|
+
console.print(f"\n[bold blue]Response:[/bold blue] {response}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def clear_screen():
|
|
92
|
+
console.clear()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def print_welcome_message(agent):
|
|
96
|
+
# Set terminal title
|
|
97
|
+
set_terminal_title()
|
|
98
|
+
|
|
99
|
+
# Skip the welcome - we already said hello in the CLI startup
|
|
100
|
+
# Just quietly start the conversation
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def print_divider():
|
|
105
|
+
console.print("─" * console.width, style="dim")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def get_user_input(agent_label):
|
|
109
|
+
try:
|
|
110
|
+
user_input = console.input(
|
|
111
|
+
"\n[bold cyan]You:[/bold cyan] "
|
|
112
|
+
) # Add a newline before the prompt
|
|
113
|
+
console.print() # Add a blank line after the user's input
|
|
114
|
+
return user_input
|
|
115
|
+
except EOFError:
|
|
116
|
+
console.print(
|
|
117
|
+
f"\n[bold red]{agent_label}:[/bold red] Conversation ended by user."
|
|
118
|
+
)
|
|
119
|
+
return "exit"
|
|
120
|
+
except KeyboardInterrupt:
|
|
121
|
+
console.print(
|
|
122
|
+
f"\n[bold red]{agent_label}:[/bold red] Conversation ended by user."
|
|
123
|
+
)
|
|
124
|
+
return "exit"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def print_image(image_path: str):
|
|
128
|
+
"""Display an image in the terminal."""
|
|
129
|
+
try:
|
|
130
|
+
console.print() # Add some spacing
|
|
131
|
+
|
|
132
|
+
# Display the file path and viewing instructions
|
|
133
|
+
message = (
|
|
134
|
+
f"[yellow]Image saved at: {image_path}[/yellow]\n\n"
|
|
135
|
+
"[dim]To view the image:[/dim]\n"
|
|
136
|
+
f"[cyan]• Local system: Open {image_path} with your image viewer[/cyan]\n"
|
|
137
|
+
"[cyan]• Remote/SSH: Download the file to your local machine to view[/cyan]"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
console.print(
|
|
141
|
+
Panel(
|
|
142
|
+
message,
|
|
143
|
+
border_style="yellow",
|
|
144
|
+
box=ROUNDED,
|
|
145
|
+
expand=False,
|
|
146
|
+
title="Graph Output",
|
|
147
|
+
title_align="left",
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Only try to show the image if we're in a GUI environment
|
|
152
|
+
if os.environ.get("DISPLAY") and platform.system() != "Windows":
|
|
153
|
+
try:
|
|
154
|
+
img = Image.open(image_path)
|
|
155
|
+
img.show()
|
|
156
|
+
except Exception:
|
|
157
|
+
pass # Silently fail if we can't display the image
|
|
158
|
+
elif platform.system() == "Windows":
|
|
159
|
+
try:
|
|
160
|
+
subprocess.run(['start', '', image_path], shell=True) # Windows-specific file opening
|
|
161
|
+
except Exception:
|
|
162
|
+
pass
|
|
163
|
+
|
|
164
|
+
console.print() # Add some spacing after
|
|
165
|
+
except Exception as e:
|
|
166
|
+
console.print(
|
|
167
|
+
Panel(
|
|
168
|
+
f"[yellow]Unable to process image. File saved at: {image_path}[/yellow]\nError: {str(e)}",
|
|
169
|
+
border_style="yellow",
|
|
170
|
+
box=ROUNDED,
|
|
171
|
+
expand=False,
|
|
172
|
+
title="Graph Output",
|
|
173
|
+
title_align="left",
|
|
174
|
+
)
|
|
175
|
+
)
|