feat: langchain improved

This commit is contained in:
Musa 2026-01-16 13:10:03 -08:00
parent 5cf67a8189
commit 6efaa0cf8d
11 changed files with 1702 additions and 0 deletions

View file

@ -0,0 +1,35 @@
"""OpenAI API protocol utilities for standardized response formatting."""
import time
import uuid
from typing import Optional
def create_chat_completion_chunk(
model: str,
content: str,
finish_reason: Optional[str] = None,
) -> dict:
"""Create an OpenAI-compatible streaming chat completion chunk.
Args:
model: Model identifier to include in the response
content: Content text for this chunk
finish_reason: Optional finish reason ('stop', 'length', etc.)
Returns:
Dictionary formatted as OpenAI chat.completion.chunk
"""
return {
"id": f"chatcmpl-{uuid.uuid4().hex[:8]}",
"object": "chat.completion.chunk",
"created": int(time.time()),
"model": model,
"choices": [
{
"index": 0,
"delta": {"content": content} if content else {},
"finish_reason": finish_reason,
}
],
}