allow specific workflow id in api

This commit is contained in:
ramnique 2025-02-14 23:30:02 +05:30
parent 64312e2d5c
commit 36135ed810
6 changed files with 61 additions and 12 deletions

View file

@ -81,4 +81,39 @@ chat = StatefulChat(
response = chat.run("Hello, how are you?")
print(response)
# I'm good, thanks! How can I help you today?
```
```
### Advanced Usage
#### Using a specific workflow
```python
response_messages, state = client.chat(
messages=messages,
workflow_id="<WORKFLOW_ID>"
)
# or
chat = StatefulChat(
client,
workflow_id="<WORKFLOW_ID>"
)
```
#### Skip tool call runs
This will surface the tool calls to the SDK instead of running them automatically on the Rowboat server.
```python
response_messages, state = client.chat(
messages=messages,
skip_tool_calls=True
)
# or
chat = StatefulChat(
client,
skip_tool_calls=True
)
```

View file

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

View file

@ -26,13 +26,15 @@ class Client:
messages: List[ApiMessage],
state: Optional[Dict[str, Any]] = None,
skip_tool_calls: bool = False,
max_turns: int = 3
max_turns: int = 3,
workflow_id: Optional[str] = None
) -> ApiResponse:
request = ApiRequest(
messages=messages,
state=state,
skipToolCalls=skip_tool_calls,
maxTurns=max_turns
maxTurns=max_turns,
workflowId=workflow_id
)
response = requests.post(self.base_url, headers=self.headers, data=request.model_dump_json())
@ -80,7 +82,8 @@ class Client:
tools: Optional[Dict[str, Callable[..., str]]] = None,
state: Optional[Dict[str, Any]] = None,
max_turns: int = 3,
skip_tool_calls: bool = False
skip_tool_calls: bool = False,
workflow_id: Optional[str] = None
) -> Tuple[List[ApiMessage], Optional[Dict[str, Any]]]:
"""Stateless chat method that handles a single conversation turn with multiple tool call rounds"""
@ -98,7 +101,8 @@ class Client:
messages=current_messages,
state=current_state,
skip_tool_calls=skip_tool_calls,
max_turns=max_turns
max_turns=max_turns,
workflow_id=workflow_id
)
current_messages.extend(response_data.messages)
@ -136,7 +140,8 @@ class StatefulChat:
tools: Optional[Dict[str, Callable[..., str]]] = None,
system_prompt: Optional[str] = None,
max_turns: int = 3,
skip_tool_calls: bool = False
skip_tool_calls: bool = False,
workflow_id: Optional[str] = None
) -> None:
self.client = client
self.tools = tools
@ -144,7 +149,7 @@ class StatefulChat:
self.state: Optional[Dict[str, Any]] = None
self.max_turns = max_turns
self.skip_tool_calls = skip_tool_calls
self.workflow_id = workflow_id
if system_prompt:
self.messages.append(SystemMessage(role='system', content=system_prompt))
@ -161,7 +166,8 @@ class StatefulChat:
tools=self.tools,
state=self.state,
max_turns=self.max_turns,
skip_tool_calls=self.skip_tool_calls
skip_tool_calls=self.skip_tool_calls,
workflow_id=self.workflow_id
)
# Update internal state

View file

@ -50,6 +50,7 @@ class ApiRequest(BaseModel):
state: Any
skipToolCalls: Optional[bool] = None
maxTurns: Optional[int] = None
workflowId: Optional[str] = None
class ApiResponse(BaseModel):
messages: List[ApiMessage]