# CURL 示例代码
curl --request POST
--url https://api.aigc-zh.cn/v1/chat/completions
--header 'Authorization: Bearer 替换为你的APIkey'
-H "Content-Type: application/json"
--data '{
"max_tokens": 4000,
"model": "gpt-3.5-turbo",
"temperature": 0.8,
"top_p": 1,
"presence_penalty": 1,
"messages": [
{
"role": "system",
"content": "This system content"
},
{
"role": "user",
"content": "pls,say test!"
}
]
}'
# Python调用示例代码
import os
from openai import OpenAI
client = OpenAI(
api_key="你的接口密钥",
base_url = "https://api.aigc-zh.cn/v1"
)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model="gpt-3.5-turbo",
)
print(chat_completion.choices[0].message.content)
# php示例代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.aigc-zh.cn/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer 替换为你的APIkey';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = array(
'max_tokens' => 3000,
'model' => 'gpt-3.5-turbo',
'temperature' => 0.8,
'top_p' => 1,
'presence_penalty' => 1,
'messages' => array(
array(
'role' => 'system',
'content' => 'This system content'
),
array(
'role' => 'user',
'content' => 'pls,say test!'
)
)
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;
# 小程序示例代码
wx.request({
url:'https://api.aigc-zh.cn/v1/chat/completions',
method: 'POST',
header: {
'Content-Type': 'application/json',
'Accept':'application/json',
// 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Authorization': 'Bearer {}'
},
data:JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你是谁"
}
]
}),
success: (result) => {
},
})
},
← 快速接入 ChatGPT开发文档 →