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.2.0rc1.tar.gz (8.9 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.2.0rc1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for suada-1.2.0rc1.tar.gz
Algorithm Hash digest
SHA256 425eea839a5667b64be96dcbcf5966067168505598bb5afcbb2391cb48e282b8
MD5 e88d523c08af9a0d267a63c1bb947945
BLAKE2b-256 ba25774c6f5c7577b48657e5c30d096d1e86600b36523a0e8be0f5e5ca3392b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: suada-1.2.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.2.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ee72e613777b89e1f038866db17b453795733f7e6d42c296c76ad60034a0514
MD5 720145470a3b3449f0b04ebfdfe6914d
BLAKE2b-256 f25ccc95830c57df09db23634b2914df4bf3d68902762be5e64c1439cfad120b

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