gpt-4o-2024-05-13· OpenAI WildChat-4.8M (AI2)
curl https://chatgpt-api.shn.hk/v1/ \ -H 'Content-Type: application/json' \ -d '{…
- User
curl https://chatgpt-api.shn.hk/v1/
-H 'Content-Type: application/json'
-d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello, how are you?"}] }'python requests code
- Assistant
Certainly! Here’s how you can make the same request using the Python
requestslibrary:import requests import json url = "https://chatgpt-api.shn.hk/v1/" headers = { "Content-Type": "application/json" } data = { "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello, how are you?"}] } response = requests.post(url, headers=headers, data=json.dumps(data)) # Print the response from the API print(response.json())In this code:
requests.postis used to make a POST request to the provided URL.headersspecify the 'Content-Type' as 'application/json'.datacontains the payload we want to send, which is a dictionary.json.dumps(data)converts the dictionarydatainto a JSON formatted string.- The response from the API is then printed in JSON format by using
response.json().
Make sure you have the
requestslibrary installed. You can install it using pip if you haven’t already:pip install requests