Files
ds_zagres_ai/test_chat_with_params.py
T
2025-05-09 15:41:16 +01:00

70 lines
1.8 KiB
Python

"""
Test script for sending a message with advanced parameters.
"""
import requests
import json
import uuid
# Create a new chat
def create_chat():
response = requests.post(
"http://localhost:5251/chats",
json={
"user_id": "test_user",
"title": "Test Chat",
"model_id": "gpt-3.5-turbo",
"is_team_chat": False
}
)
if response.status_code == 200:
return response.json()["id"]
else:
print(f"Error creating chat: {response.status_code}")
print(response.text)
return None
# Send a message with advanced parameters
def send_message(chat_id):
response = requests.post(
f"http://localhost:5251/chats/{chat_id}/messages",
json={
"message": "Tell me about artificial intelligence",
"user_id": "test_user",
"use_rag": False,
"temperature": 0.7,
"max_tokens": 500,
"top_p": 0.9,
"frequency_penalty": 0.5,
"presence_penalty": 0.5,
"system_prompt": "You are a helpful AI assistant that provides concise responses."
}
)
if response.status_code == 200:
return response.json()
else:
print(f"Error sending message: {response.status_code}")
print(response.text)
return None
# Main function
def main():
print("Creating a new chat...")
chat_id = create_chat()
if chat_id:
print(f"Chat created with ID: {chat_id}")
print("\nSending a message with advanced parameters...")
response = send_message(chat_id)
if response:
print("\nResponse received:")
print(f"Message ID: {response['id']}")
print(f"Content: {response['content']}")
if __name__ == "__main__":
main()