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

编程入门 行业动态 更新时间:2024-10-16 00:18:09

chatgpt升级啦,训练数据时间更新到2023年4月,支持tools(升级functionCall),128k<a href=https://www.elefans.com/category/jswz/34/1770489.html style=上下文"/>

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

 (2023年11月7日)

gpt-4-1106-preview

训练数据日期升级到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.chatpletions.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.chatpletions.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);

 一次查询两个城市的天气

 

一次查询两个人的新闻

参考链接:

/

更多推荐

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

本文发布于:2023-11-15 22:48:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   新到   时间   数据   chatgpt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!