Khun
Khun2mo ago

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)
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?
5 Replies
Nicolas
Nicolas2mo ago
Hey, when using the non-JS clients you need to use a : separator between the module and the function name
Nicolas
Nicolas2mo ago
You can also check the function name you need to use on the dashboard
No description
Khun
KhunOP2mo ago
Apologies, I am new to this.
Khun
KhunOP2mo ago
so in my convex python file I would only need to do chat:getChats?
No description
Nicolas
Nicolas2mo ago
Yes exactly

Did you find this page helpful?