103 lines
3.0 KiB
Bash
Executable File
103 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Stop any existing service
|
|
pkill -f "uvicorn ai_service.api:app" || true
|
|
|
|
# Create data directory if it doesn't exist
|
|
mkdir -p ai_service/data
|
|
|
|
# Set environment variables for testing
|
|
# In production, replace these with your actual API keys
|
|
export PINECONE_API_KEY="test-pinecone-api-key"
|
|
export PINECONE_ENVIRONMENT="test-pinecone-environment"
|
|
export OPENAI_API_KEY="test-openai-api-key"
|
|
|
|
# Create empty files for local storage if they don't exist
|
|
touch ai_service/data/chatbot.db
|
|
touch ai_service/data/document_metadata.json
|
|
touch ai_service/data/chats.json
|
|
|
|
# For testing purposes, we'll use a simplified API
|
|
echo "Starting Simple API Service on port 5251..."
|
|
VENV_PATH="./venv"
|
|
PYTHON_PATH="$VENV_PATH/bin/python"
|
|
|
|
# Check if the virtual environment exists
|
|
if [ -f "$PYTHON_PATH" ]; then
|
|
echo "Using Python from virtual environment: $PYTHON_PATH"
|
|
# Use the simplified API for testing
|
|
nohup $PYTHON_PATH simple_api.py > ai_service.log 2>&1 &
|
|
else
|
|
echo "Virtual environment not found at $VENV_PATH, using system Python"
|
|
nohup python simple_api.py > ai_service.log 2>&1 &
|
|
fi
|
|
|
|
# Wait a moment for the service to start
|
|
sleep 2
|
|
|
|
# Check if the service is running
|
|
if pgrep -f "simple_api.py" > /dev/null; then
|
|
echo "AI Service started successfully on port 5251"
|
|
echo "Check ai_service.log for output"
|
|
echo "To stop the service, run: pkill -f \"simple_api.py\""
|
|
|
|
# Test the health endpoint
|
|
echo -e "\nTesting health endpoint..."
|
|
curl -s http://localhost:5251/health
|
|
echo -e "\n"
|
|
|
|
# Test creating a chat and sending a message
|
|
echo "Testing chat creation and message sending..."
|
|
if [ -f "$PYTHON_PATH" ]; then
|
|
# Create a simple test script
|
|
cat > test_api.py << 'EOF'
|
|
import requests
|
|
import json
|
|
|
|
# Create a chat
|
|
response = requests.post(
|
|
"http://localhost:5251/chats",
|
|
json={
|
|
"user_id": "test_user",
|
|
"title": "Test Chat",
|
|
"model_id": "gpt-3.5-turbo"
|
|
}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
chat_id = response.json()["id"]
|
|
print(f"Chat created with ID: {chat_id}")
|
|
|
|
# Send a message with parameters
|
|
response = requests.post(
|
|
f"http://localhost:5251/chats/{chat_id}/messages",
|
|
json={
|
|
"message": "Hello, AI!",
|
|
"user_id": "test_user",
|
|
"temperature": 0.7,
|
|
"max_tokens": 100
|
|
}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
print("Message sent successfully")
|
|
print(f"Response: {response.json()['content'][:100]}...")
|
|
else:
|
|
print(f"Error sending message: {response.status_code}")
|
|
print(response.text)
|
|
else:
|
|
print(f"Error creating chat: {response.status_code}")
|
|
print(response.text)
|
|
EOF
|
|
|
|
# Run the test script with the virtual environment's Python
|
|
$PYTHON_PATH test_api.py
|
|
rm test_api.py
|
|
else
|
|
echo "Skipping API test as virtual environment Python is not available"
|
|
fi
|
|
else
|
|
echo "Failed to start AI Service. Check ai_service.log for errors."
|
|
exit 1
|
|
fi
|