semantio 0.0.2__tar.gz → 0.0.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {semantio-0.0.2 → semantio-0.0.3}/PKG-INFO +1 -1
- {semantio-0.0.2 → semantio-0.0.3}/semantio/agent.py +28 -28
- {semantio-0.0.2 → semantio-0.0.3}/semantio/cli/main.py +6 -6
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/PKG-INFO +1 -1
- {semantio-0.0.2 → semantio-0.0.3}/setup.py +1 -1
- {semantio-0.0.2 → semantio-0.0.3}/LICENSE +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/README.md +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/api/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/api/api_generator.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/api/fastapi_app.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/cli/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/knowledge_base/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/knowledge_base/document_loader.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/knowledge_base/retriever.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/knowledge_base/vector_store.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/anthropic.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/base_llm.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/deepseek.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/gemini.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/groq.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/mistral.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/llm/openai.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/memory.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/rag.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/storage/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/storage/cloud_storage.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/storage/local_storage.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/tools/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/tools/base_tool.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/tools/crypto.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/tools/duckduckgo.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/tools/stocks.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/__init__.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/config.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/date_utils.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/file_utils.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/logger.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio/utils/validation_utils.py +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/SOURCES.txt +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/dependency_links.txt +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/entry_points.txt +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/requires.txt +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/semantio.egg-info/top_level.txt +0 -0
- {semantio-0.0.2 → semantio-0.0.3}/setup.cfg +0 -0
@@ -21,24 +21,24 @@ import os
|
|
21
21
|
logging.basicConfig(level=logging.INFO)
|
22
22
|
logger = logging.getLogger(__name__)
|
23
23
|
|
24
|
-
class
|
24
|
+
class Agent(BaseModel):
|
25
25
|
# -*- Agent settings
|
26
|
-
name: Optional[str] = Field(None, description="Name of the
|
27
|
-
description: Optional[str] = Field(None, description="Description of the
|
28
|
-
instructions: Optional[List[str]] = Field(None, description="List of instructions for the
|
26
|
+
name: Optional[str] = Field(None, description="Name of the agent.")
|
27
|
+
description: Optional[str] = Field(None, description="Description of the agent's role.")
|
28
|
+
instructions: Optional[List[str]] = Field(None, description="List of instructions for the agent.")
|
29
29
|
model: Optional[str] = Field(None, description="This one is not in the use.")
|
30
30
|
show_tool_calls: bool = Field(False, description="Whether to show tool calls in the response.")
|
31
31
|
markdown: bool = Field(False, description="Whether to format the response in markdown.")
|
32
|
-
tools: Optional[List[BaseTool]] = Field(None, description="List of tools available to the
|
33
|
-
user_name: Optional[str] = Field("User", description="Name of the user interacting with the
|
34
|
-
emoji: Optional[str] = Field(":robot:", description="Emoji to represent the
|
32
|
+
tools: Optional[List[BaseTool]] = Field(None, description="List of tools available to the agent.")
|
33
|
+
user_name: Optional[str] = Field("User", description="Name of the user interacting with the agent.")
|
34
|
+
emoji: Optional[str] = Field(":robot:", description="Emoji to represent the agent in the CLI.")
|
35
35
|
rag: Optional[RAG] = Field(None, description="RAG instance for context retrieval.")
|
36
36
|
knowledge_base: Optional[Any] = Field(None, description="Knowledge base for domain-specific information.")
|
37
37
|
llm: Optional[str] = Field(None, description="The LLM provider to use (e.g., 'groq', 'openai', 'anthropic').")
|
38
38
|
llm_model: Optional[str] = Field(None, description="The specific model to use for the LLM provider.")
|
39
39
|
llm_instance: Optional[BaseLLM] = Field(None, description="The LLM instance to use.")
|
40
40
|
json_output: bool = Field(False, description="Whether to format the response as JSON.")
|
41
|
-
api: bool = Field(False, description="Whether to generate an API for the
|
41
|
+
api: bool = Field(False, description="Whether to generate an API for the agent.")
|
42
42
|
api_config: Optional[Dict] = Field(
|
43
43
|
None,
|
44
44
|
description="Configuration for the API (e.g., host, port, authentication).",
|
@@ -46,7 +46,7 @@ class Assistant(BaseModel):
|
|
46
46
|
api_generator: Optional[Any] = Field(None, description="The API generator instance.")
|
47
47
|
expected_output: Optional[Union[str, Dict]] = Field(None, description="The expected format or structure of the output.")
|
48
48
|
semantic_model: Optional[Any] = Field(None, description="SentenceTransformer model for semantic matching.")
|
49
|
-
team: Optional[List['
|
49
|
+
team: Optional[List['Agent']] = Field(None, description="List of assistants in the team.")
|
50
50
|
auto_tool: bool = Field(False, description="Whether to automatically detect and call tools.")
|
51
51
|
|
52
52
|
# Allow arbitrary types
|
@@ -125,7 +125,7 @@ class Assistant(BaseModel):
|
|
125
125
|
try:
|
126
126
|
# Import the module
|
127
127
|
module_name = file.stem
|
128
|
-
module = importlib.import_module(f"
|
128
|
+
module = importlib.import_module(f"semantio.tools.{module_name}")
|
129
129
|
|
130
130
|
# Find all classes that inherit from BaseTool
|
131
131
|
for name, obj in module.__dict__.items():
|
@@ -197,7 +197,7 @@ class Assistant(BaseModel):
|
|
197
197
|
model_to_use = self.llm_model or default_model
|
198
198
|
|
199
199
|
# Dynamically import and initialize the LLM class
|
200
|
-
module_name = f"
|
200
|
+
module_name = f"semantio.llm.{llm_provider}"
|
201
201
|
llm_module = importlib.import_module(module_name)
|
202
202
|
llm_class = getattr(llm_module, llm_class_name)
|
203
203
|
self.llm_instance = llm_class(model=model_to_use, api_key=api_key)
|
@@ -214,10 +214,10 @@ class Assistant(BaseModel):
|
|
214
214
|
stream: bool = False,
|
215
215
|
markdown: bool = False,
|
216
216
|
tools: Optional[List[BaseTool]] = None,
|
217
|
-
team: Optional[List['
|
217
|
+
team: Optional[List['Agent']] = None,
|
218
218
|
**kwargs,
|
219
219
|
) -> Union[str, Dict]: # Add return type hint
|
220
|
-
"""Print the
|
220
|
+
"""Print the agent's response to the console and return it."""
|
221
221
|
|
222
222
|
if stream:
|
223
223
|
# Handle streaming response
|
@@ -234,14 +234,14 @@ class Assistant(BaseModel):
|
|
234
234
|
|
235
235
|
|
236
236
|
def _stream_response(self, message: str, markdown: bool = False, **kwargs) -> Iterator[str]:
|
237
|
-
"""Stream the
|
237
|
+
"""Stream the agent's response."""
|
238
238
|
# Simulate streaming by yielding chunks of the response
|
239
239
|
response = self._generate_response(message, markdown=markdown, **kwargs)
|
240
240
|
for chunk in response.split():
|
241
241
|
yield chunk + " "
|
242
242
|
|
243
243
|
def register_tool(self, tool: BaseTool):
|
244
|
-
"""Register a tool for the
|
244
|
+
"""Register a tool for the agent."""
|
245
245
|
if self.tools is None:
|
246
246
|
self.tools = []
|
247
247
|
self.tools.append(tool)
|
@@ -256,7 +256,7 @@ class Assistant(BaseModel):
|
|
256
256
|
|
257
257
|
# Create a prompt for the LLM
|
258
258
|
prompt = f"""
|
259
|
-
You are an AI
|
259
|
+
You are an AI agent that helps users by selecting the most appropriate tool to answer their query. Below is a list of available tools and their functionalities:
|
260
260
|
|
261
261
|
{self._get_tool_descriptions()}
|
262
262
|
|
@@ -290,7 +290,7 @@ class Assistant(BaseModel):
|
|
290
290
|
"""
|
291
291
|
# Create a prompt for the LLM to analyze the query and select tools
|
292
292
|
prompt = f"""
|
293
|
-
You are an AI
|
293
|
+
You are an AI agent that helps analyze user queries and select the most appropriate tools.
|
294
294
|
Below is a list of available tools and their functionalities:
|
295
295
|
|
296
296
|
{self._get_tool_descriptions()}
|
@@ -324,8 +324,8 @@ class Assistant(BaseModel):
|
|
324
324
|
return []
|
325
325
|
|
326
326
|
|
327
|
-
def _generate_response(self, message: str, markdown: bool = False, tools: Optional[List[BaseTool]] = None, team: Optional[List['
|
328
|
-
"""Generate the
|
327
|
+
def _generate_response(self, message: str, markdown: bool = False, tools: Optional[List[BaseTool]] = None, team: Optional[List['Agent']] = None, **kwargs) -> str:
|
328
|
+
"""Generate the agent's response, including tool execution and context retrieval."""
|
329
329
|
# Use the specified tools or team if provided
|
330
330
|
if tools is not None:
|
331
331
|
self.tools = tools
|
@@ -435,12 +435,12 @@ class Assistant(BaseModel):
|
|
435
435
|
# Combine all responses into a single string
|
436
436
|
return "\n\n".join(responses)
|
437
437
|
|
438
|
-
def _generate_team_response(self, message: str, team: List['
|
438
|
+
def _generate_team_response(self, message: str, team: List['Agent'], markdown: bool = False, **kwargs) -> str:
|
439
439
|
"""Generate a response using a team of assistants."""
|
440
440
|
responses = []
|
441
|
-
for
|
442
|
-
response =
|
443
|
-
responses.append(f"**{
|
441
|
+
for agent in team:
|
442
|
+
response = agent.print_response(message, markdown=markdown, **kwargs)
|
443
|
+
responses.append(f"**{agent.name}:**\n\n{response}")
|
444
444
|
return "\n\n".join(responses)
|
445
445
|
|
446
446
|
def _build_prompt(self, message: str, context: Optional[List[Dict]]) -> str:
|
@@ -578,7 +578,7 @@ class Assistant(BaseModel):
|
|
578
578
|
exit_on: Optional[List[str]] = None,
|
579
579
|
**kwargs,
|
580
580
|
):
|
581
|
-
"""Run the
|
581
|
+
"""Run the agent in a CLI app."""
|
582
582
|
from rich.prompt import Prompt
|
583
583
|
|
584
584
|
if message:
|
@@ -593,15 +593,15 @@ class Assistant(BaseModel):
|
|
593
593
|
self.print_response(message=message, **kwargs)
|
594
594
|
|
595
595
|
def _generate_api(self):
|
596
|
-
"""Generate an API for the
|
596
|
+
"""Generate an API for the agent if api=True."""
|
597
597
|
from .api.api_generator import APIGenerator
|
598
598
|
self.api_generator = APIGenerator(self)
|
599
|
-
print(f"API generated for
|
599
|
+
print(f"API generated for agent '{self.name}'. Use `.run_api()` to start the API server.")
|
600
600
|
|
601
601
|
def run_api(self):
|
602
|
-
"""Run the API server for the
|
602
|
+
"""Run the API server for the agent."""
|
603
603
|
if not hasattr(self, 'api_generator'):
|
604
|
-
raise ValueError("API is not enabled for this
|
604
|
+
raise ValueError("API is not enabled for this agent. Set `api=True` when initializing the agent.")
|
605
605
|
|
606
606
|
# Get API configuration
|
607
607
|
host = self.api_config.get("host", "0.0.0.0") if self.api_config else "0.0.0.0"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import argparse
|
2
2
|
import warnings
|
3
|
-
from
|
4
|
-
from
|
3
|
+
from semantio.agent import Agent
|
4
|
+
from semantio.llm import get_llm
|
5
5
|
from urllib3.exceptions import NotOpenSSLWarning
|
6
6
|
|
7
7
|
# Suppress the NotOpenSSLWarning
|
@@ -9,7 +9,7 @@ warnings.filterwarnings("ignore", category=NotOpenSSLWarning)
|
|
9
9
|
|
10
10
|
def main():
|
11
11
|
parser = argparse.ArgumentParser(description="opAi CLI")
|
12
|
-
parser.add_argument("--message", type=str, required=True, help="Message to send to the
|
12
|
+
parser.add_argument("--message", type=str, required=True, help="Message to send to the agent")
|
13
13
|
parser.add_argument("--provider", type=str, required=True, help="LLM provider (e.g., groq, openai)")
|
14
14
|
parser.add_argument("--api-key", type=str, required=True, help="API key for the LLM provider")
|
15
15
|
parser.add_argument("--model", type=str, default=None, help="Model name (e.g., mixtral-8x7b-32768)")
|
@@ -22,9 +22,9 @@ def main():
|
|
22
22
|
|
23
23
|
llm = get_llm(provider=args.provider, **llm_config)
|
24
24
|
|
25
|
-
# Create an
|
26
|
-
|
27
|
-
|
25
|
+
# Create an agent
|
26
|
+
agent = Agent(model=args.provider, llm=llm)
|
27
|
+
agent.print_response(args.message)
|
28
28
|
|
29
29
|
|
30
30
|
if __name__ == "__main__":
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|