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

chatgpt升级啦,训练数据时间更新到2023年4月,支持tools(升级functionCall),128k上下文

 (2023年11月7日)

gpt-4-1106-preview

https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo

训练数据日期升级到2023年四月

上线文增加到128k

调用一次chatgpt接口,可以得到多次函数调用

 

import OpenAI from "openai";
const openai = new OpenAI();// Example dummy function hard coded to return the same weather
// In production, this could be your backend API or an external API
function getCurrentWeather(location, unit = "fahrenheit") {if (location.toLowerCase().includes("tokyo")) {return JSON.stringify({ location, temperature: "10", unit: "celsius" });} else if (location.toLowerCase().includes("san francisco")) {return JSON.stringify({ location, temperature: "72", unit: "fahrenheit" });} else {return JSON.stringify({ location, temperature: "22", unit: "celsius" });}
}async function runConversation() {// Step 1: send the conversation and available functions to the modelconst messages = [{ role: "user", content: "What's the weather like in San Francisco, Tokyo, and Paris?" },];const tools = [{type: "function",function: {name: "get_current_weather",description: "Get the current weather in a given location",parameters: {type: "object",properties: {location: {type: "string",description: "The city and state, e.g. San Francisco, CA",},unit: { type: "string", enum: ["celsius", "fahrenheit"] },},required: ["location"],},},},];const response = await openai.chat.completions.create({model: "gpt-3.5-turbo-1106",messages: messages,tools: tools,tool_choice: "auto", // auto is default, but we'll be explicit});const responseMessage = response.choices[0].message;// Step 2: check if the model wanted to call a functionconst toolCalls = responseMessage.tool_calls;if (responseMessage.tool_calls) {// Step 3: call the function// Note: the JSON response may not always be valid; be sure to handle errorsconst availableFunctions = {get_current_weather: getCurrentWeather,}; // only one function in this example, but you can have multiplemessages.push(responseMessage); // extend conversation with assistant's replyfor (const toolCall of toolCalls) {const functionName = toolCall.function.name;const functionToCall = availableFunctions[functionName];const functionArgs = JSON.parse(toolCall.function.arguments);const functionResponse = functionToCall(functionArgs.location,functionArgs.unit);messages.push({tool_call_id: toolCall.id,role: "tool",name: functionName,content: functionResponse,}); // extend conversation with function response}const secondResponse = await openai.chat.completions.create({model: "gpt-3.5-turbo-1106",messages: messages,}); // get a new response from the model where it can see the function responsereturn secondResponse.choices;}
}runConversation().then(console.log).catch(console.error);

 一次查询两个城市的天气

 

一次查询两个人的新闻

参考链接:

https://chat.xutongbao.top/

http://www.lryc.cn/news/222135.html

相关文章:

  • 各种格式文件预览
  • 21款奔驰GLE350升级迈巴赫电动踏板 上下车更加方便
  • 【Android】Lombok for Android Studio 离线插件
  • 在Docker中设置Redis的密码
  • C++跨模块传递CRT引发问题
  • 常用的国外邮箱服务有哪些?
  • windows cmake x86 x64 下载与安装
  • 目标检测算法 - YOLOv1
  • Mercury性能测试模板
  • ts面试题总结
  • 访问控制列表
  • java入坑之类加载器
  • 登录Tomcat控制台,账号密码输入正确但点击登录没反应不跳转到控制台页面
  • [黑马程序员Pandas教程]——Pandas缺失值处理
  • Mysql进阶-视图篇
  • 一种libuv实现websockets服务的解决方案
  • MobaXterm配置SSHTunnel
  • MySQL中的datetime和timestamp有什么区别
  • 如何开发一个求职招聘小程序?详细步骤解析与教程
  • 安克创新音频算法工程师(应届生)招聘
  • Ubuntu 22.04.3 LTS中安装singularity
  • NVM安装node后提示没有对应npm包(即:无法将“npm”项识别为 cmdlet、函数、脚本文件)
  • 路由器基础(十一):ACL 配置
  • 【今日文章】:如何用css 实现星空效果
  • HackTheBox-Starting Point--Tier 1---Three
  • Linux Alsa声卡驱动(2):Machine驱动
  • 某综合性能源集团绩效考核设计项目纪实
  • ubuntu18.04 通过创建服务实现开机自启, 启动指定脚本
  • Tomcat 9.0.x 源码编译
  • 基于SSM的旅游管理系统的设计与实现