Skip to content

Commit b4a09c9

Browse files
authored
remove session id as tools, and allow user to call them (#27)
1 parent d3e82d9 commit b4a09c9

File tree

1 file changed

+12
-25
lines changed
  • python/thirdweb-ai/src/thirdweb_ai/services

1 file changed

+12
-25
lines changed

python/thirdweb-ai/src/thirdweb_ai/services/nebula.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66

77
class Nebula(Service):
8-
def __init__(self, secret_key: str, response_format: dict[str, int | str] | None = None) -> None:
8+
def __init__(
9+
self, secret_key: str, session_id: str | None = None, response_format: dict[str, int | str] | None = None
10+
) -> None:
911
super().__init__(base_url="https://nebula-api.thirdweb.com", secret_key=secret_key)
10-
if response_format:
11-
self.response_format = response_format
12+
self.response_format = response_format or None
13+
self.session_id = session_id or None
1214

1315
@tool(
1416
description="Send a message to Nebula AI and get a response. This can be used for blockchain queries, contract interactions, and access to thirdweb tools."
@@ -19,39 +21,24 @@ def chat(
1921
str,
2022
"The natural language message to process. Can be a question about blockchain data, a request to execute a transaction, or any web3-related query.",
2123
],
22-
session_id: Annotated[
23-
str | None,
24-
"Optional session ID to maintain conversation context. If provided, this message will be part of an ongoing conversation; if omitted, a new session is created.",
25-
] = None,
26-
context: Annotated[
27-
dict[str, Any] | None,
28-
"Contextual information for processing the request, including: chainIds (array of chain identifiers) and walletAddress (user's wallet for transaction signing). Example: {'chainIds': ['1', '137'], 'walletAddress': '0x123...'}",
29-
] = None,
3024
) -> dict[str, Any]:
3125
data: dict[str, Any] = {"message": message, "stream": False}
32-
if session_id:
33-
data["session_id"] = session_id
34-
if context:
35-
data["context"] = context
3626
if self.response_format:
3727
data["response_format"] = self.response_format
28+
if self.session_id:
29+
data["context"] = {"session_id": self.session_id}
3830

3931
return self._post("/chat", data)
4032

41-
@tool(
42-
description="Retrieve all available Nebula AI sessions for the authenticated account. Returns an array of session metadata including IDs, titles, and creation timestamps, allowing you to find and reference existing conversations."
43-
)
4433
def list_sessions(self) -> dict[str, Any]:
4534
return self._get("session/list")
4635

47-
@tool(
48-
description="Fetch complete information about a specific Nebula AI session, including conversation history, context settings, and metadata. Use this to examine past interactions or resume an existing conversation thread."
49-
)
5036
def get_session(
5137
self,
52-
session_id: Annotated[
53-
str,
54-
"Unique identifier for the target session. This UUID references a specific conversation history in the Nebula system.",
55-
],
38+
session_id: str,
5639
) -> dict[str, Any]:
5740
return self._get(f"/session/{session_id}")
41+
42+
def create_session(self) -> dict[str, Any]:
43+
data = {}
44+
return self._post("/session", data)

0 commit comments

Comments
 (0)