mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 00:16:29 +02:00
update py-sdk docs
This commit is contained in:
parent
63564810e8
commit
05fb6ad9a8
2 changed files with 51 additions and 88 deletions
|
|
@ -12,102 +12,65 @@ pip install rowboat
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Basic Usage with StatefulChat
|
### Basic Usage
|
||||||
|
|
||||||
The easiest way to interact with Rowboat is using the `StatefulChat` class, which maintains conversation state automatically:
|
The main way to interact with Rowboat is using the `Client` class, which provides a stateless chat API. You can manage conversation state using the `conversationId` returned in each response.
|
||||||
|
|
||||||
```python
|
|
||||||
from rowboat import Client, StatefulChat
|
|
||||||
|
|
||||||
# Initialize the client
|
|
||||||
client = Client(
|
|
||||||
host="<HOST>",
|
|
||||||
project_id="<PROJECT_ID>",
|
|
||||||
api_key="<API_KEY>"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create a stateful chat session
|
|
||||||
chat = StatefulChat(client)
|
|
||||||
|
|
||||||
# Have a conversation
|
|
||||||
response = chat.run("What is the capital of France?")
|
|
||||||
print(response)
|
|
||||||
# The capital of France is Paris.
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
```
|
|
||||||
|
|
||||||
### Advanced Usage
|
|
||||||
|
|
||||||
#### Using a specific workflow
|
|
||||||
|
|
||||||
You can specify a workflow ID to use a particular conversation configuration:
|
|
||||||
|
|
||||||
```python
|
|
||||||
chat = StatefulChat(
|
|
||||||
client,
|
|
||||||
workflow_id="<WORKFLOW_ID>"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Using a test profile
|
|
||||||
|
|
||||||
You can specify a test profile ID to use a specific test configuration:
|
|
||||||
|
|
||||||
```python
|
|
||||||
chat = StatefulChat(
|
|
||||||
client,
|
|
||||||
test_profile_id="<TEST_PROFILE_ID>"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Tool overrides
|
|
||||||
|
|
||||||
You can provide tool override instructions to test a specific configuration:
|
|
||||||
|
|
||||||
```python
|
|
||||||
chat = StatefulChat(
|
|
||||||
client,
|
|
||||||
mock_tools={
|
|
||||||
"weather_lookup": "The weather in any city is sunny and 25°C.",
|
|
||||||
"calculator": "The result of any calculation is 42.",
|
|
||||||
"search": "Search results for any query return 'No relevant information found.'"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Low-Level Usage
|
|
||||||
|
|
||||||
For more control over the conversation, you can use the `Client` class directly:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from rowboat.client import Client
|
||||||
from rowboat.schema import UserMessage
|
from rowboat.schema import UserMessage
|
||||||
|
|
||||||
# Initialize the client
|
# Initialize the client
|
||||||
client = Client(
|
client = Client(
|
||||||
host="<HOST>",
|
host="<HOST>",
|
||||||
project_id="<PROJECT_ID>",
|
projectId="<PROJECT_ID>",
|
||||||
api_key="<API_KEY>"
|
apiKey="<API_KEY>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create messages
|
# Start a new conversation
|
||||||
messages = [
|
result = client.run_turn(
|
||||||
UserMessage(role='user', content="Hello, how are you?")
|
messages=[
|
||||||
]
|
UserMessage(role='user', content="list my github repos")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
print(result.turn.output[-1].content)
|
||||||
|
print("Conversation ID:", result.conversationId)
|
||||||
|
|
||||||
# Get response
|
# Continue the conversation by passing the conversationId
|
||||||
response = client.chat(messages=messages)
|
result = client.run_turn(
|
||||||
print(response.messages[-1].content)
|
messages=[
|
||||||
|
UserMessage(role='user', content="how many did you find?")
|
||||||
# For subsequent messages, you need to manage the message history and state manually
|
],
|
||||||
messages.extend(response.messages)
|
conversationId=result.conversationId
|
||||||
messages.append(UserMessage(role='user', content="What's your name?"))
|
)
|
||||||
response = client.chat(messages=messages, state=response.state)
|
print(result.turn.output[-1].content)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using Tool Overrides (Mock Tools)
|
||||||
|
|
||||||
|
You can provide tool override instructions to test a specific configuration using the `mockTools` argument:
|
||||||
|
|
||||||
|
```python
|
||||||
|
result = client.run_turn(
|
||||||
|
messages=[
|
||||||
|
UserMessage(role='user', content="What's the weather?")
|
||||||
|
],
|
||||||
|
mockTools={
|
||||||
|
"weather_lookup": "The weather in any city is sunny and 25°C.",
|
||||||
|
"calculator": "The result of any calculation is 42."
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print(result.turn.output[-1].content)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Message Types
|
||||||
|
|
||||||
|
You can use different message types as defined in `rowboat.schema`, such as `UserMessage`, `SystemMessage`, etc. See `schema.py` for all available message types.
|
||||||
|
|
||||||
|
### Error Handling
|
||||||
|
|
||||||
|
If the API returns a non-200 status code, a `ValueError` will be raised with the error details.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
For more advanced usage, see the docstrings in `client.py` and the message schemas in `schema.py`.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "rowboat"
|
name = "rowboat"
|
||||||
version = "5.0.0"
|
version = "5.0.1"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Ramnique Singh", email = "ramnique@rowboatlabs.com" },
|
{ name = "Ramnique Singh", email = "ramnique@rowboatlabs.com" },
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue