| import requests | |
| import json | |
| url = "https://api.openai-hk.com/v1/chat/completions" | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer hk-218wghmq4zcf4x42crjof0zlrpl4p22r96d44ola4wmyw92o" | |
| } | |
| data = { | |
| "max_tokens": 1200, | |
| "model": "gpt-3.5-turbo", | |
| "temperature": 0.8, | |
| "top_p": 1, | |
| "presence_penalty": 1, | |
| "messages": [ | |
| { | |
| "role": "system", | |
| "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible." | |
| }, | |
| { | |
| "role": "user", | |
| "content": "你是chatGPT多少?" | |
| } | |
| ] | |
| } | |
| response = requests.post(url, headers=headers, data=json.dumps(data).encode('utf-8') ) | |
| result = response.content.decode("utf-8") | |
| print(result) |