1 Star 8 Fork 1

xing/zzz-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

优质稳定的Chat的API接口-For企业和开发者

重要!!

为了简单起见,后续仅维护github地址:https://github.com/xing61/zzz-api

  • 项目地址
    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/

    输入图片说明

API文档

注意事项!!

现在主要发现是有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

1、创建chat

调用本接口,发起一次对话请求

  • 请求URL

v1/chat/completions

  • 请求方式

POST

  • Header参数
名称 参数说明
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。
  • message说明
名称 类型 描述
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 (仅为估算逻辑)。
  • choice说明
名称 类型 描述
message message 见上文message说明。
index int 当前choice的序号。
finish_reason string 结束原因。
  • usage说明
名称 类型 描述
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
  }
}

2、Completions

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

2.1、Create completion

Creates a completion for the provided prompt and parameters.

  • 请求URL

v1/completions

  • 请求方式

POST

  • Header参数
名称
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 (仅为估算逻辑)。
  • choice说明
名称 类型 描述
text string 返回的文本
index int 当前choice的序号。
logprobs int 当前choice的logprobs。
finish_reason string 结束原因。
  • usage说明
名称 类型 描述
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
  }
}

3、图片-创建图片

Given a prompt and/or an input image, the model will generate a new image.

  • 请求URL

v1/images/generations

  • 请求方式

POST

  • Header参数
名称
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) 对话返回结果。
  • 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://..."
    }
  ]
}

4、Embeddings

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. Related guide: Embeddings

4.1、Create embeddings

Creates an embedding vector representing the input text.

  • 请求URL

v1/embeddings

  • 请求方式

POST

  • Header参数
名称
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
  }
}

空文件

简介

智增增,大模型的API接口服务商 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/smarttrot/zzz-api.git
git@gitee.com:smarttrot/zzz-api.git
smarttrot
zzz-api
zzz-api
master

搜索帮助

371d5123 14472233 46e8bd33 14472233