Skip to content

add parallel llm call demo #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demos/use_cases/llm_routing/parallel_calls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This demo shows how you can make parallel calls using python against arch gateway
47 changes: 47 additions & 0 deletions demos/use_cases/llm_routing/parallel_calls/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import asyncio
import aiohttp
import time

API_URL = "http://localhost:12000/v1/chat/completions"


async def fetch_response(
session: aiohttp.ClientSession, prompt: str
) -> aiohttp.ClientResponse:
headers = {
"Content-Type": "application/json",
}
payload = {"messages": [{"role": "user", "content": prompt}]}

start_time = time.monotonic()
async with session.post(API_URL, json=payload, headers=headers) as response:
result = await response.json()
end_time = time.monotonic()
elapsed_time = end_time - start_time
return prompt, result, elapsed_time


async def main():
prompts = [
"Hello!",
"Tell me a joke.",
"Who was the president of the United States in the 1990?",
]

async with aiohttp.ClientSession() as session:
tasks = [fetch_response(session, prompt) for prompt in prompts]

for completed in asyncio.as_completed(tasks):
prompt, result, elapsed_time = await completed
print("user prompt: ", prompt)
resp = result.get("choices")[0].get("message", {}).get("content", {})
print("assistant response: ", resp)
print(
f"logs: request time: {elapsed_time:.3f}s, model name: {result.get('model', '')}"
)
print()
for task in tasks:
task.close()


asyncio.run(main())
9 changes: 9 additions & 0 deletions demos/use_cases/llm_routing/parallel_calls/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "parallel-calls"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"aiohttp>=3.11.14",
]
Loading