From bd23dba190ba6bafc07ccd59ed6b325e8d762f43 Mon Sep 17 00:00:00 2001 From: cjber Date: Tue, 8 Apr 2025 17:49:02 +0100 Subject: [PATCH 1/2] filter outputs from resolve --- python/thirdweb-ai/src/thirdweb_ai/common/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/thirdweb-ai/src/thirdweb_ai/common/utils.py b/python/thirdweb-ai/src/thirdweb_ai/common/utils.py index 8d02f9f..608b2e3 100644 --- a/python/thirdweb-ai/src/thirdweb_ai/common/utils.py +++ b/python/thirdweb-ai/src/thirdweb_ai/common/utils.py @@ -56,10 +56,9 @@ def clean_resolve(out: dict[str, Any]): """Clean the response from the resolve function.""" if "transactions" in out["data"]: for transaction in out["data"]["transactions"]: - if "data" in transaction and is_encoded(transaction["data"]): - transaction.pop("data") - if "logs_bloom" in transaction: - transaction.pop("logs_bloom") + for key in list(transaction.keys()): + if key not in TRANSACTION_KEYS_TO_KEEP: + transaction.pop(key, None) return out From 902c596d876ce6ba65bbfa02a5fedd723dcdc633 Mon Sep 17 00:00:00 2001 From: cjber Date: Tue, 8 Apr 2025 18:14:23 +0100 Subject: [PATCH 2/2] add structured output example --- python/thirdweb-ai/README.md | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/python/thirdweb-ai/README.md b/python/thirdweb-ai/README.md index b759f74..5124e06 100644 --- a/python/thirdweb-ai/README.md +++ b/python/thirdweb-ai/README.md @@ -124,6 +124,45 @@ autogen_tools = get_autogen_tools(tools) More examples are available in the examples directory that can be found [here](https://github.com/thirdweb-dev/ai/tree/main/python/examples) +### Structured Outputs with Nebula + +Nebula supports returning structured outputs through the `response_format` parameter. For example; + +```python +response_format = { + "type": "json_schema", + "json_schema": { + "name": "example_schema", + "schema": { + "type": "object", + "properties": { + "ens_name": { + "type": "string", + "description": "The ENS name being queried", + }, + "balance": { + "type": "integer", + "description": "The balance of the address on the specified contract", + }, + }, + "required": ["ens_name", "balance"], + }, + }, +} + + +nebula = Nebula( + secret_key=os.getenv("THIRDWEB_SECRET_KEY"), response_format=response_format +) +``` + +This will return the output as JSON, using the requested format. For example; "what is the balance of thirdweb.eth on contract 0xddC761FEb956Caf62dfa1c8b42e9f33Df424715A on sepolia" would give something like. + +```json +{'ens_name': 'thirdweb.eth', 'balance': 3} +``` + + ## Custom Integration If you're using a framework that isn't directly supported, you can still use thirdweb-ai by creating a custom adapter. The core `Tool` class follows a standard interface that can be adapted to most frameworks: