gpt支持json格式的数据返回(response

编程入门 行业动态 更新时间:2024-10-14 14:20:10

gpt支持json<a href=https://www.elefans.com/category/jswz/34/1771175.html style=格式的数据返回(response"/>

gpt支持json格式的数据返回(response

      Api.h5.chatCreateChatCompletion({model: 'gpt-3.5-turbo-1106',token: 'sk-f4fe8b67-fcbe-46fd-8cc9-fd1dac5d6d59',messages: [{role: 'user',content:'使用json格式返回十二生肖,包含中文名和英文名,[{id:"1", enName:"", cnName: ""}]',},],params: {n: 1,response_format: { type: 'json_object' },},}).then((res) => {if (res.code === 200) {console.log(res)let content = res.datapletion.choices[0].message.contentconsole.log(content)try {content = JSON.parse(content)console.log(content)} catch (error) {console.log(error)}}})}

接口地址

/api/light/chat/createChatCompletion

请求方式

post

Token获取方式

访问:/

使用邮箱注册账号

点击【我的】

点击【API】

model可选值

“gpt-3.5-turbo-1106”、 “gpt-3.5-turbo-16k” 、 “gpt-4”、“gpt-4-1106-preview”。 默认值为: “gpt-3.5-turbo-1106”

请求参数示例

{"model": "gpt-3.5-turbo-1106","token": "sk-3d76d415-dd72-43ff-b7c8-65fb426f1d7b","messages": [{"role": "user","content": "List of months that have 30 days in json"}],"params": {"n": 1,"response_format": {"type": "json_object"}}
}

响应数据

{"code": 200,"data": {"completion": {"id": "chatcmpl-8K3TSgnJ31qpVlomvnSYpqKYmEZFR","object": "chatpletion","created": 1699790606,"model": "gpt-3.5-turbo-1106","choices": [{"index": 0,"message": {"role": "assistant","content": "{\n  \"months\": [\n    \"April\",\n    \"June\",\n    \"September\",\n    \"November\"\n  ]\n}"},"finish_reason": "stop"}],"usage": {"prompt_tokens": 17,"completion_tokens": 25,"total_tokens": 42},"system_fingerprint": "fp_eeff13170a"},"info": {"isSdHide": "2","sdLimitCount": 2000,"sdTextToImg": 412,"token": "sk-3d76d415-dd72-43ff-b7c8-65fb426f1d7b","numOfOneDayCanCallApi": 50,"numOfOneDayAlreadyCallApi": 7,"apiDate": "2023-11-12","isHasGPT4Auth": true}},"message": "成功"
}

使用json格式返回十二生肖,包含中文名和英文名,[{id:"1", enName:"", cnName: ""}] 

更多推荐

gpt支持json格式的数据返回(response

本文发布于:2023-11-15 04:17:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:格式   数据   gpt   json   response

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!