403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/api/tests/integration/player_flow_manual.py
#!/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()

Youez - 2016 - github.com/yon3zu
LinuXploit