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

广州国外建站模板整站快速排名

广州国外建站模板,整站快速排名,18年手机网站,p2p网站制作目前百度文心一言的内测资格申请相当拉胯,提交申请快3个月,无任何音讯。不知道要等到什么时候。 百度适时开放了百度文心千帆大模型平台,目前可以提交申请测试,貌似通过的很快,已取得测试申请资格,可以用起…

目前百度文心一言的内测资格申请相当拉胯,提交申请快3个月,无任何音讯。不知道要等到什么时候。
百度适时开放了百度文心千帆大模型平台,目前可以提交申请测试,貌似通过的很快,已取得测试申请资格,可以用起来。
申请测试网址
获得测试资格后的页面时这样的:
在这里插入图片描述
点击立即使用,可以在线测试:
在这里插入图片描述

使用千帆大模型API

点击主页右上角,控制台,进入百度云控制台,创建应用:在这里插入图片描述
在这里插入图片描述
之后就可以得到调用API的 AppID,APIKey,SecretKey。API调用时,主要使用APIKey,SecretKey。

目前赠送代金券,测试用足够了,按调用次数收费。
在这里插入图片描述

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_type=client_credentials&client_id="+APIKey+"&client_secret="+SecretKeypayload = 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")if __name__ == '__main__':APIKey="6bWN69CoTBjgC**********"  # 填入平台申请的实际APIKeySecretKey="wy1nU8UrnePKWm0***************" # 填入平台申请的实际SecretKeyaccess_token = main(APIKey,SecretKey)print(access_token)

如果打印得到access_token,则证明相关参数无误:
在这里插入图片描述
可进行下一步对话测试。

大模型回答测试代码

import requests
import jsondef get_access_token(APIKey, SecretKey):"""使用 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="+APIKey+"&client_secret="+SecretKeypayload = 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(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, headers=headers, data=payload)print(response.text)if __name__ == '__main__':APIKey="6bWN69CoTBjgC**********"  # 填入平台申请的实际APIKeySecretKey="wy1nU8UrnePKWm0***************" # 填入平台申请的实际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_KEY="6bWN69CoTBjgC**********"  # 填入平台申请的实际APIKey
SECRET_KEY="wy1nU8UrnePKWm0***************" # 填入平台申请的实际SecretKey# 获取access_token
TOKEN_URL = f"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API_KEY}&client_secret={SECRET_KEY}"
response = requests.get(TOKEN_URL)
ACCESS_TOKEN = response.json()["access_token"]# 定义ERNIE-Bot聊天接口地址
CHAT_API_URL = f"https://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 resp@app.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, headers=headers, json=data)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(host='0.0.0.0', port=1333, debug=False)

在app.py的同级目录下,建立目录templates,用来存放访问页面文件index.html。

index.html内容:

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>百度千帆</title><style>body {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;}</style><script src="https://www.hyluz.cn/marked.min.js"></script>
</head>
<body>
<h1>百度千帆</h1>
<div id="chat-container"><div id="chat-history"></div><div class="send"><input type="text" id="user-input" placeholder="输入您的消息..."/><button id="send-button" onclick="sendMessage()">发送</button></div>
</div><script>const 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.hengruixuexiao.com/news/20791.html

相关文章:

  • 网站概要设计模板神马搜索seo优化排名
  • 网站开发后台需要什么技术专业海外网站推广
  • 即墨做网站公司西安seo排名优化推广价格
  • 别人帮自己做网站有后门吗网站建设平台哪家好
  • 海南茶叶网站建设青岛网站建设推广公司
  • 西安市网站建设西安网站快速排名提升
  • b2c网站名称小红书推广
  • 做网站的公司现在还 赚钱吗6sem是什么测试
  • 镇网站建设管理工作总结时事新闻最新
  • 建设公司大还是建筑公司大成都关键词seo推广平台
  • c++ 网站开发网站关键词优化怎么做的
  • 郑州城乡建设委员会网站免费发广告帖子的网站
  • 网站建设昆明网络公司aso关键词排名优化是什么
  • 放单网站建设应用商店app下载
  • 网站工信部备案号学生网页制作成品
  • html5做网页网站免费推广神器
  • 长沙网站设计工作室seo排名点击 seo查询
  • 苏州专业做网站的公司手机百度旧版本下载
  • 制作企业网站的报告网站建设公司开发
  • 企业网站为什么做优化重庆网站页面优化
  • 企业网站源码搭建微信代运营
  • 国外做兼职的网站全国疫情最新
  • Ecshop网站建设总结百度一下百度主页度
  • 怎样用织梦做音乐网站免费的行情网站
  • 企业app定制开发宁波seo优化公司排名
  • 免费观看电视剧网站线上营销工具
  • 网站建设项目团队长沙网络优化产品
  • 网站标头设计seo技巧课程
  • 黄岩做网站广州外包网络推广公司
  • 如何自己搭建微信小程序疫情优化调整