solana-agent 2.1.2__tar.gz → 3.0.0__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.
- {solana_agent-2.1.2 → solana_agent-3.0.0}/PKG-INFO +1 -1
- {solana_agent-2.1.2 → solana_agent-3.0.0}/pyproject.toml +1 -1
- {solana_agent-2.1.2 → solana_agent-3.0.0}/solana_agent/ai.py +37 -17
- {solana_agent-2.1.2 → solana_agent-3.0.0}/LICENSE +0 -0
- {solana_agent-2.1.2 → solana_agent-3.0.0}/README.md +0 -0
- {solana_agent-2.1.2 → solana_agent-3.0.0}/solana_agent/__init__.py +0 -0
|
@@ -9,6 +9,7 @@ from pydantic import BaseModel
|
|
|
9
9
|
from pymongo import MongoClient
|
|
10
10
|
from openai import OpenAI
|
|
11
11
|
import inspect
|
|
12
|
+
import pytz
|
|
12
13
|
import requests
|
|
13
14
|
from zep_cloud.client import AsyncZep as AsyncZepCloud
|
|
14
15
|
from zep_cloud.client import Zep as ZepCloud
|
|
@@ -69,7 +70,9 @@ class AI:
|
|
|
69
70
|
pinecone_embed_model: Literal["llama-text-embed-v2"] = "llama-text-embed-v2",
|
|
70
71
|
gemini_api_key: str = None,
|
|
71
72
|
openai_base_url: str = None,
|
|
72
|
-
|
|
73
|
+
main_model: str = "o3-mini",
|
|
74
|
+
tool_formatting_model: str = "gpt-4o-mini",
|
|
75
|
+
tool_formatting_instructions: str = None,
|
|
73
76
|
):
|
|
74
77
|
"""Initialize a new AI assistant instance.
|
|
75
78
|
|
|
@@ -86,8 +89,9 @@ class AI:
|
|
|
86
89
|
pinecone_embed_model (Literal["llama-text-embed-v2"], optional): Pinecone embedding model. Defaults to "llama-text-embed-v2"
|
|
87
90
|
gemini_api_key (str, optional): API key for Gemini search. Defaults to None
|
|
88
91
|
openai_base_url (str, optional): Base URL for OpenAI API. Defaults to None
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
main_model (str, optional): Main OpenAI model for conversation. Defaults to "o3-mini"
|
|
93
|
+
tool_formatting_model (str, optional): OpenAI model for tool formatting. Defaults to "gpt-4o-mini"
|
|
94
|
+
tool_formatting_instructions (str, optional): Instructions for tool formatting
|
|
91
95
|
Example:
|
|
92
96
|
```python
|
|
93
97
|
ai = AI(
|
|
@@ -116,6 +120,7 @@ class AI:
|
|
|
116
120
|
Always be concise and ensure that your response maintains coherence across the conversation while respecting the user's context and previous data.
|
|
117
121
|
"""
|
|
118
122
|
self._instructions = instructions + " " + memory_instructions
|
|
123
|
+
self._tool_formatting_instructions = tool_formatting_instructions
|
|
119
124
|
self._database: MongoDatabase = database
|
|
120
125
|
self._accumulated_value_queue = asyncio.Queue()
|
|
121
126
|
if zep_api_key and not zep_base_url:
|
|
@@ -140,7 +145,8 @@ class AI:
|
|
|
140
145
|
self._pinecone_index_name) if self._pinecone else None
|
|
141
146
|
)
|
|
142
147
|
self._openai_base_url = openai_base_url
|
|
143
|
-
self.
|
|
148
|
+
self._main_model = main_model
|
|
149
|
+
self._tool_formatting_model = tool_formatting_model
|
|
144
150
|
self._tools = []
|
|
145
151
|
|
|
146
152
|
async def __aenter__(self):
|
|
@@ -431,16 +437,19 @@ class AI:
|
|
|
431
437
|
self.kb.delete(ids=[id], namespace=user_id)
|
|
432
438
|
self._database.kb.delete_one({"reference": id})
|
|
433
439
|
|
|
434
|
-
def check_time(self) -> str:
|
|
440
|
+
def check_time(self, timezone: str) -> str:
|
|
435
441
|
"""Get current UTC time formatted as a string via Cloudflare's NTP service.
|
|
436
442
|
|
|
443
|
+
Args:
|
|
444
|
+
timezone (str): Timezone to convert the time to (e.g., "America/New_York")
|
|
445
|
+
|
|
437
446
|
Returns:
|
|
438
|
-
str: Current
|
|
447
|
+
str: Current time in the requested timezone in format 'YYYY-MM-DD HH:MM:SS'
|
|
439
448
|
|
|
440
449
|
Example:
|
|
441
450
|
```python
|
|
442
|
-
time = ai.check_time()
|
|
443
|
-
# Returns: "2025-02-26
|
|
451
|
+
time = ai.check_time("America/New_York")
|
|
452
|
+
# Returns: "The current time in America/New_York is 2025-02-26 10:30:45"
|
|
444
453
|
```
|
|
445
454
|
|
|
446
455
|
Note:
|
|
@@ -448,14 +457,25 @@ class AI:
|
|
|
448
457
|
Fetches time over NTP from Cloudflare's time server (time.cloudflare.com).
|
|
449
458
|
"""
|
|
450
459
|
try:
|
|
460
|
+
# Request time from Cloudflare's NTP server
|
|
451
461
|
client = ntplib.NTPClient()
|
|
452
|
-
# Request time from Cloudflare's NTP server.
|
|
453
462
|
response = client.request("time.cloudflare.com", version=3)
|
|
454
|
-
|
|
463
|
+
|
|
464
|
+
# Get UTC time from NTP response
|
|
465
|
+
utc_dt = datetime.datetime.fromtimestamp(
|
|
455
466
|
response.tx_time, datetime.timezone.utc)
|
|
456
|
-
|
|
467
|
+
|
|
468
|
+
# Convert to requested timezone
|
|
469
|
+
try:
|
|
470
|
+
tz = pytz.timezone(timezone)
|
|
471
|
+
local_dt = utc_dt.astimezone(tz)
|
|
472
|
+
formatted_time = local_dt.strftime("%Y-%m-%d %H:%M:%S")
|
|
473
|
+
return f"The current time in {timezone} is {formatted_time}"
|
|
474
|
+
except pytz.exceptions.UnknownTimeZoneError:
|
|
475
|
+
return f"Error: Unknown timezone '{timezone}'. Please use a valid timezone like 'America/New_York'."
|
|
476
|
+
|
|
457
477
|
except Exception as e:
|
|
458
|
-
return f"Error: {e}"
|
|
478
|
+
return f"Error getting the current time: {e}"
|
|
459
479
|
|
|
460
480
|
# has to be sync for tool
|
|
461
481
|
def get_memory_context(
|
|
@@ -788,7 +808,7 @@ class AI:
|
|
|
788
808
|
async def stream_processor():
|
|
789
809
|
memory = self.get_memory_context(user_id)
|
|
790
810
|
response = self._client.chat.completions.create(
|
|
791
|
-
model=self.
|
|
811
|
+
model=self._main_model,
|
|
792
812
|
messages=[
|
|
793
813
|
{
|
|
794
814
|
"role": "system",
|
|
@@ -828,11 +848,11 @@ class AI:
|
|
|
828
848
|
# Execute the tool call (synchronously; adjust if async is needed)
|
|
829
849
|
result = func(**args)
|
|
830
850
|
response = self._client.chat.completions.create(
|
|
831
|
-
model=self.
|
|
851
|
+
model=self._tool_formatting_model,
|
|
832
852
|
messages=[
|
|
833
853
|
{
|
|
834
854
|
"role": "system",
|
|
835
|
-
"content": self.
|
|
855
|
+
"content": self._tool_formatting_instructions,
|
|
836
856
|
},
|
|
837
857
|
{
|
|
838
858
|
"role": "user",
|
|
@@ -988,11 +1008,11 @@ class AI:
|
|
|
988
1008
|
# Execute the tool call (synchronously; adjust if async is needed)
|
|
989
1009
|
result = func(**args)
|
|
990
1010
|
response = self._client.chat.completions.create(
|
|
991
|
-
model=self.
|
|
1011
|
+
model=self._tool_formatting_model,
|
|
992
1012
|
messages=[
|
|
993
1013
|
{
|
|
994
1014
|
"role": "system",
|
|
995
|
-
"content": self.
|
|
1015
|
+
"content": self._tool_formatting_instructions,
|
|
996
1016
|
},
|
|
997
1017
|
{
|
|
998
1018
|
"role": "user",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|