项目地址
1、项目官方网址:https://zhizengzeng.com
智增增-大模型的API接口服务商
开发者单独的Secret Key、余额查询、示例代码等可以从管理后台中获取。
2、微信交流群(如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流):
典型用法
典型用法:
1、设置OPENAI_API_KEY环境变量为:智增增后台获取的api_secret_key,替换官方的API_KEY: sk-******
2、设置OPENAI_API_BASE_URL环境变量为:https://api.zhizengzeng.com/v1/
, 替换官方的域名: https://api.openai.com/v1/
注意事项!!
现在主要发现是有2个问题,
1、要加一个请求头,api接口文档中有说明:
curl -H "Content-Type: application/json" -H "Authorization: Bearer $api_secret_key" -XPOST https://api.zhizengzeng.com/v1/chat/completions -d '{"messages": [{"role":"user","content":"请介绍一下你自己"}]}' | iconv -f utf-8 -t utf-8
2、messages传的不对,messages是array
注:
1、以下所有接口的base_url: https://api.zhizengzeng.com/
2、API通过HTTP请求调用。每次请求,需要在HTTP头中携带用户的api_secret_key,用于认证。 开发者单独的api_secret_key请从智增增后台获得
请求头形如:
Content-Type: application/json
Authorization: Bearer $api_secret_key
调用本接口,发起一次对话请求
POST
名称 | 值 | 参数说明 |
---|---|---|
Content-Type | application/json | |
Authorization | Bearer $api_secret_key | 开发者单独的api_secret_key |
请求参数 | 参数类型 | 是否必须 | 参数说明 |
---|---|---|---|
model | string | 否 | 大模型的类别,包括但不限于(基本所有官网的都支持,以官网为准 https://platform.openai.com/docs/models ):gpt-4-1106-preview,gpt-4-vision-preview,gpt-3.5-turbo-1106,gpt-3.5-turbo-instruct,gpt-4, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k, gpt-3.5-turbo-16k-0613。默认gpt-3.5-turbo |
messages | List(message) | 是 | 聊天上下文信息。说明: (1)messages成员不能为空,1个成员表示单轮对话,多个成员表示多轮对话。 (2)最后一个message为当前请求的信息,前面的message为历史对话信息。 (3)必须为奇数个成员,成员中message的role必须依次为user、assistant。 (4)最后一个message的content长度(即此轮对话的问题)不能超过2000个字符;如果messages中content总长度大于2000字符,系统会依次遗忘最早的历史会话,直到content的总长度不超过2000个字符。 |
stream | bool | 否 | 是否以流式接口的形式返回数据,默认false。 |
user | string | 否 | 表示最终用户的唯一标识符,可以监视和检测滥用行为,防止接口恶意调用。 |
其它高级参数:
请求参数 | 参数类型 | 是否必须 | 参数说明 |
---|---|---|---|
api_secret_key | string | 否 | 兼容老版接口,api_secret_key在header和此字段二者传其一即可。 注意:此字段将在后续版本中逐渐废弃 |
temperature | number | 否 | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.We generally recommend altering this or top_p but not both.,默认:1。 |
top_p | number | 否 | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.We generally recommend altering this or temperature but not both.,默认:1。 |
n | number | 否 | How many chat completion choices to generate for each input message. 默认:1。 |
stop | string | 否 | Up to 4 sequences where the API will stop generating further tokens.,默认null。 |
max_tokens | number | 否 | The maximum number of tokens to generate in the chat completion.The total length of input tokens and generated tokens is limited by the model's context length. Example Python code for counting tokens.默认: 不限制。 |
presence_penalty | number | 否 | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.,默认:0。 |
frequency_penalty | number | 否 | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.,默认:0。 |
logit_bias | map | 否 | Modify the likelihood of specified tokens appearing in the completion.Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.,默认:null。 |
名称 | 类型 | 描述 |
---|---|---|
role | string | The role of the messages author. One of system, user, assistant, or function. user: 表示用户 assistant: 表示对话助手 function:表示函数调用 |
content | string | 对话内容,不能为空。 |
返回参数 | 参数类型 | 参数说明 |
---|---|---|
code | int | 执行结果code |
msg | String | 执行结果消息 |
id | string | 本轮对话的id。 |
created | int | 时间戳。 |
choices | List(choice) | 对话返回结果。 |
usage | usage | token统计信息,token数 = 汉字数+单词数*1.3 (仅为估算逻辑)。 |
名称 | 类型 | 描述 |
---|---|---|
message | message | 见上文message说明。 |
index | int | 当前choice的序号。 |
finish_reason | string | 结束原因。 |
名称 | 类型 | 描述 |
---|---|---|
prompt_tokens | int | 问题tokens数。 |
completion_tokens | int | 回答tokens数。 |
total_tokens | int | tokens总数。 |
更多示例见本页:https://github.com/xing61/zzz-api/tree/main/示例代码
curl -H "Content-Type: application/json"
-H "Authorization: Bearer $api_secret_key"
-XPOST https://flag.smarttrot.com/v1/chat/completions -d '{
"messages": [
{"role":"user","content":"请介绍一下你自己"},
{"role":"assistant","content":"您好,我是智增增机器人。我能够与人对话互动,回答问题,协助创作,高效便捷地帮助人们获取信息、知识和灵感。"},
{"role":"user","content": "1+100="}
]
}' | iconv -f utf-8 -t utf-8
php示例代码:
// 设置请求头
$api_secret_key = 'xxxxxxxxxxxxxxxxxx'; // 你的api_secret_key
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer ".$api_secret_key,
);
// 设置请求参数
$params = array();
$params['user'] = '张三';
{
$one = ["role" => 'user', "content" => "1+100="];
$messages = array(); $messages[] = $one;
$params['messages'] = $messages;
}
// 调用请求
$cburl = 'https://api.zhizengzeng.com/v1/chat/completions';
$chatgpt_resp = Tool::_request('post', $cburl, $params, $headers);
$data = json_decode($chatgpt_resp, true);
python使用官方库示例代码:
import os
import openai
openai.api_key = "您的api_secret_key"
openai.api_base = "https://api.zhizengzeng.com/v1"
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{ "role": "user", "content": "Hello world" }]
)
print(chat_completion.choices[0].message.content)
python示例代码:
import os
import requests
import time
import json
def chat_completions():
url="https://api.zhizengzeng.com/v1/chat/completions"
api_secret_key = 'xxxxxxxxx'; # 你的api_secret_key
headers = {'Content-Type': 'application/json', 'Accept':'application/json',
'Authorization': "Bearer "+api_secret_key}
params = {'user':'张三',
'messages':[{'role':'user', 'content':'1+100='}]};
r = requests.post(url, json.dumps(params), headers=headers)
print(r.json())
if __name__ == '__main__':
chat_completions();
{
"code": 0,
"msg": "",
"id": "as-bcmt5ct4iy",
"created": 1680167072,
"choices":[{"message":{"role":"assistant","content":"1+100=101"},"finish_reason":"stop","index":0}],
"usage": {
"prompt_tokens": 470,
"completion_tokens": 198,
"total_tokens": 668
}
}
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
Creates a completion for the provided prompt and parameters.
POST
名称 | 值 |
---|---|
Content-Type | application/json |
Authorization | Bearer $api_secret_key |
请求参数 | 参数类型 | 是否必须 | 参数说明 |
---|---|---|---|
model | string | 是 | ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. |
prompt | string or array | 否 | The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that < |
suffix | string | 否 | The suffix that comes after a completion of inserted text.Defaults to null |
max_tokens | int | 否 | The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length. Example Python code for counting tokens.Defaults to 16 |
temperature | number | 否 | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.Defaults to 1 |
top_p | number | 否 | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.Defaults to 1 |
n | number | 否 | How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.Defaults to 1 |
stream | bool | 否 | Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Example Python code.Defaults to false |
logprobs | int | 否 | Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens. For example, if logprobs is 5, the API will return a list of the 5 most likely tokens. The API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. The maximum value for logprobs is 5. If you need more than this, please contact us through our Help center and describe your use case.Defaults to null |
echo | bool | 否 | Echo back the prompt in addition to the completion。Defaults to false |
stop | int | 是 | Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.Defaults to null |
presence_penalty | int | 否 | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties.Defaults to 0 |
frequency_penalty | int | 否 | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties.Defaults to 0 |
best_of | int | 否 | Generates best_of completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. When used with n, best_of controls the number of candidate completions and n specifies how many to return – best_of must be greater than n. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.Defaults to 1 |
logit_bias | map | 否 | Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass {"50256": -100} to prevent the < |
user | string | 否 | 表示最终用户的唯一标识符,可以监视和检测滥用行为,防止接口恶意调用。 |
返回参数 | 参数类型 | 参数说明 |
---|---|---|
code | int | 执行结果code |
msg | String | 执行结果消息 |
id | string | 本轮对话的id。 |
object | string | text_completion |
created | int | 时间戳。 |
model | string | 本次调用的模型 |
choices | List(choice) | 对话返回结果。 |
usage | usage | token统计信息,token数 = 汉字数+单词数*1.3 (仅为估算逻辑)。 |
名称 | 类型 | 描述 |
---|---|---|
text | string | 返回的文本 |
index | int | 当前choice的序号。 |
logprobs | int | 当前choice的logprobs。 |
finish_reason | string | 结束原因。 |
名称 | 类型 | 描述 |
---|---|---|
prompt_tokens | int | 问题tokens数。 |
completion_tokens | int | 回答tokens数。 |
total_tokens | int | tokens总数。 |
curl -H "Content-Type: application/json" -H "Authorization: Bearer $api_secret_key" -XPOST xxxxx/v1/chat/completions -d '{
"messages": [
{"role":"user","content":"请介绍一下你自己"}
]
}' | iconv -f utf-8 -t utf-8
{
"code": 0,
"msg": "",
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "text_completion",
"created": 1589478378,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nThis is indeed a test",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
Given a prompt and/or an input image, the model will generate a new image.
POST
名称 | 值 |
---|---|
Content-Type | application/json |
Authorization | Bearer $api_secret_key |
请求参数 | 参数类型 | 是否必须 | 参数说明 |
---|---|---|---|
prompt | string | 是 | A text description of the desired image(s). The maximum length is 1000 characters. |
n | int | 否 | The number of images to generate. Must be between 1 and 10. Defaults to 1 |
size | string | 否 | The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024. Defaults to 1024x1024 |
response_format | string | 否 | The format in which the generated images are returned. Must be one of url or b64_json. Defaults to url |
user | string | 否 | 表示最终用户的唯一标识符,可以监视和检测滥用行为,防止接口恶意调用。 |
返回参数 | 参数类型 | 参数说明 |
---|---|---|
code | int | 执行结果code |
msg | String | 执行结果消息 |
created | int | 时间戳。 |
data | List(img) | 对话返回结果。 |
名称 | 类型 | 描述 |
---|---|---|
url | string | 当前图片的地址url |
curl -H "Content-Type: application/json" -H "Authorization: Bearer $api_secret_key" -XPOST xxxxx/v1/images/generations -d '{
"prompt": "A cute baby sea otter",
}' | iconv -f utf-8 -t utf-8
{
"code": 0,
"msg": "",
"created": 1680167072,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. Related guide: Embeddings
Creates an embedding vector representing the input text.
POST
名称 | 值 |
---|---|
Content-Type | application/json |
Authorization | Bearer $api_secret_key |
请求参数 | 参数类型 | 是否必须 | 参数说明 |
---|---|---|---|
model | string | 是 | ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. 默认:text-embedding-ada-002(官方推荐) |
input | string | 是 | Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. Each input must not exceed the max input tokens for the model (8191 tokens for text-embedding-ada-002). Example Python code for counting tokens. |
user | string | 否 | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
curl -H "Content-Type: application/json" -H "Authorization: Bearer $api_secret_key" -XPOST xxxxx/v1/embeddings -d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002"
}' | iconv -f utf-8 -t utf-8
{
"code": 0,
"msg": "",
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。