前言
在这篇文章中,我将分享如何利用ChatGPT 4.0辅助论文写作的技巧,并根据网上的资料和最新的研究补充更多好用的咒语技巧。
GPT4的官方售价是每月20美元,很多人并不是天天用GPT,只是偶尔用一下。
如果调用官方的GPT4接口,就可以按使用量付费,用多少付多少,而且没有3个小时内只能提问50条的使用限制。
但是对很多人来说调用接口是比较麻烦的。如果开发一个网站,后台调用GPT4的接口,大家一起用,
分摊一下服务器的成本,就比较划算了。见文末【参考链接】
{
"openapi": "3.1.0",
"info": {
"title": "获取城市的天气数据",
"description": "获取指定地区的当前天气情况",
"version": "v1.0.0"
},
"servers": [
{
"url": "https://chat.xutongbao.top"
}
],
"paths": {
"/api/light/chat/getWeather": {
"get": {
"description": "获取指定地区的当前天气情况",
"operationId": "GetCurrentWeather",
"parameters": [
{
"name": "city",
"in": "query",
"description": "城市,例如:深圳,城市的值必须是中文",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "extensions",
"in": "query",
"description": "extensions可选值:base/all base:返回实况天气 all:返回预报天气",
"required": true,
"enum": ['base', 'all'],
"schema": {
"type": "string"
}
}
],
"deprecated": false
}
}
},
"components": {
"schemas": {}
}
}
nodejs后台代码:
let baseApiKeyOnServer = 'Basic xxx'
const chatGetWeather = async (req, res) => {
let { city = '北京', extensions = 'all' } = req.query
let headers = req.headers
let authorization = req.headers?.authorization
console.log('天气', city, headers, req.query)
if (authorization === baseApiKeyOnServer) {
let resultCity = cityList.find((item) => item.name.includes(city))
let cityCode = '110000'
if (resultCity && resultCity.adcode) {
cityCode = resultCity.adcode
}
console.log('高德天气查询', city, cityCode, extensions)
// extensions可选值:base/all base:返回实况天气 all:返回预报天气
let result = await axios.get(
`https://restapi.amap.com/v3/weather/weatherInfo?key=${weatherApiKey}&city=${cityCode}&extensions=${extensions}`
)
const searchResult = result.data
let functionResponse
if (searchResult && Array.isArray(searchResult.lives)) {
functionResponse = `${JSON.stringify(searchResult.lives)}`
} else if (searchResult && Array.isArray(searchResult.forecasts)) {
functionResponse = `${JSON.stringify(searchResult.forecasts)}`
} else {
functionResponse = `${JSON.stringify(searchResult)}`
}
res.send({
code: 200,
data: {
city,
headers,
result: functionResponse,
},
message: '成功',
})
} else {
res.send({
code: 400,
message: '失败:参数headers.authorization',
})
}
}
测试:
参考链接:文章来源:https://www.toymoban.com/news/detail-809886.html
https://chat.xutongbao.top文章来源地址https://www.toymoban.com/news/detail-809886.html
到了这里,关于给自己创建的GPTs添加Action(查天气)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!