Files
voyage/backend/server/chat/models.py
alex 757140ec70 feat(chat): add LLM-powered travel agent with multi-provider support
Implement a full chat-based travel agent using LiteLLM for multi-provider
LLM support (OpenAI, Anthropic, Gemini, Ollama, Groq, Mistral, etc.).

Backend:
- New 'chat' Django app with ChatConversation and ChatMessage models
- Streaming SSE endpoint via StreamingHttpResponse
- 5 agent tools: search_places, list_trips, get_trip_details,
  add_to_itinerary, get_weather
- LiteLLM client wrapper with per-user API key retrieval
- System prompt with user preference context injection

Frontend:
- New /chat route with full-page chat UI (DaisyUI + Tailwind)
- Collapsible conversation sidebar with CRUD
- SSE streaming response display with tool call visualization
- Provider selector dropdown
- SSE proxy fix to stream text/event-stream without buffering
- Navbar link and i18n keys
2026-03-08 18:44:44 +00:00

48 lines
1.5 KiB
Python

import uuid
from django.conf import settings
from django.db import models
class ChatConversation(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="chat_conversations",
)
title = models.CharField(max_length=255, blank=True, default="")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-updated_at"]
def __str__(self):
return f"{self.title or 'Untitled'} ({self.user.username})"
class ChatMessage(models.Model):
ROLE_CHOICES = [
("user", "User"),
("assistant", "Assistant"),
("system", "System"),
("tool", "Tool"),
]
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
conversation = models.ForeignKey(
ChatConversation,
on_delete=models.CASCADE,
related_name="messages",
)
role = models.CharField(max_length=20, choices=ROLE_CHOICES)
content = models.TextField(blank=True, default="")
tool_calls = models.JSONField(null=True, blank=True)
tool_call_id = models.CharField(max_length=255, blank=True, null=True)
name = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["created_at"]