KhunK
Convex Community7mo ago
5 replies
Khun

Convex Python Error

Error message:
"detail": "Internal server error: Module path (chat.getChatByUserId) has an extension that isn't 'js'."
from .settings.convex_client import client


def get_chat_by_id(id: str):
    """Get chat by database ID"""
    return client.query("chat.getChatById", {"id": id})


def get_chat_by_user_id(user_id: str):
    """Get all chats for a specific user"""
    return client.query("chat.getChatByUserId", {"userId": user_id})


def get_chat_by_chat_id(chat_id: str):
    """Get chat by chatId field"""
    return client.query("chat.getChatByChatId", {"chatId": chat_id})


def add_messages(chat_id: str, messages: list):
    """Add messages to an existing chat
    
    Args:
        chat_id (str): The chatId of the chat to update
        messages (list): List of message objects with 'content', 'role', and 'timestamp'
    """
    return client.mutation("chat.addMessages", {
        "chatId": chat_id,
        "messages": messages
    })


def create_chat(chat_id: str, chat_name: str, user_id: str, ai_avatar_url=None, initial_message=None):
    """Create a new chat
    
    Args:
        chat_id (str): Unique identifier for the chat
        chat_name (str): Display name for the chat
        user_id (str): User ID who owns the chat
        ai_avatar_url (str, optional): URL for AI avatar
        initial_message (dict, optional): Initial message object
    """
    args = {
        "chatId": chat_id,
        "chatName": chat_name,
        "userId": user_id,
    }
    
    if ai_avatar_url:
        args["aiAvatarUrl"] = ai_avatar_url
        
    if initial_message:
        args["initialMessage"] = initial_message
    
    return client.mutation("chat.createChat", args) 

Anyone know how to fix this error?
Was this page helpful?