2025-01-15 17:44:32 +05:30
|
|
|
# Rowboat Python SDK
|
|
|
|
|
|
|
|
|
|
A Python SDK for interacting with the Rowboat API.
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
You can install the package using pip:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pip install rowboat
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
### Basic Usage
|
|
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
Initialize a client and use the chat method directly:
|
2025-01-15 17:44:32 +05:30
|
|
|
|
|
|
|
|
```python
|
2025-01-15 20:29:50 +05:30
|
|
|
from rowboat import Client
|
|
|
|
|
from rowboat.schema import UserMessage, SystemMessage
|
2025-01-15 17:44:32 +05:30
|
|
|
|
|
|
|
|
# Initialize the client
|
|
|
|
|
client = Client(
|
|
|
|
|
host="<HOST>",
|
|
|
|
|
project_id="<PROJECT_ID>",
|
2025-01-27 11:01:53 +05:30
|
|
|
api_key="<API_KEY>"
|
2025-01-15 17:44:32 +05:30
|
|
|
)
|
|
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
# Create messages
|
|
|
|
|
messages = [
|
|
|
|
|
SystemMessage(role='system', content="You are a helpful assistant"),
|
|
|
|
|
UserMessage(role='user', content="Hello, how are you?")
|
|
|
|
|
]
|
2025-01-15 17:44:32 +05:30
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
# Get response
|
|
|
|
|
response_messages, state = client.chat(messages=messages)
|
|
|
|
|
print(response_messages[-1].content)
|
|
|
|
|
|
|
|
|
|
# For subsequent messages, include previous messages and state
|
|
|
|
|
messages.extend(response_messages)
|
|
|
|
|
messages.append(UserMessage(role='user', content="What's your name?"))
|
|
|
|
|
response_messages, state = client.chat(messages=messages, state=state)
|
2025-01-15 17:44:32 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Using Tools
|
|
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
The SDK supports function calling through tools:
|
2025-01-15 17:44:32 +05:30
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def weather_lookup(city_name: str) -> str:
|
|
|
|
|
return f"The weather in {city_name} is 22°C."
|
|
|
|
|
|
|
|
|
|
# Create a tools dictionary
|
|
|
|
|
tools = {
|
|
|
|
|
'weather_lookup': weather_lookup
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
# Use tools with the chat method
|
|
|
|
|
response_messages, state = client.chat(
|
|
|
|
|
messages=messages,
|
|
|
|
|
tools=tools
|
|
|
|
|
)
|
2025-01-15 17:44:32 +05:30
|
|
|
```
|
|
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
### Stateful Chat (Convenience Wrapper)
|
2025-01-15 17:44:32 +05:30
|
|
|
|
2025-01-15 20:29:50 +05:30
|
|
|
For simpler use cases, the SDK provides a `StatefulChat` class that maintains conversation state automatically:
|
2025-01-15 17:44:32 +05:30
|
|
|
|
|
|
|
|
```python
|
2025-01-15 20:29:50 +05:30
|
|
|
from rowboat import StatefulChat
|
|
|
|
|
|
|
|
|
|
# Initialize stateful chat
|
2025-01-15 17:44:32 +05:30
|
|
|
chat = StatefulChat(
|
|
|
|
|
client,
|
|
|
|
|
tools=tools,
|
2025-01-15 20:29:50 +05:30
|
|
|
system_prompt="You are a helpful assistant."
|
2025-01-15 17:44:32 +05:30
|
|
|
)
|
2025-01-15 20:29:50 +05:30
|
|
|
|
|
|
|
|
# Simply send messages and get responses
|
|
|
|
|
response = chat.run("Hello, how are you?")
|
|
|
|
|
print(response)
|
|
|
|
|
# I'm good, thanks! How can I help you today?
|
2025-02-03 13:53:47 +05:30
|
|
|
```
|