Current model: gpt-4 Current date: 2024-10-27T18:14:48.459Z You are a helpful…
- User
System: Current model: gpt-4 Current date: 2024-10-27T18:14:48.459Z
You are a helpful assistant. You can help me by answering my questions. You can also ask me questions. User: I have a python script that makes requests to the backend of a service called amigochat, that is based on gpt. I'd like to use this service with an openai api compatible client. I'll provide you the script and an example response, and you'll write a python script that acts as an intermediary / middleware for converting the requests and response from openai api format to amigochat format and viceversa. Here's the script: import requests
headers = { 'Host': 'api.amigochat.io', 'X-Device-Platform': 'android', 'X-Device-Version': '11', 'X-Device-Brand': 'samsung', 'X-Device-Id': 'exynos96101', 'X-App-Build-Number': '12', 'X-App-Version': '1.0', 'X-App-Default-Lang': 'it', 'Content-Type': 'application/json', # 'Content-Length': '352', # 'Accept-Encoding': 'gzip, deflate, br', 'User-Agent': 'okhttp/4.12.0', }
json_data = { 'messages': [ { 'role': 'system', 'content': 'You are OpenAI o1. If the response includes mathematical expressions, wrap them in markdown symbols ```math.', }, { 'role': 'user', 'content': 'Write a python script for fibonacci pls', }, ], 'model': 'o1-preview', 'frequency_penalty': 0, 'max_tokens': 4000, 'presence_penalty': 0, 'stream': False, 'temperature': 0.1, 'top_p': 0.95, }
response = requests.post('https://api.amigochat.io/v1/chat/completions', headers=headers, json=json_data, verify=False)
print(response.content)
Note: json_data will not be serialized by requests
exactly as it was in the original request.
#data = '{"messages":[{"role":"system","content":"You are OpenAI o1. If the response includes mathematical expressions, wrap them in markdown symbols ```math."},{"role":"user","content":"How do I solve partial derivatives equations"}],"model":"o1-mini","frequency_penalty":0,"max_tokens":4000,"presence_penalty":0,"stream":false,"temperature":0.5,"top_p":0.95}' #response = requests.post('https://api.amigochat.io/v1/chat/completions', headers=headers, data=data, verify=False)
Here's the output of the script: PS C:\TMP\aiassist\amigochat> python .\request.py C:\Users\Giovanni\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.amigochat.io'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings warnings.warn( b'data: {"id":"chatcmpl-AN204xMe5A9Fs0BgsruI3xCMEJhMv","object":"chat.completion.chunk","created":1730052596,"model":"o1-preview-2024-09-12","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"Certainly! Here's a Python script that generates the Fibonacci sequence up to a specified number of terms:\n\n\n\n\n\nThe Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. Mathematically, it's defined by the recurrence relation:\n\n\n\nwith seed values:\n\n\n\nIn the script:\n\n- We define a function that generates the sequence up to terms.\n- We initialize the first two numbers of the sequence ( and ) as 0 and 1.\n- We use a loop to calculate subsequent numbers by updating and .\n\n\n\nIf you run the script and input , it will output:\n\n\n\nFeel free to modify the script or let me know if you have any questions!"},"logprobs":null,"finish_reason":"stop"}]}\n\ndata: [DONE]\n\n'
- Assistant