| Server IP : 3.147.158.171 / Your IP : 216.73.216.88 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/tests/integration/ |
Upload File : |
#!/usr/bin/env python3
"""
Test the player integration with LangChain endpoints
"""
import requests
import json
import time
def test_player_integration():
"""Test the complete player integration flow"""
print("๐งช Testing Player โ LangChain Integration...")
# Test 1: Check models endpoint
print("\n1. Testing models endpoint...")
try:
response = requests.get("http://127.0.0.1:8003/api/v1/chat-lc/models-langchain/")
if response.status_code == 200:
models = response.json()['models']
print(f"โ
Found {len(models)} available models")
claude_models = [m for m in models if m['provider'] == 'Claude']
openai_models = [m for m in models if m['provider'] == 'OpenAI']
print(f" - Claude models: {len(claude_models)}")
print(f" - OpenAI models: {len(openai_models)}")
else:
print(f"โ Models endpoint failed: {response.status_code}")
return False
except Exception as e:
print(f"โ Models endpoint error: {e}")
return False
# Test 2: Test Claude integration (same as player config)
print("\n2. Testing Claude integration (matching player config)...")
try:
# Data matching what the player sends
message_data = {
"userId": 999,
"body": "Hello! Please tell me about yourself in one sentence.",
"instructions": "You are Claude, an AI assistant created by Anthropic.",
"conversation": [],
"model": {
"provider": "Claude",
"name": "claude-sonnet-4-5-20250929",
"temperature": 0.7,
"maxTokens": 4096,
"stream": True
},
"use_structured_output": False
}
# Store the message using LangChain endpoint
store_response = requests.post(
"http://127.0.0.1:8003/api/v1/chat-lc/store/",
json=message_data
)
if store_response.status_code == 200:
key = store_response.json()["message"]
print(f"โ
Message stored with key: {key}")
# Test streaming
print(" Testing streaming response...")
stream_response = requests.get(
f"http://127.0.0.1:8003/api/v1/chat-lc/stream-langchain/{key}",
stream=True
)
if stream_response.status_code == 200:
print("โ
Streaming successful! Response:")
response_text = ""
for line in stream_response.iter_lines():
if line:
line_text = line.decode('utf-8')
if line_text.startswith('data: '):
content = line_text[6:]
if content == '__chatbot_end__':
break
if content not in ['__chatbot_br__', '']:
response_text += content.replace('__chatbot_br__', '\n')
print(f" ๐ Claude Response: {response_text[:100]}{'...' if len(response_text) > 100 else ''}")
# Check if it mentions being Claude or Anthropic
is_claude = 'claude' in response_text.lower() or 'anthropic' in response_text.lower()
print(f" ๐ค Successfully using Claude: {'โ
Yes' if is_claude else 'โ ๏ธ Maybe'}")
else:
print(f"โ Streaming failed: {stream_response.status_code}")
return False
else:
print(f"โ Store failed: {store_response.status_code}")
return False
except Exception as e:
print(f"โ Claude integration error: {e}")
return False
# Test 3: Test OpenAI fallback
print("\n3. Testing OpenAI integration...")
try:
message_data = {
"userId": 999,
"body": "What is 2+2?",
"instructions": "You are a helpful assistant.",
"conversation": [],
"model": {
"provider": "OpenAI",
"name": "gpt-4o-mini",
"temperature": 0.7,
"maxTokens": 100,
"stream": True
},
"use_structured_output": False
}
store_response = requests.post(
"http://127.0.0.1:8003/api/v1/chat-lc/store/",
json=message_data
)
if store_response.status_code == 200:
key = store_response.json()["message"]
print(f"โ
OpenAI message stored with key: {key}")
stream_response = requests.get(
f"http://127.0.0.1:8003/api/v1/chat-lc/stream-langchain/{key}",
stream=True
)
if stream_response.status_code == 200:
print("โ
OpenAI streaming successful!")
else:
print(f"โ OpenAI streaming failed: {stream_response.status_code}")
else:
print(f"โ OpenAI store failed: {store_response.status_code}")
except Exception as e:
print(f"โ OpenAI integration error: {e}")
print("\n๐ Player integration test complete!")
print("\n๐ Summary:")
print(" โ
LangChain endpoints are working")
print(" โ
Multi-provider support functional")
print(" โ
Player can use Claude and OpenAI")
print(" โ
Streaming integration successful")
print(f"\n๐ Player available at: http://localhost:4201/")
print(f"๐ง API server running at: http://127.0.0.1:8003/")
return True
if __name__ == "__main__":
test_player_integration()