fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")result=db.ask("What's our total revenue this quarter?")print(result)# Returns: "Total revenue for Q4 2024 is $2.4M"
fromtoolfrontimportAPIapi=API("https://api.example.com/openapi.json")result=api.ask("Get the latest status for service XYZ")print(result)# Returns: "Service XYZ is running with 99.9% uptime"
fromtoolfrontimportDocumentdoc=Document("/path/to/annual_report.pdf")result=doc.ask("What were the key achievements this year?")print(result)# Returns: "Key achievements include 30% revenue growth..."
fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")total_orders:int=db.ask("How many orders do we have?")# Returns: 1250avg_price:float=db.ask("What's our average ticket price?")# Returns: 29.99best_product:str=db.ask("What's our best-selling product?")# Returns: "Wireless Headphones Pro"has_inventory:bool=db.ask("Do we have any monitors in stock?")# Returns True
fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")price:int|float=db.ask("Price of product XYZ?")# Returns: 29.99, 30result:str|list[str]=db.ask("Best-sellers this month?")# Returns: ["Product A", "Product B"] or "No data found"error:str|None=db.ask("What was the error message?")# Returns: "Connection timeout" or Nonestatus:bool|str=db.ask("Is the system healthy?")# Returns: True or "Database connection failed"
fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")# Export 100,000+ rowssales_data:db.Table=db.ask("Get all sales from 2024")# Process locallydf=sales_data.to_dataframe()print(f"Retrieved {len(df):,} rows")# Export formatssales_data.to_csv("sales_2024.csv")sales_data.to_excel("report.xlsx")print(sales_data.columns)
fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")# Add business context for better understandingcontext="""Our company operates in the fashion industry.Revenue is measured quarterly, and our fiscal year starts in April.Product categories include: clothing, accessories, footwear."""result=db.ask("What's our total revenue this quarter?",context=context)print(result)# Returns more contextually accurate result
fromtoolfrontimportDatabasedb=Database("postgresql://user:pass@host/db")# Success returns data, failure returns error stringresult:list[dict]|str=db.ask("Complex query that might fail")# Returns: [{"id": 1, "name": "John"}] or "Error: table not found"# Handle both success and error casesstatus:bool|str=db.ask("Is the system healthy?")# Returns: True or "Database connection failed"ifisinstance(result,str):print(f"Error: {result}")else:print(f"Found {len(result)} records")