这里写自定义目录标题
背景
一直困惑于ai是如何使用插件或者其他一些功能的,后来发现,很多大模型都支持function call功能,如何让大模型能够联网查询呢,function call就可以做到。
什么是function call
Function calling enables developers to connect language models to external data and systems. You can define a set of functions as tools that the model has access to, and it can use them when appropriate based on the conversation history. You can then execute those functions on the application side, and provide results back to the model.
函数调用使开发人员能够将语言模型连接到外部数据和系统。您可以将一组函数定义为模型有权访问的工具,并且它可以根据对话历史记录在适当的时候使用它们。然后,您可以在应用程序端执行这些函数,并将结果返回给模型。
你可以理解为,大模型允许你按照一定的格式,告诉大模型你可以提供的函数和函数功能,然后当你调用大模型的时候,它可以参考是否有可用的函数来完成本次工作,如果有的话,返回值里就会指示要调用函数,并且给出入参。
怎么用function call?
官方文档写的很清楚,可以参考:Function Calling 函数调用
我主要是照着这个文档整的,好的,接下来直接给例子:
涉及到以下几个类:
你的函数类:
@Service
@Slf4j
public class WeatherService implements Function<WeatherService.Request, WeatherService.Response> {
public enum Unit {
C, F }
@JsonClassDescription("Get the weather in location") // // function description
public record Request(String location, Unit unit) {
}