Skip to content

Commit eaf8a71

Browse files
committed
fix: Update example scripts to work with current SDK API
- Fixed FlareAIKit initialization in examples (removed non-existent get_settings()) - Updated FAssets example method signatures to match actual implementation - Fixed import in 04_verify_fassets_implementation.py (EcosystemSettingsModel -> EcosystemSettings) - Added graceful handling for missing API keys in 07_rag_vector_demo.py - All examples now run without import errors or basic initialization issues Fixes #109
1 parent 7bb99c8 commit eaf8a71

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

examples/01_get_ftso_price.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22

33
from flare_ai_kit import FlareAIKit
4-
from flare_ai_kit.config import get_settings
54

65

76
async def main() -> None:
@@ -10,8 +9,8 @@ async def main() -> None:
109
1110
For a full list of feeds: https://dev.flare.network/ftso/feeds
1211
"""
13-
# Initialize the Flare AI Kit
14-
kit = FlareAIKit(get_settings())
12+
# Initialize the Flare AI Kit with default settings
13+
kit = FlareAIKit(None)
1514

1615
# Get the latest price for FLR/USD from the FTSOv2 oracle
1716
try:

examples/03_fassets_basic.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ async def perform_swap_operations(
6565
print("1. Swap FXRP for Native Token (FLR/SGB)")
6666
tx_hash = await fassets.swap_fasset_for_native(
6767
FAssetType.FXRP,
68-
amount_in=swap_amount,
69-
amount_out_min=min_native_out,
70-
deadline=deadline,
68+
swap_amount,
69+
min_native_out,
70+
deadline,
7171
)
7272
print(f" Transaction: {tx_hash}")
7373

@@ -76,9 +76,9 @@ async def perform_swap_operations(
7676
min_fxrp_out = 900000 # 0.9 FXRP
7777
tx_hash = await fassets.swap_native_for_fasset(
7878
FAssetType.FXRP,
79-
amount_out_min=min_fxrp_out,
80-
deadline=deadline,
81-
amount_in=native_amount,
79+
min_fxrp_out,
80+
deadline,
81+
native_amount,
8282
)
8383
print(f" Transaction: {tx_hash}")
8484

@@ -91,9 +91,9 @@ async def perform_swap_operations(
9191
tx_hash = await fassets.swap_fasset_for_fasset(
9292
FAssetType.FXRP,
9393
other_fasset,
94-
amount_in=swap_amount,
95-
amount_out_min=500000, # Adjust based on decimals
96-
deadline=deadline,
94+
swap_amount,
95+
500000, # Adjust based on decimals
96+
deadline,
9797
)
9898
print(f" Transaction: {tx_hash}")
9999

@@ -127,11 +127,10 @@ async def demonstrate_minting_workflow(fassets: FAssets) -> None:
127127
)
128128
reservation_id = await fassets.reserve_collateral(
129129
FAssetType.FXRP,
130-
agent_vault=agent_address,
131-
lots=1,
132-
max_minting_fee_bips=100, # 1%
133-
executor=executor,
134-
executor_fee_nat=0,
130+
agent_address,
131+
1,
132+
100, # 1%
133+
executor,
135134
)
136135
print(f"Collateral Reservation ID: {reservation_id}")
137136

@@ -142,9 +141,9 @@ async def demonstrate_minting_workflow(fassets: FAssets) -> None:
142141
)
143142
minted_amount = await fassets.execute_minting(
144143
FAssetType.FXRP,
145-
collateral_reservation_id=int(reservation_id),
146-
payment_reference=payment_reference,
147-
recipient=executor,
144+
int(reservation_id.get('reservation_id', 0)),
145+
payment_reference,
146+
executor,
148147
)
149148
print(f"Minted Amount: {minted_amount} wei")
150149

@@ -162,16 +161,15 @@ async def perform_redemption_operations(fassets: FAssets) -> None:
162161
# Redeem FAssets back to underlying
163162
redemption_id = await fassets.redeem_from_agent(
164163
FAssetType.FXRP,
165-
lots=1,
166-
max_redemption_fee_bips=100, # 1%
167-
underlying_address="rXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", # XRP address
168-
executor=executor,
169-
executor_fee_nat=0,
164+
1,
165+
100, # 1%
166+
"rXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", # XRP address
167+
executor,
170168
)
171169
print(f"Redemption Request ID: {redemption_id}")
172170

173171
# Get redemption request details
174-
request_id = int(redemption_id)
172+
request_id = int(redemption_id.get('request_id', 0))
175173
if request_id > 0:
176174
redemption_details: dict[str, Any] = await fassets.get_redemption_request(
177175
FAssetType.FXRP, request_id
@@ -266,8 +264,8 @@ async def main() -> None:
266264
update the contract addresses in the FAssets connector with actual
267265
deployed addresses.
268266
"""
269-
# Initialize the Flare AI Kit
270-
kit = FlareAIKit()
267+
# Initialize the Flare AI Kit with default settings
268+
kit = FlareAIKit(None)
271269

272270
try:
273271
# Get the FAssets connector

examples/04_verify_fassets_implementation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
FAssetType,
2929
)
3030
from flare_ai_kit.ecosystem.protocols.fassets import FAssets
31-
from flare_ai_kit.ecosystem.settings_models import EcosystemSettingsModel
31+
from flare_ai_kit.ecosystem.settings import EcosystemSettings
3232

3333
# Add the src directory to the path
3434
sys.path.insert(0, str(Path(__file__).parent.parent))
@@ -38,14 +38,14 @@
3838
T = TypeVar("T")
3939

4040

41-
def create_test_settings() -> EcosystemSettingsModel:
41+
def create_test_settings() -> EcosystemSettings:
4242
"""Create test settings for Coston2 network."""
4343
# Use a test account with no real value
4444
Account.enable_unaudited_hdwallet_features()
4545
account = Account.from_mnemonic(
4646
"test test test test test test test test test test test junk"
4747
)
48-
return EcosystemSettingsModel(
48+
return EcosystemSettings(
4949
is_testnet=True,
5050
web3_provider_url=HttpUrl("https://coston-api.flare.network/ext/bc/C/rpc"),
5151
web3_provider_timeout=5,

examples/07_rag_vector_demo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
)
3939

4040
# 3. Use the Gemini embedding model for testing
41+
# Check if API key is configured
42+
if agent.gemini_api_key is None:
43+
print("❌ GEMINI_API_KEY environment variable not set.")
44+
print("Please set the GEMINI_API_KEY environment variable to run this demo.")
45+
print("Example: export GEMINI_API_KEY='your_api_key_here'")
46+
exit(1)
47+
4148
embedding_model = GeminiEmbedding(
4249
api_key=agent.gemini_api_key.get_secret_value(),
4350
model=vector_db.embeddings_model,

0 commit comments

Comments
 (0)