This library provides the functions to complete the conversation via SSE between client and LLM
Project description
AXMP AI Conversation Completor
A Python library for handling Server-Sent Events (SSE) communication between clients and Large Language Models (LLMs). This library provides a robust way to stream AI responses and handle tool calls in real-time conversations.
Features
- Server-Sent Events (SSE) streaming support
- Real-time AI message streaming
- Tool calls handling and streaming
- Structured response formatting
- Async/await support
- Type hints and validation using Pydantic models
Installation
pip install axmp-ai-conversation-completor
Quick Start
from axmp_ai_conversation_completor import generate_sse_response
@router.post(
"/conversations/{thread_id}/completion",
summary="Chat with the alert AI agent",
response_class=EventSourceResponse,
response_model=EventStreamResponse,
)
async def conversations_completion(
request: Request,
aiops_chat_request: AIOpsChatRequest,
thread_id: str = Path(..., description="Thread ID"),
) -> EventSourceResponse:
"""docstring..."""
# some source...
config = RunnableConfig(
configurable=Configuration(
thread_id=thread_id,
user_id=user_id,
model=llm_model,
temperature=temperature,
max_tokens=aiops_settings.chatops_model_max_tokens,
).model_dump(),
recursion_limit=recursion_limit,
)
messages = [chat_request.prompt]
inputs = ChatOpsState(
messages=[
HumanMessage(content=messages[0]),
]
)
response = chatops_agent.astream(inputs, config, stream_mode=stream_mode)
return EventSourceResponse(
generate_sse_response(
response,
thread_id,
llm_model=llm_model,
stream_mode=stream_mode
)
)
API Reference
generate_sse_response(response, thread_id, *, llm_model=None, stream_mode="messages")
Generates Server-Sent Events (SSE) responses for AI conversations.
Parameters:
response(AsyncIterator[dict[str, Any] | Any]): The response iterator from the LLMthread_id(str): Unique identifier for the conversation threadllm_model(str | None): Name of the LLM model being usedstream_mode(str): Mode of streaming, defaults to "messages"
Returns:
- AsyncIterator[EventStreamResponse]: An async iterator yielding SSE events
Event Types:
- MESSAGE_START: Indicates the start of a new message
- CONTENT_BLOCK_START: Indicates the start of a content block
- CONTENT_BLOCK_DELTA: Contains incremental updates to the content
- CONTENT_BLOCK_STOP: Indicates the end of a content block
- MESSAGE_STOP: Indicates the end of a message
Project Structure
src/axmp_ai_conversation_completor/
├── __init__.py
├── completion/
│ └── sse_reponse_generator.py
├── scheme/
│ └── chat_messages.py
└── util/
└── graph_stream_utils.py
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Authors
- Kilsoo Kang (kilsoo75@gmail.com)
Acknowledgments
- Thanks to all contributors who have helped shape this library
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 axmp_ai_conversation_completor-0.1.6.tar.gz.
File metadata
- Download URL: axmp_ai_conversation_completor-0.1.6.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a57e2f9d4c63a0a5524befa6ee635dfe55a9ebf9b874fcd68def16294ae4932
|
|
| MD5 |
c2b8152b519d40d70bd1cea2e8e826f3
|
|
| BLAKE2b-256 |
23fc07fa3ffdbb2acdece7f94f1f8d063bb9be2f0c9a880a8bdab4f4c89adb45
|
File details
Details for the file axmp_ai_conversation_completor-0.1.6-py3-none-any.whl.
File metadata
- Download URL: axmp_ai_conversation_completor-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775106f587a3d6b4f3bece0e13b23f555a1be26ac863c0775a20c2aa72496dc1
|
|
| MD5 |
c7b2a0348d5800506b2ba016ac9c9fcc
|
|
| BLAKE2b-256 |
fc0d107859c5cbbd543831167b44cfcb9610466e8413376ef045b5872bb8f36d
|