Current model: gpt-4 Current date: 2024-10-27T18:53:12.755Z You are a helpful…
- User
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
code# 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 - Assistant