Framework for building AI assistants with streaming updates and user interactions
Project description
Tfy Assistant Framework
Overview
The Tfy Assistant Framework is a framework for building AI assistants with streaming updates and user interactions.
Installation
pip install tfy-assistant-framework
Usage
Simple chat assistant:
from tfy_assistant_framework.swarm import Agent, client
class Chat(Agent[Any]): ...
chat_agent = Chat(
instructions="Chat with the user",
)
async def run_chat_assistant() -> None:
async for agent_run in client.run(agent=chat_agent, messages=[], interactive=True):
agent_run.debug_log()
This can be run in console directly to chat with the assistant. To serve the assistant via FastAPI,
js: JetStreamContext
assistant_serve = AssistantServe()
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
global js
async with nats_connection() as (nc, js_):
js = js_
async with assistant_serve.init(nc=nc, app=app):
yield
app = FastAPI(
title="LLM Assistants Server",
lifespan=lifespan,
docs_url="/",
)
@app.post("/assistants/chat/task")
async def chat_task() -> CreateAssistantTaskRunResult:
task_id = uuid.uuid4().hex
return await assistant_serve.create_assistant_task(
task_id=task_id,
assistant_awaitable=run_chat_assistant(),
assistant_update_sink=NATSAssistantUpdateSink(task_id=task_id, js=js),
)
@app.post("/tasks/{task_id}/message")
async def send_message_to_assistant_task(
task_id: str,
message: PostAssistantTaskMessage,
) -> Response:
return await assistant_serve.send_message_to_assistant_task(task_id, message)
For more examples, see the examples directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tfy_assistant_framework-0.1.0rc1.tar.gz.
File metadata
- Download URL: tfy_assistant_framework-0.1.0rc1.tar.gz
- Upload date:
- Size: 73.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
201e7983cccc0e9754246c0ab1fd88a28e9b0965d871a64d1133d61a3ef4ba7d
|
|
| MD5 |
29ab369385b622f8689e315cc9483f47
|
|
| BLAKE2b-256 |
f5786f1dedc97de7de576fabd8947b83e0cbbff1cc20627f3f4e4511d4f71473
|
File details
Details for the file tfy_assistant_framework-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: tfy_assistant_framework-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fe1ef344aae15de297c2f3db957977af7900b3535f02158607288f287bb29c6
|
|
| MD5 |
08e6a13099dc06c69c0cbcb5d10440d5
|
|
| BLAKE2b-256 |
60a08b10b3c41447dc44763d5ce06c77c26c550f4792ecd00e44acd20c7bbf55
|