update readme w.r.t sdk

This commit is contained in:
ramnique 2025-01-15 20:29:50 +05:30
parent e868e4520a
commit 696cee8ed5
3 changed files with 64 additions and 30 deletions

View file

@ -77,9 +77,36 @@ Before running RowBoat, ensure you have:
4. **Access the App**
- Visit [http://localhost:3000](http://localhost:3000).
5. **Use the API**
5. **Interact with RowBoat**
You can use the API at [http://localhost:3000/api/v1/](http://localhost:3000/api/v1/)
There are two ways to interact with RowBoat:
### Option 1: Python SDK
For Python applications, we provide an official SDK for easier integration:
```bash
pip install rowboat
```
```python
from rowboat import Client
client = Client(
host="http://localhost:3000",
project_id="<PROJECT_ID>",
project_secret="<PROJECT_SECRET>"
)
# Simple chat interaction
messages = [{"role": "user", "content": "Tell me the weather in London"}]
response_messages, state = client.chat(messages=messages)
```
For more details, see the [Python SDK documentation](./apps/python-sdk/README.md).
### Option 2: HTTP API
You can use the API directly at [http://localhost:3000/api/v1/](http://localhost:3000/api/v1/)
- Project ID is available in the URL of the project page
- Project Secret is available in the project config page

View file

@ -14,10 +14,11 @@ pip install rowboat
### Basic Usage
Initialize a client and create a chat session:
Initialize a client and use the chat method directly:
```python
from rowboat import Client, StatefulChat
from rowboat import Client
from rowboat.schema import UserMessage, SystemMessage
# Initialize the client
client = Client(
@ -26,21 +27,28 @@ client = Client(
project_secret="<PROJECT_SECRET>"
)
# Create a chat session
chat = StatefulChat(client)
# Create messages
messages = [
SystemMessage(role='system', content="You are a helpful assistant"),
UserMessage(role='user', content="Hello, how are you?")
]
# Send a message and get a response
response = chat.run("Hello, how are you?")
print(response)
# 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)
```
### Using Tools
The SDK supports function calling through tools. Here's how to use them:
The SDK supports function calling through tools:
```python
def weather_lookup(city_name: str) -> str:
# Implement your weather lookup logic here
return f"The weather in {city_name} is 22°C."
# Create a tools dictionary
@ -48,24 +56,31 @@ tools = {
'weather_lookup': weather_lookup
}
# Initialize chat with tools
chat = StatefulChat(client, tools=tools)
# The AI can now use the weather tool
response = chat.run("What's the weather in London?")
print(response)
# Use tools with the chat method
response_messages, state = client.chat(
messages=messages,
tools=tools
)
```
### System Prompts
### Stateful Chat (Convenience Wrapper)
You can initialize the chat with a system prompt to guide the AI's behavior:
For simpler use cases, the SDK provides a `StatefulChat` class that maintains conversation state automatically:
```python
from rowboat import StatefulChat
# Initialize stateful chat
chat = StatefulChat(
client,
tools=tools,
system_prompt="You are a helpful assistant who specializes in weather information."
system_prompt="You are a helpful assistant."
)
# 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?
```
## API Reference
@ -88,12 +103,4 @@ StatefulChat(
tools: Optional[Dict[str, Callable[..., str]]] = None,
system_prompt: Optional[str] = None
)
```
## License
[Add your license information here]
## Contributing
[Add contribution guidelines here]
```

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "rowboat"
version = "0.2.0"
version = "0.2.1"
authors = [
{ name = "Your Name", email = "your.email@example.com" },
]