Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
docs: 将示例更改为可折叠的样式
Browse files Browse the repository at this point in the history
  • Loading branch information
LinLin00000000 committed Jun 10, 2023
1 parent c89692e commit 7401164
Showing 1 changed file with 135 additions and 109 deletions.
244 changes: 135 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,125 +37,151 @@

## 示例

- Postman
![Example of Postman, Header](doc/2023-06-10-11-10-29.png)
![Example of Postman, Body](doc/2023-06-10-11-12-09.png)
<details><summary>Postman</summary>
<p>

以下代码均由 Postman 生成

- cURL

```bash
curl --location 'https://YOUR DOMAIN(改成你的域名)/v1/chat/completions' \
--header 'Authorization: Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
}
'
![Example of Postman, Header](doc/2023-06-10-11-10-29.png)
![Example of Postman, Body](doc/2023-06-10-11-12-09.png)

```
</p>
</details>

- Python - Requests
以下代码均由 Postman 生成

```python
import requests
import json
<details><summary>cURL</summary>
<p>

url = "https://YOUR DOMAIN(改成你的域名)/v1/chat/completions"
```bash
curl --location 'https://YOUR DOMAIN(改成你的域名)/v1/chat/completions' \
payload = json.dumps({
--header 'Authorization: Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
{
"role": "user",
"content": "你好"
}
]
})
headers = {
'Authorization': 'Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)',
}
'
```

</p>
</details>

<details><summary>Python - Requests</summary>
<p>

```python
import requests
import json
url = "https://YOUR DOMAIN(改成你的域名)/v1/chat/completions"
payload = json.dumps({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
})
headers = {
'Authorization': 'Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
```

</p>
</details>

<details><summary>NodeJs - Axios</summary>
<p>

```javascript
const axios = require('axios');
let data = JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://YOUR DOMAIN(改成你的域名)/v1/chat/completions',
headers: {
'Authorization': 'Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
```

- NodeJs - Axios

```javascript
const axios = require('axios');
let data = JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://YOUR DOMAIN(改成你的域名)/v1/chat/completions',
headers: {
'Authorization': 'Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```

- JavaScript - Fetch

```javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://YOUR DOMAIN(改成你的域名)/v1/chat/completions", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
```

- 飞书机器人
![Example of Feishu robot](doc/2023-06-10-11-44-29.png)
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```

</p>
</details>

<details><summary>JavaScript - Fetch</summary>
<p>

```javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer sk-xxxxxxxxxxxxx(改成你的APIKEY)");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "你好"
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://YOUR DOMAIN(改成你的域名)/v1/chat/completions", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
```

</p>
</details>

<details><summary>飞书机器人</summary>
<p>

![Example of Feishu robot](doc/2023-06-10-11-44-29.png)

</p>
</details>

## 部署

Expand Down

0 comments on commit 7401164

Please sign in to comment.