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

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

时间:2023-11-14 15:06:04浏览次数:34  
标签:function const messages 升级 location 2023 tools response unit


 (2023年11月7日)

gpt-4-1106-preview

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

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

上线文增加到128k

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

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

 

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

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 model
  const 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 function
  const 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 errors
    const availableFunctions = {
      get_current_weather: getCurrentWeather,
    }; // only one function in this example, but you can have multiple
    messages.push(responseMessage); // extend conversation with assistant's reply
    for (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 response
    return secondResponse.choices;
  }
}


runConversation().then(console.log).catch(console.error);

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

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

 一次查询两个城市的天气

 

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

一次查询两个人的新闻

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


标签:function,const,messages,升级,location,2023,tools,response,unit
From: https://blog.51cto.com/xutongbao/8369418

相关文章

  • 2023 年度 10 月份 GitHubJava 项目排行榜 Top 10
    1.mall项目地址:https://github.com/macrozheng/mallmall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心......
  • GEE ——errors & debuggings (2023GEE峰会总结)
    简介:在gee中有三种错误,一种就是系统错误,也就是我们看到的会在JavaScriptcodeeditor中出现的错误,也就是在程序还没有启动之前就会提示的错误,而客户端错误则主要是会提示一些在代码过程中的错误,比如说没出现过的变量名称,另外就是服务器出席那的错误,也就是说,你的代码和你索要运行的......
  • GEE数据集——2019、2020、2021、2022和2023年全球固定宽带和移动(蜂窝)网络性能Shapefi
    全球固定宽带和移动(蜂窝)网络性能¶全球固定宽带和移动(蜂窝)网络性能,分配给缩放级别16网络墨卡托图块(赤道处约610.8米x610.8米)。数据以Shapefile格式和ApacheParquet格式提供,其几何形状以众所周知的文本(WKT)表示,投影在EPSG:4326中。下载速度、上传速度和延迟是通过......
  • 20231114打卡
    早上,我在课堂上学习了拓扑排序和关键路径两个在工程实践中非常重要的概念。拓扑排序是一种拓扑排序算法,用于高效地解决有向无环图(DAG)中的依赖问题。关键路径则可以帮助我们确定项目计划中的关键节点和关键路径,是工程项目管理中非常常用的技术。通过课堂讲解和案例分析,我对这两个概......
  • .NET Conf 2023 议程(简体中文)
    .NETConf2023议程(简体中文)最大的在线.NET活动11月14日至16日。重要:本文内容引用翻译自 www.paioffice.com第一天Tuesday,November1408:00-09:00PST欢迎使用.NET8DamianEdwards,SafiaAbdalla,DavidFowler,GauravSeth,DanielRoth,Glenn......
  • Tita 「OKR、任务、报表」细节优化升级
    升级详情Tita-OKR和新绩效一体化管理平台一、【OKR 仪表盘】支持按群组筛选统计·仪表盘的右上角支持按群组进行筛选统计·具体数据的下钻页面同样支持二、【OKR批量导入】支持对齐KR与对齐多个目标的填写导入需要对齐KR时填写好ID,对齐多个目标时用”、”隔开......
  • 202311141210——《一些修改表字段的sql语句》
    ALTERTABLEuserADDCOLUMNtelCHAR(11)AFTERwechat;#添加列ALTERtablecustomermodifycolumnpasswordvarchar(200);#修改列类型ALTERTABLEuserALTERCOLUMNstatusSETDEFAULT1;#设置默认值ALTERTABLEuserMODIFYcolumnemp_idTIMESTAMPDEFAULTNULL......
  • CSP-S 2023 游记和西南大学附属中学校(东区)暑假游记
    同步发布于洛谷博客。前言本游记分为两部分,第一部分为本人今年暑假7月份在西南大学附属中学校(东区)集训,第二部分是2023年非专业软件能力认证提高级的游记。西南大学附属中学校(东区)暑假游记由于鸽的比较久所以不可能很详细的记述了。现在主要是凭借本人自己还残存的一些记......
  • tmdb 无法连接 修改host可解决 (2023/11/14)
    tinyMediaManager的刮削服务总是失败,根本原因在于tmdb网站的DNS地址无法解析。解决方法:手动修改DNS。作者:PH34Rhttps://www.bilibili.com/read/cv18215732/?spm_id_from=333.999.collection.opus.click出处:bilibili通过 https://dnschecker.org/ 查询上述三个地址,选择在......
  • Mac Os VS Code 无法升级Cannot update while running on a read-only volume.
    macOSVSCode无法升级,提示“Cannotupdatewhilerunningonaread-onlyvolume“错误提示错误如下:Cannotupdatewhilerunningonaread-onlyvolume.Theapplicationisonaread-onlyvolume.Pleasemovetheapplicationandtryagain.Ifyou’reonmacOSSierr......