聊天补全
curl --request POST \
--url https://infistar.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "你是一个有帮助的助手"
},
{
"role": "user",
"content": "你好"
}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": false
}
'import requests
url = "https://infistar.ai/v1/chat/completions"
payload = {
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "你是一个有帮助的助手"
},
{
"role": "user",
"content": "你好"
}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-4',
messages: [{role: 'system', content: '你是一个有帮助的助手'}, {role: 'user', content: '你好'}],
temperature: 0.7,
max_tokens: 1000,
stream: false
})
};
fetch('https://infistar.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://infistar.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-4',
'messages' => [
[
'role' => 'system',
'content' => '你是一个有帮助的助手'
],
[
'role' => 'user',
'content' => '你好'
]
],
'temperature' => 0.7,
'max_tokens' => 1000,
'stream' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://infistar.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://infistar.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://infistar.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么可以帮助你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 30,
"total_tokens": 50
}
}文本与对话
聊天补全
对话补全接口,用于 AI 对话交互。支持流式和非流式响应。
POST
/
v1
/
chat
/
completions
聊天补全
curl --request POST \
--url https://infistar.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "你是一个有帮助的助手"
},
{
"role": "user",
"content": "你好"
}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": false
}
'import requests
url = "https://infistar.ai/v1/chat/completions"
payload = {
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "你是一个有帮助的助手"
},
{
"role": "user",
"content": "你好"
}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-4',
messages: [{role: 'system', content: '你是一个有帮助的助手'}, {role: 'user', content: '你好'}],
temperature: 0.7,
max_tokens: 1000,
stream: false
})
};
fetch('https://infistar.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://infistar.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-4',
'messages' => [
[
'role' => 'system',
'content' => '你是一个有帮助的助手'
],
[
'role' => 'user',
'content' => '你好'
]
],
'temperature' => 0.7,
'max_tokens' => 1000,
'stream' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://infistar.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://infistar.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://infistar.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-4\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"你是一个有帮助的助手\"\n },\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000,\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么可以帮助你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 30,
"total_tokens": 50
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Response
200 - application/json
成功
⌘I