当前位置: 首页 > news >正文

上海网站建设收费手机网站有免费做的吗

上海网站建设收费,手机网站有免费做的吗,西安网站建设哪个平台好,百度 wordpress目前百度文心一言的内测资格申请相当拉胯#xff0c;提交申请快3个月#xff0c;无任何音讯。不知道要等到什么时候。 百度适时开放了百度文心千帆大模型平台#xff0c;目前可以提交申请测试#xff0c;貌似通过的很快#xff0c;已取得测试申请资格#xff0c;可以用起…目前百度文心一言的内测资格申请相当拉胯提交申请快3个月无任何音讯。不知道要等到什么时候。 百度适时开放了百度文心千帆大模型平台目前可以提交申请测试貌似通过的很快已取得测试申请资格可以用起来。 申请测试网址 获得测试资格后的页面时这样的 点击立即使用可以在线测试 使用千帆大模型API 点击主页右上角控制台进入百度云控制台创建应用 之后就可以得到调用API的 AppIDAPIKeySecretKey。API调用时主要使用APIKeySecretKey。 目前赠送代金券测试用足够了按调用次数收费。 API调用测试第一步取得access_token 这里根据网友的代码用于测试有修改。 原始代码参考-百度文心千帆 网页搭建和示例测评 假设调用ERNIE-Bot-turbo 官方帮助文档见ERNIE-Bot-turbo 请求地址 https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant 请求方式 POST access_token有效性测试基于python # 填充API Key与Secret Key import requests import jsondef main(APIKey,SecretKey):url https://aip.baidubce.com/oauth/2.0/token?grant_typeclient_credentialsclient_idAPIKeyclient_secretSecretKeypayload json.dumps()headers {Content-Type: application/json,Accept: application/json}response requests.request(POST, url, headersheaders, datapayload)return response.json().get(access_token)if __name__ __main__:APIKey6bWN69CoTBjgC********** # 填入平台申请的实际APIKeySecretKeywy1nU8UrnePKWm0*************** # 填入平台申请的实际SecretKeyaccess_token main(APIKey,SecretKey)print(access_token)如果打印得到access_token则证明相关参数无误 可进行下一步对话测试。 大模型回答测试代码 import requests import jsondef get_access_token(APIKey, SecretKey):使用 API KeySecret Key 获取access_token替换下列示例中的应用API Key、应用Secret Keyurl https://aip.baidubce.com/oauth/2.0/token?grant_typeclient_credentialsclient_idAPIKeyclient_secretSecretKeypayload json.dumps()headers {Content-Type: application/json,Accept: application/json}response requests.request(POST, url, headersheaders, datapayload)return response.json().get(access_token)def main(APIKey, SecretKey):url https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token get_access_token(APIKey, SecretKey)payload json.dumps({messages: [{role: user,content: 给我推荐一些北京周边的自驾游路线}],stream: True})headers {Content-Type: application/json}response requests.request(POST, url, headersheaders, datapayload)print(response.text)if __name__ __main__:APIKey6bWN69CoTBjgC********** # 填入平台申请的实际APIKeySecretKeywy1nU8UrnePKWm0*************** # 填入平台申请的实际SecretKeymain(APIKey, SecretKey)大模型回复示例如下 基于Flask轻量化工具测试 编写app.py from flask import Flask, render_template, request, jsonify, make_response import requests import uuidapp Flask(__name__)# 替换成您的API Key和Secret Key API_KEY6bWN69CoTBjgC********** # 填入平台申请的实际APIKey SECRET_KEYwy1nU8UrnePKWm0*************** # 填入平台申请的实际SecretKey# 获取access_token TOKEN_URL fhttps://aip.baidubce.com/oauth/2.0/token?grant_typeclient_credentialsclient_id{API_KEY}client_secret{SECRET_KEY} response requests.get(TOKEN_URL) ACCESS_TOKEN response.json()[access_token]# 定义ERNIE-Bot聊天接口地址 CHAT_API_URL fhttps://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token{ACCESS_TOKEN} user_chat_histories {}app.route(/) def index():sessionid str(uuid.uuid4())[:16]resp make_response(render_template(index.html))resp.set_cookie(sessionid, sessionid)return respapp.route(/chat, methods[POST]) def chat_with_ernie_bot():# 从前端获取用户输入的对话内容和sessioniduser_id request.cookies.get(sessionid)user_input request.json[user_input]# 获取该用户的对话历史如果用户是首次对话则新建一个空列表作为其对话历史user_history user_chat_histories.get(user_id, [])# 将用户输入添加到对话历史中user_history.append({role: user, content: user_input})# 调用ERNIE-Bot聊天接口headers {Content-Type: application/json}data {messages: user_history}response requests.post(CHAT_API_URL, headersheaders, jsondata)result response.json()[result]print(result)user_history.append({role: assistant, content: result})user_chat_histories[user_id] user_historyreturn jsonify({response: result})if __name__ __main__:app.run(host0.0.0.0, port1333, debugFalse) 在app.py的同级目录下建立目录templates用来存放访问页面文件index.html。 index.html内容 !DOCTYPE html html headmeta charsetUTF-8title百度千帆/titlestylebody {font-family: Arial, sans-serif;}#chat-container {display: flex;flex-direction: column;height: 80vh;width: 50%;margin: auto;border: 1px solid #ddd;border-radius: 10px;padding: 10px;}#chat-history {flex-grow: 1;overflow-y: auto;margin-bottom: 10px;}#user-input {flex-grow: 0;margin-right: 10px;}h1 {text-align: center;}.send {text-align: center;}/stylescript srchttps://www.hyluz.cn/marked.min.js/script /head body h1百度千帆/h1 div idchat-containerdiv idchat-history/divdiv classsendinput typetext iduser-input placeholder输入您的消息.../button idsend-button onclicksendMessage()发送/button/div /divscriptconst chatHistory document.getElementById(chat-history);const userInput document.getElementById(user-input);userInput.addEventListener(keydown, function (e) {if (e.key Enter) {e.preventDefault();sendMessage();}});function getCookie(name) {const value ; document.cookie;const parts value.split(; name );if (parts.length 2) return parts.pop().split(;).shift();}function addMessageToChatHistory(role, message) {const messageElement document.createElement(div);messageElement.className role;messageElement.innerHTML marked.parse(message);chatHistory.appendChild(messageElement);chatHistory.scrollTop chatHistory.scrollHeight;}function sendMessage() {const userMessage userInput.value.trim();if (!userMessage) {return;}const userId getCookie(sessionid);addMessageToChatHistory(user, 用户: userMessage);fetch(/chat, {method: POST,headers: {Content-Type: application/json,},body: JSON.stringify({user_id: userId, user_input: userMessage}),}).then(response response.json()).then(data {const botResponse data.response;addMessageToChatHistory(assistant, 百度AI: botResponse);}).catch(error {console.error(Error:, error);});userInput.value ;} /script /body /html运行app.py本地客户端运行本地访问地址及端口 浏览器中打开地址http://127.0.0.1:1333/打开index.html显示交互界面 可以输入信息调用api进行交互。
http://www.hkea.cn/news/14482398/

