System: 
Current model: gpt-4
Current date: 2024-10-27T18:53:12.755Z

You are a helpful assistant. You can help me by answering my questions. You can also ask me questions.
User: Hello, who are you?
User: Ok so with this script:
from flask import Flask, request, jsonify
import requests
import json

app = Flask(__name__)

# AmigoChat headers
amigo_headers = {
    'Host': 'api.amigochat.io',
    'X-Device-Platform': 'android',
    'X-Device-Version': '11',
    'X-Device-Brand': 'samsung',
    'X-Device-Id': 'exynos9610134',
    'X-App-Build-Number': '12',
    'X-App-Version': '1.0',
    'X-App-Default-Lang': 'it',
    'Content-Type': 'application/json',
    'User-Agent': 'okhttp/4.12.0',
}

# Function to convert OpenAI request to AmigoChat format
def convert_openai_to_amigochat(request_json):
    amigochat_request = {
        'messages': [
            {'role': 'system', 'content': request_json['messages'][0]['content']},
            {'role': 'user', 'content': request_json['messages'][1]['content']}
        ],
        'model': 'o1-preview',
        'frequency_penalty': request_json.get('frequency_penalty', 0),
        'max_tokens': request_json.get('max_tokens', 4000),
        'presence_penalty': request_json.get('presence_penalty', 0),
        'stream': request_json.get('stream', False),
        'temperature': request_json.get('temperature', 0.1),
        'top_p': request_json.get('top_p', 0.95),
    }
    return amigochat_request

# Function to convert AmigoChat response to OpenAI format
def convert_amigochat_to_openai(amigochat_response):
    choices = amigochat_response['choices']
    openai_response = {
        'id': amigochat_response['id'],
        'object': 'chat.completion',
        'created': amigochat_response['created'],
        'model': amigochat_response['model'],
        'choices': [
            {
                'index': choice['index'],
                'message': {
                    'role': 'assistant',
                    'content': choice['delta']['content']
                },
                'finish_reason': choice['finish_reason']
            }
            for choice in choices
        ]
    }
    return openai_response

@app.route('/v1/chat/completions', methods=['POST'])
def completions():
    try:
        amigochat_response_content = request.data.decode('utf-8')
        print("Raw response content:", amigochat_response_content)  # Debugging line

        # Attempt to parse the JSON response
        amigochat_response_json = json.loads(amigochat_response_content)
        print("Parsed JSON:", amigochat_response_json)  # Debugging line

        return jsonify(amigochat_response_json)
    except json.JSONDecodeError as e:
        print("JSONDecodeError:", e)  # Debugging line
        return jsonify({"error": "JSONDecodeError", "message": str(e)}), 500
    except Exception as e:
        print("Exception:", e)  # Debugging line
        return jsonify({"error": "Exception", "message": str(e)}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

We get this output in the console:
PS C:\TMP\aiassist\amigochat> python .\proxy.py
 * Serving Flask app 'proxy'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
 * Running on http://192.168.0.118:5000
Press CTRL+C to quit
Raw response content: {"model":"o1-preview","messages":[{"role":"user","content":"\nCurrent model: o1-preview\nCurrent date: 2024-10-27T18:51:44.363Z\n\nYou are a helpful assistant. You can help me by answering my questions. You can also ask me questions."},{"role":"user","content":"Hello, who are you?"}]}
Parsed JSON: {'model': 'o1-preview', 'messages': [{'role': 'user', 'content': '\nCurrent model: o1-preview\nCurrent date: 2024-10-27T18:51:44.363Z\n\nYou are a helpful assistant. You can help me by answering my questions. You can also ask me questions.'}, {'role': 'user', 'content': 'Hello, who are you?'}]}
127.0.0.1 - - [27/Oct/2024 19:51:44] "POST /v1/chat/completions HTTP/1.1" 200 -

And the gui client shows this error:
Cannot read properties of undefined (reading '0')

Assistant: