Skip to content

Commit bf3a675

Browse files
committed
Update LMNT example project: Revise README for clarity on LMNT voice generation, adjust workflow scheduling functions, and enhance service rate limits for improved performance.
1 parent cb934d8 commit bf3a675

File tree

5 files changed

+24
-33
lines changed

5 files changed

+24
-33
lines changed

community/lmnt/README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
11
# Restack AI - LMNT Example
22

33
This repository contains a simple example project to help you scale with Restack AI.
4-
It demonstrates how to scale reliably to millions of workflows on a local machine with a local LLM provider.
5-
6-
## Walkthrough video
7-
8-
https://www.youtube.com/watch?v=WsUtQYC74og
4+
It demonstrates how to scale reliably to millions of workflows on a local machine with LMNT voice generation.
95

106
## Motivation
117

128
When scaling AI workflows, you want to make sure that you can handle failures and retries gracefully.
13-
This example demonstrates how to do this with Restack AI.
9+
This example demonstrates how to do this with Restack AI and LMNT's voice generation API.
1410

1511
### Workflow Steps
1612

1713
The table below shows the execution of 50 workflows in parallel, each with three steps.
18-
Steps 2 and 3 are LLM functions that must adhere to a rate limit of 1 concurrent call per second.
14+
Steps 2 is LMNT voice generation functions that must adhere to a rate limit of 1 concurrent call per second.
1915

2016
| Step | Workflow 1 | Workflow 2 | ... | Workflow 50 |
2117
| ---- | ---------- | ---------- | --- | ----------- |
2218
| 1 | Basic | Basic | ... | Basic |
23-
| 2 | LLM | LLM | ... | LLM |
24-
| 3 | LLM | LLM | ... | LLM |
19+
| 2 | LMNT | LMNT | ... | LMNT |
2520

2621
### Traditional Rate Limit Management
2722

28-
When running multiple workflows in parallel, managing the rate limit for LLM functions is crucial. Here are common strategies:
23+
When running multiple workflows in parallel, managing the rate limit for LMNT functions is crucial. Here are common strategies:
2924

30-
1. **Task Queue**: Use a task queue (e.g., Celery, RabbitMQ) to schedule LLM calls, ensuring only one is processed at a time.
25+
1. **Task Queue**: Use a task queue (e.g., Celery, RabbitMQ) to schedule LMNT calls, ensuring only one is processed at a time.
3126
2. **Rate Limiting Middleware**: Implement middleware to queue requests and process them at the allowed rate.
32-
3. **Semaphore or Locking**: Use a semaphore or lock to control access, ensuring only one LLM function runs per second.
27+
3. **Semaphore or Locking**: Use a semaphore or lock to control access, ensuring only one LMNT function runs per second.
3328

3429
### With Restack
3530

3631
Restack automates rate limit management, eliminating the need for manual strategies. Define the rate limit in the service options, and Restack handles queuing and execution:
3732

3833
```python
3934
client.start_service(
40-
task_queue="llm",
41-
functions=[llm_generate, llm_evaluate],
35+
task_queue="lmnt",
36+
functions=[lmnt_list_voices, lmnt_synthesize],
4237
options=ServiceOptions(
4338
rate_limit=1,
4439
max_concurrent_function_runs=1
@@ -63,13 +58,7 @@ And for each child workflow, for each step you can see how long the function sta
6358
- Python 3.10 or higher
6459
- Poetry (for dependency management)
6560
- Docker (for running the Restack services)
66-
- Local LLM provider (we use LMStudio and a Meta Llama 3.1 8B Instruct 4bit model in this example)
67-
68-
## Start LM stduio for local LLM provider
69-
70-
Start local server with Meta Llama 3.1 8B Instruct 4bit model
71-
72-
https://lmstudio.ai
61+
- LMNT API key (sign up at https://www.lmnt.com)
7362

7463
## Prerequisites
7564

community/lmnt/schedule_interval.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import asyncio
22
import time
3+
from datetime import timedelta
34
from restack_ai import Restack
45
from restack_ai.restack import ScheduleSpec, ScheduleIntervalSpec
5-
from datetime import timedelta
66

7-
async def main():
7+
from src.client import client
88

9-
client = Restack()
9+
async def main():
1010

1111
workflow_id = f"{int(time.time() * 1000)}-ChildWorkflow"
1212
await client.schedule_workflow(
@@ -21,8 +21,8 @@ async def main():
2121

2222
exit(0)
2323

24-
def run_schedule_scale():
24+
def run_schedule_interval():
2525
asyncio.run(main())
2626

2727
if __name__ == "__main__":
28-
run_schedule_scale()
28+
run_schedule_interval()

community/lmnt/schedule_scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def main():
1212
await client.schedule_workflow(
1313
workflow_name="ExampleWorkflow",
1414
workflow_id=workflow_id,
15-
input=ExampleWorkflowInput(amount=50)
15+
input=ExampleWorkflowInput(max_amount=50)
1616
)
1717

1818
exit(0)

community/lmnt/schedule_workflow.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import time
33
from restack_ai import Restack
44

5-
async def main():
5+
from src.client import client
6+
from src.workflows.child import ChildWorkflowInput
67

7-
client = Restack()
8+
async def main():
89

9-
workflow_id = f"{int(time.time() * 1000)}-ExampleWorkflow"
10+
workflow_id = f"{int(time.time() * 1000)}-ChildWorkflow"
1011
run_id = await client.schedule_workflow(
1112
workflow_name="ChildWorkflow",
12-
workflow_id=workflow_id
13+
workflow_id=workflow_id,
14+
input=ChildWorkflowInput(name="Hi, my name is John Doe", voice="morgan")
1315
)
1416

1517
await client.get_workflow_result(

community/lmnt/src/services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ async def main():
2828
task_queue="lmnt",
2929
functions=[lmnt_synthesize, lmnt_list_voices],
3030
options=ServiceOptions(
31-
rate_limit=1,
32-
max_concurrent_function_runs=1
31+
rate_limit=2,
32+
max_concurrent_function_runs=4
3333
)
3434
)
3535
)

0 commit comments

Comments
 (0)