相关文章:

  • 沈阳网站建设哪家便宜湖南网络推广服务
  • 微博白菜网站怎么做网站图标的制作h1优化代码
  • 网站300兆是多少网站三大标签修改注意事项
  • wordpress整站无法打开wordpress按需求开发
  • 温州网站建设免费咨询西安哪家网络公司做网站
  • 优客逸家网站建设电脑淘宝网页版
  • 做淘推广的网站wordpress 链接按钮
  • 无锡做网站哪个公司好在哪可以做网站
  • 有没有专业做网站的建设网站怎么输入分子式
  • 安顺市哪里可以做网站网站设计方案模板
  • 做前端网站用什么软件写代码吗开发手机网站多少钱
  • 后期网站建设及维护推广宿迁网站推广公司
  • 去类似美团网站做软件开发seo最好的cms系统
  • iis5.1 建立网站南昌网站建设公司行情
  • 北京专业网站建设大全做百度关键词网站
  • 域名回收网站做网站网页版和手机版
  • 整站优化加盟钓鱼网站网址
  • wordpress版权声明株洲百度seo
  • 广东网站建设网站室内设计可以做网站吗
  • 高端网站特色找广告商的平台
  • 做新网站 备案证明交接线上平台名称大全
  • 做网站运营买什么电脑WordPress附件空间
  • 购物网站设计人员兰州网站seo分析
  • wordpress网站开发代码wordpress模板dux主题
  • 杭州网站开发外包公司武义公司网站建设
  • 做购物网站能赚钱吗好单库网站是怎么做的
  • 莱州市招聘网站个人摄影作品网站
  • 网站未备案怎么做淘宝客中国建设银行手机银行下载官方网站
  • dede手机网站开发怎么查自己专业是否符合一建
  • 怎么建设投票网站国外网站模板下载