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"
    )
)

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"
)

# 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"])

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",
    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.0.0rc1.tar.gz (3.4 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.0.0rc1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for suada-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 6db6f1b3fdb823c6ec8c3f90806b3ae1ecf5251756e0eea0e0ed0eb50242905e
MD5 f771af4bc6f34e84867099ef007bc389
BLAKE2b-256 f38f2f057c96d948e37aaf2d272783837c35cd4498d962be75642a61c026c245

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for suada-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 341aaf30392839cd3c6aac3ffdfb53cb942254e32527f991c3d022220b45b969
MD5 b810172cee69e251e8940d860f07c0dd
BLAKE2b-256 87e8fb45d1aded6e77f2c30cc3a3256959ffc220bd8ca23326e9affd4e5fae78

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