StableLM-Alpha -7B
所有文档
menu
没有找到结果,请重新输入

千帆大模型平台

StableLM-Alpha -7B

StableLM-Alpha-7B是Stability AI开发的7B参数的NeoX transformer架构语言模型,支持4k上下文。本文介绍了相关API。

创建completion

调用本接口,发起一次文本续写请求。

本文接口返回不支持图片内容,图片内容的请求返回会在后续支持,敬请期待!

请求地址: https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/completions/{申请发布时填写的API地址}

请求方式: POST

API地址说明

申请发布时填写的API地址,相关内容请查看 大模型服务使用说明-发布服务-服务配置

Header参数

# 步骤一,获取access_token,替换下列示例中的应用API Key与应用Secret Key
curl 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]'
# 步骤二,调用本文API,使用步骤一获取的access_token,替换下列示例中的“调用接口获取的access_token”;替换示例中的申请发布时填写的API名称
curl -XPOST  'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/completions/[申请发布时填写的API名称]?access_token=[步骤一调用接口获取的access_token]' -d '{
   "prompt":"Introduce the city Beijing"
}' | iconv -f utf-8 -t utf-8
import requests
import json
def get_access_token():
    使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key
    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]"
    payload = json.dumps("")
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json().get("access_token")
def main():
    替换下列示例中的申请发布时填写的API名称
    url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/completions/[申请发布时填写的API名称]?access_token=" + get_access_token()
    payload = json.dumps({
        "prompt":"Introduce the city Beijing"
    headers = {
        'Content-Type': 'application/json'
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)
if __name__ == '__main__':
    main()

响应示例(单轮)

"id": "as-rq3wwusja8", "object": "completion", "created": 1693811110, "result": ", China.\nBeijing is the capital city of China and is located in the northern part of the country. It is the largest city in China and is known for its modern architecture, cultural heritage, and historical significance. The city is home to many famous landmarks, such as the Forbidden City, Tiananmen Square, and the Great Wall of China. It is also known for its vibrant nightlife, delicious food, and stunning scenery.", "is_safe": 1, "usage": { "prompt_tokens": 5, "completion_tokens": 92, "total_tokens": 97

请求示例(流式)

# 步骤一,获取access_token,替换下列示例中的应用API Key与应用Secret Key
curl 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]'
# 步骤二,调用本文API,使用步骤一获取的access_token,替换下列示例中的“调用接口获取的access_token”;替换示例中的申请发布时填写的API名称
curl -XPOST 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/completions/[申请发布时填写的API名称]?access_token=[步骤一调用接口获取的access_token]' -d '{
  "prompt":"Introduce the city Beijing",
  "stream": true
            
import requests
import json
def get_access_token():
    使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key
    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]"
    payload = json.dumps("")
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json().get("access_token")
def main():
    替换下列示例中的申请发布时填写的API名称
    url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/completions/[申请发布时填写的API名称]?access_token=" + get_access_token()
     payload = json.dumps({
        "prompt":"Introduce the city Beijing",
        "stream": True
    headers = {
        'Content-Type': 'application/json'
    response = requests.request("POST", url, headers=headers, data=payload, stream=True)
    for line in response.iter_lines():
        print(line)
if __name__ == '__main__':
    main()

响应示例(流式)

data: {"id":"as-9092ws9jgh","object":"completion","created":1693811126,"sentence_id":0,"is_end":false,"result":", China.\nBeijing is the capital city of China and is located in the northern part of the country. It is the largest city in China and is known for its modern architecture, cultural heritage, and historical significance. The city is home to many famous landmarks, such as the Forbidden City, Tiananmen Square","is_safe":1,"usage":{"prompt_tokens":5,"completion_tokens":67,"total_tokens":72}}
data: {"id":"as-9092ws9jgh","object":"completion","created":1693811128,"sentence_id":1,"is_end":true,"result":", and the Great Wall of China. It is also known for its vibrant nightlife, delicious food, and stunning scenery.","is_safe":1,"usage":{"prompt_tokens":5,"completion_tokens":24,"total_tokens":96}}

如果请求错误,服务器返回的JSON文本包含以下参数。

Open api daily request limit reached API未开通付费,或者当前账户已欠费,导致请求失败。每天请求量超限额,已上线计费的接口,请直接在控制台开通计费,调用量不受限制,按调用量阶梯计费;未上线计费的接口,请在百度云控制台内 提交工单 反馈 Open api qps request limit reached QPS超限额,已上线计费的接口,请直接在控制台开通计费,调用量不受限制,按调用量阶梯计费;未上线计费的接口,请在百度云控制台内 提交工单 反馈 Open api total request limit reached 请求总量超限额,已上线计费的接口,请直接在控制台开通计费,调用量不受限制,按调用量阶梯计费;未上线计费的接口,请在百度云控制台内 提交工单 反馈 Invalid parameter 无效的access_token参数,请检查后重新尝试 Access token invalid or no longer valid access_token无效 Access token expired access token过期 336000 Internal error 服务内部错误 336001 Invalid Argument 入参格式有误,比如缺少必要参数 336002 Invalid JSON 入参body不是标准的JSON格式 336003 {参数校验不合法的具体原因}说明:参数不同,返回错误信息不同 参数校验不合法,error_msg中会给出具体原因 336004 {权限控制出错的具体原因} 权限控制出错 336005 API name not exist 定制化模型服务apiname不存在 336100 人工智能是一项革命性的技术。与我互动的人过多,请您稍后重新向我提问。 人工智能是一项革命性的技术。与我互动的人过多,请您稍后重新向我提问 336101 Invalid HTTP Method