Skip to main content

Official Python SDK for Suada's Business Analyst API

Project description

Suada Python SDK

The official Python SDK for Suada's Business Analyst API. This SDK allows you to easily integrate Suada's powerful business analysis capabilities into your applications and LangChain agents.

Installation

pip install suada

Usage

Basic Usage

from suada import Suada, SuadaConfig, ChatPayload

# Initialize the client
suada = Suada(
    config=SuadaConfig(
        api_key="your-api-key"
    )
)

# Send a chat message
response = suada.chat(
    payload=ChatPayload(
        message="What's our revenue trend?",
        external_user_identifier="user-123"  # Optional when passthrough_mode is False
    )
)

print(response)

Integration with LangChain

from suada import Suada, SuadaConfig
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate

# Initialize Suada
suada = Suada(
    config=SuadaConfig(
        api_key="your-api-key"
    )
)

# Create Suada tool
suada_tool = suada.create_tool(
    name="business_analyst",
    description="Use this tool to get business insights and analysis",
    external_user_identifier="user-123",  # Required when passthrough_mode is True
    passthrough_mode=True  # Optional, defaults to False
)

# Create OpenAI agent with Suada tool
model = ChatOpenAI(temperature=0)
tools = [suada_tool]

prompt = PromptTemplate.from_template(
    """You are a helpful assistant that uses Suada's business analyst capabilities.
    
    Current conversation:
    {chat_history}
    
    Human: {input}
    Assistant: Let me help you with that."""
)

agent = create_openai_functions_agent(
    llm=model,
    tools=tools,
    prompt=prompt
)

executor = AgentExecutor.from_agent_and_tools(
    agent=agent,
    tools=tools,
    verbose=True
)

# Use the agent
result = executor.invoke({
    "input": "What's our revenue trend for the last quarter?",
    "chat_history": []
})

print(result["output"])

Passthrough Mode and User Identification

The SDK supports two modes of operation:

  1. Standard Mode (passthrough_mode=False, default): In this mode, Suada's AI analyzes the query and provides structured business insights. The external_user_identifier is optional.

  2. Passthrough Mode (passthrough_mode=True): In this mode, messages are passed directly to the LLM. When using passthrough mode, external_user_identifier is required for proper user tracking.

# Standard mode - external_user_identifier is optional
response_standard = suada.chat(
    payload=ChatPayload(
        message="What's our revenue trend?",
        passthrough_mode=False  # This is the default
    )
)

# Passthrough mode - external_user_identifier is required
response_passthrough = suada.chat(
    payload=ChatPayload(
        message="What's our revenue trend?",
        external_user_identifier="user-123",
        passthrough_mode=True
    )
)

Response Format

The SDK formats responses from Suada's API into a structured string format that can be easily parsed by LangChain agents. The response includes the following sections:

  • <metrics>: Key performance metrics
  • <insights>: Business insights
  • <recommendations>: Action recommendations
  • <risks>: Potential risks
  • <reasoning>: Analysis reasoning
  • <response>: Main response text

Example response:

<metrics>
revenue: $1.2M
growth_rate: 15%
</metrics>

<insights>
Strong growth in enterprise segment
New product adoption exceeding expectations
</insights>

<recommendations>
Increase focus on enterprise sales
Expand product feature set
</recommendations>

<risks>
Market competition intensifying
Supply chain constraints
</risks>

<reasoning>
Analysis shows positive growth trajectory with some areas requiring attention
</reasoning>

<response>
Your revenue has shown strong growth, particularly in the enterprise segment...
</response>

Configuration

The SDK accepts the following configuration options:

from suada import SuadaConfig

config = SuadaConfig(
    api_key="your-api-key",
    base_url="https://suada.ai/api/public/"  # Optional, defaults to https://suada.ai/api/public/
)

Type Safety

The SDK uses Pydantic models for type safety and validation:

from suada import ChatPayload, ChatMessage

# All fields are properly typed and validated
payload = ChatPayload(
    message="What's our revenue?",
    external_user_identifier="user-123",  # Required only when passthrough_mode is True
    passthrough_mode=True,
    chat_history=[
        ChatMessage(
            role="user",
            content="Previous message"
        )
    ]
)

Error Handling

The SDK throws descriptive exceptions when API calls fail:

from suada import Suada, SuadaConfig, ChatPayload

suada = Suada(config=SuadaConfig(api_key="your-api-key"))

try:
    response = suada.chat(
        payload=ChatPayload(
            message="What's our revenue?",
            external_user_identifier="user-123"
        )
    )
except Exception as e:
    print(f"Error: {str(e)}")

Development

To set up the development environment:

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run type checking
mypy suada

# Run code formatting
black suada
isort suada

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

suada-1.1.0rc1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

suada-1.1.0rc1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file suada-1.1.0rc1.tar.gz.

File metadata

  • Download URL: suada-1.1.0rc1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for suada-1.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 ff3191da2096bf4ba5f4ba3f6b65bed0b309253658fde3ba6841b28f2ec439a6
MD5 42fb03f7063d9be058fdf99765754bd6
BLAKE2b-256 d0f05addd573a4d625845a472d68e8246dfe8bde4dc42c05635e0ae1a49cc971

See more details on using hashes here.

File details

Details for the file suada-1.1.0rc1-py3-none-any.whl.

File metadata

  • Download URL: suada-1.1.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for suada-1.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea83cd896df6aa54372ed6f6b7c5bd0e949937fa4d63b75e0e4d50a40860b23
MD5 478c146c8155f419a536868d0d979f16
BLAKE2b-256 226f74dcfe03908ed8645346396ff2dda66b0366ad05dded6509a262b1cbbde2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page