2025-02-03 13:53:47 +05:30
# Using the Python SDK
This is a guide on using the RowBoat Python SDK as an alternative to the [RowBoat HTTP API ](/using_the_api ) to power conversations with the assistant created in Studio.
## Prerequisites
- ``` pip install rowboat ` ``
2025-02-05 15:04:32 +05:30
- [Deploy your assistant to production ](/using_the_api/#deploy-your-assistant-to-production-on-studio )
- [Obtain your `<API_KEY>` and `<PROJECT_ID>` ](/using_the_api/#obtain-api-key-and-project-id )
### API Host
- For the open source installation, the `<HOST>` is [http://localhost:3000 ](http://localhost:3000 )
- When using the hosted app, the `<HOST>` is [https://app.rowboatlabs.com ](https://app.rowboatlabs.com )
2025-02-03 13:53:47 +05:30
## Usage
2025-04-10 00:24:47 +05:30
### Basic Usage with StatefulChat
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
The easiest way to interact with Rowboat is using the `StatefulChat` class, which maintains conversation state automatically:
2025-02-03 13:53:47 +05:30
```python
2025-04-10 00:24:47 +05:30
from rowboat import Client, StatefulChat
2025-02-03 13:53:47 +05:30
# Initialize the client
client = Client(
host="< HOST > ",
project_id="< PROJECT_ID > ",
api_key="< API_KEY > "
)
2025-04-10 00:24:47 +05:30
# Create a stateful chat session
chat = StatefulChat(client)
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
# Have a conversation
response = chat.run("What is the capital of France?")
print(response)
# The capital of France is Paris.
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
# Continue the conversation - the context is maintained automatically
response = chat.run("What other major cities are in that country?")
print(response)
# Other major cities in France include Lyon, Marseille, Toulouse, and Nice.
response = chat.run("What's the population of the first city you mentioned?")
print(response)
# Lyon has a population of approximately 513,000 in the city proper.
2025-02-03 13:53:47 +05:30
```
2025-04-10 00:24:47 +05:30
### Advanced Usage
#### Using a specific workflow
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
You can specify a workflow ID to use a particular conversation configuration:
2025-02-03 13:53:47 +05:30
```python
2025-04-10 00:24:47 +05:30
chat = StatefulChat(
client,
workflow_id="< WORKFLOW_ID > "
2025-02-03 13:53:47 +05:30
)
```
2025-04-10 00:24:47 +05:30
#### Using a test profile
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
You can specify a test profile ID to use a specific test configuration:
2025-02-03 13:53:47 +05:30
```python
chat = StatefulChat(
client,
2025-04-10 00:24:47 +05:30
test_profile_id="< TEST_PROFILE_ID > "
2025-02-03 13:53:47 +05:30
)
2025-04-10 00:24:47 +05:30
```
2025-02-03 13:53:47 +05:30
2025-04-10 00:24:47 +05:30
### Low-Level Usage
For more control over the conversation, you can use the `Client` class directly:
```python
from rowboat.schema import UserMessage
# Initialize the client
client = Client(
host="< HOST > ",
project_id="< PROJECT_ID > ",
api_key="< API_KEY > "
)
# Create messages
messages = [
UserMessage(role='user', content="Hello, how are you?")
]
# Get response
response = client.chat(messages=messages)
print(response.messages[-1].content)
# For subsequent messages, you need to manage the message history and state manually
messages.extend(response.messages)
messages.append(UserMessage(role='user', content="What's your name?"))
response = client.chat(messages=messages, state=response.state)
2025-02-03 14:02:59 +05:30
```