-
Notifications
You must be signed in to change notification settings - Fork 2
Using ChatGPT FunctionCall from Java
As artificial intelligence and chatbots continue to gain popularity, integrating functions into chat conversations is becoming increasingly important. Functions are small units of code that can be reused and embedded into larger programs to perform a specific task. In this blog post, we will discuss how to implement and integrate functions into ChatGPT conversations using JAI, a Java Open AI API client. This guide will define a function, handle function callbacks, and mix function results with content/context returned from the function to enhance ChatGPTs’ response with your domain. Additionally, we will provide an example implementation of a weather-related function and its integration into a larger program using a function map.
This developer notebook guides implementing and integrating functions into a ChatGPT conversation with JAI, a Java Open AI API client. It covers everything from defining a function to handling function callbacks and mixing the results with the content/context returned. In addition, the guide includes an example implementation of a weather-related function and its integration into a larger program using a function map.
The latest models (gpt-3.5-turbo-0613
and gpt-4-0613
) have been fine-tuned to detect when a function should be called based on the input, and to respond with JSON that follows the function signature. However, this power also comes with great responsibility due to potential risks. Users must build some user confirmation before taking actions on behalf of users that could impact the world (such as sending an email, posting political views online, buying something, etc.).
The notebook begins by explaining how to define a function by creating a dictionary that maps function names to their respective implementations. It then covers handling function callbacks, which occur when ChatGPT calls a function and returns a "function call" object containing the function's name and its arguments. The guide also explains how to call ChatGPT again by appending the function response as a new message and returning the updated chat request to the ChatGPT model.
The model will intelligently select and output a JSON object, called a functionCall
, containing names of the functions and arguments to call those functions. Note that the Chat Completions API does not call the function but instead generates JSON that the user can use to call the function in their code.
This is a powerful concept and allows you a way to combine up-to-date data from your business domain with ChatGPT.
Function calling enables you to add more context to the output from ChatGPT and allows you to get structured data from a model from ChatGPT. This can be used to:
- Create chatbots that answer questions by calling external APIs (e.g. ChatGPT Plugins).
- For example, you can define functions like
send_email(to: string, body: string)
orget_current_weather(location: string, unit: 'celsius' | 'fahrenheit')
.
- For example, you can define functions like
- Convert natural language into function calls.
- For example, you can convert "Who are my top followers on IG?" to
get_top_IG_followers(min_revenue: int, created_before: string, limit: int)
and call an internal function that could hit an internal service.
- For example, you can convert "Who are my top followers on IG?" to
- Extract structured data from text.
- For example, you can define a function called
extract_data(name: string, birthday: string)
orsql_query(query: string)
.
- For example, you can define a function called
Defining a function is the first step in implementing it into a ChatGPT conversation. Once you have defined your function and input/output formats, the next step is to handle function callbacks.
Handling function callbacks is crucial to ensuring the chatbot can execute the desired interaction successfully. Callbacks work by ChatGPT notifying the API client when a function should be executed and passing any necessary data from the function back to the ChatGPT. Additionally, the function's return value must be mixed with the content/context returned from the chatbot to create a seamless experience. This is one way to mix content from your business domain into the ChatGPT results.
We will use the classic example of implementing a function into a ChatGPT conversation that uses a weather-related lookup. This function can provide users with real-time weather updates on a specific location. The input for this function would be the user’s desired location, and the output would be the weather information returned as a return object.
The basic steps for function calls is:
- Call the ChatGPT chat with the user query and a set of functions defined in the functions parameter.
- ChatGPT can choose to call a function. ChatGPT selects this function by returning a
functionCall
from a message (from a choice). ThefunctionaCall
arguments is in a JSON object that you must deserialize. - From the
functionaCall
you call a function in your code with the arguments provided, and get a function response. - Call the ChatGPT again by appending the function response as a new message, and let the model summarize the results to the user.
Let’s look at some example code.
package com.cloudurable.jai.examples;
import com.cloudurable.jai.OpenAIClient;
import com.cloudurable.jai.model.text.completion.chat.ChatRequest;
import com.cloudurable.jai.model.text.completion.chat.ChatResponse;
import com.cloudurable.jai.model.text.completion.chat.Message;
import com.cloudurable.jai.model.text.completion.chat.Role;
import com.cloudurable.jai.model.text.completion.chat.function.*;
import com.cloudurable.jai.util.JsonSerializer;
import io.nats.jparse.node.ObjectNode;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public class WeatherFunctionCallExample {
private final OpenAIClient client;
/**
* Holds the function mappings.
*/
private final Map<String, Function<ObjectNode, String>> functionMap = new HashMap<>();
public WeatherFunctionCallExample(OpenAIClient client) {
this.client = client;
functionMap.put("get_current_weather", this::getCurrentWeather);
}
/**
*
* Example dummy function hard coded to return the same weather for two
* cities and default for other cities.
* In production, this could be your backend API or an external API
* @param objectNode arguments from chat GPT.
* @return JSON string
*/
public String getCurrentWeather(final ObjectNode objectNode) {
final String location = objectNode.getString("location");
final String unit = Optional.ofNullable(objectNode.get("unit"))
.map(node->node.asScalar().stringValue()).orElse("fahrenheit");
final JsonSerializer json = new JsonSerializer();
json.startObject();
json.addAttribute("location", location);
json.addAttribute("unit", unit);
switch (location) {
case "Austin, TX":
json.addAttribute("temperature", 92);
json.endObject();
return json.toString();
case "Boston, MA":
json.addAttribute("temperature", 72);
json.endObject();
return json.toString();
default:
json.addAttribute("temperature", 70);
json.endObject();
return json.toString();
}
}
public static void main(final String... args) {
try {
final var client = OpenAIClient.builder().setApiKey(System.getenv("OPENAI_API_KEY")).build();
new WeatherFunctionCallExample(client).runConversation();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void runConversation() {
final var getCurrentWeatherFunc = getFunctionDefinition();
final var message = Message.builder().role(Role.USER)
.content("What's the weather like in Boston in fahrenheit?").build();
final var chatBuilder = ChatRequest.builder()
.model("gpt-3.5-turbo-0613")
.addMessage(message)
.addFunction(getCurrentWeatherFunc)
.functionalCall(ChatRequest.AUTO);
final var chatRequest = chatBuilder.build();
final var chatResponse = client.chat(chatRequest);
chatResponse.getResponse().ifPresent(
response -> handleFunctionCallback(chatBuilder, response));
System.out.println(chatResponse.getStatusCode().orElse(666));
System.out.println(chatResponse.getStatusMessage().orElse(""));
chatResponse.getException().ifPresent(e-> e.printStackTrace());
}
private void handleFunctionCallback(final ChatRequest.Builder chatBuilder, final ChatResponse chatResponse) {
var responseMessage = chatResponse.getChoices().get(0).getMessage();
var functionCall = responseMessage.getFunctionCall();
var functionResponse = getFunctionResponse(functionCall);
chatBuilder.addMessage(Message.builder().name(functionCall.getName()).role(Role.FUNCTION)
.content(functionResponse)
.build());
var response = client.chat(chatBuilder.build());
response.getResponse().ifPresent(chatResponse1 ->
System.out.println(chatResponse1.getChoices().get(0).getMessage().getContent()));
if (response.getStatusMessage().isPresent()) {
System.out.println(response.getStatusMessage().orElse(""));
}
}
private String getFunctionResponse(FunctionalCall functionCall) {
String functionResponse = "";
if (functionCall !=null && functionMap.containsKey(functionCall.getName())) {
functionResponse = functionMap.get(functionCall.getName()).apply(functionCall.getArguments());
}
return functionResponse;
}
private static FunctionDef getFunctionDefinition() {
return FunctionDef.builder().name("get_current_weather")
.description("Get the current weather in a given location")
.setParameters(
ObjectParameter.objectParamBuilder()
.addParameter(Parameter.builder().name("location")
.description("The city and state, e.g. Austin, TX").build())
.addParameter(
EnumParameter.enumBuilder()
.name("unit").enumValues("celsius", "fahrenheit").build())
.required("location")
.build()
).build();
}
}
If that is not all clear, let me break it down based on the steps we defined. Then we will show the actual messages flying across the wire between the client application and Chat GPT.
public void runConversation() {
// Call the ChatGPT chat with the user query.
final var message = Message.builder().role(Role.USER)
.content("What's the weather like in Boston in fahrenheit?").build();
final var chatBuilder = ChatRequest.builder()
.model("gpt-3.5-turbo-0613")
.addMessage(message) // user query
...
.functionalCall(ChatRequest.AUTO);
The runConversation()
establishes a conversation with the ChatGPT model by providing a user query and configuring the chat request. Next, it prepares the conversation to handle functional calls, allowing the model to invoke specific functions as needed during the conversation.
This **runConversation()
**demonstrates using the ChatGPT model to run a conversation and make a function call. Let's break it down step by step:
- The
runConversation()
method is the entry point for executing the conversation. - The code begins by creating a user query message using the
Message.builder()
method. The query is set to "What's the weather like in Boston in Fahrenheit?" and is assigned the user's role. - A
ChatRequest
builder object,chatBuilder
, is created to configure the chat request to be sent to the ChatGPT model. - The model for the chat is specified as "gpt-3.5-turbo-0613" using the
model()
method on thechatBuilder
. - The user query message is added to the
chatBuilder
using theaddMessage()
method. This message represents the initial user input for the conversation. - Additional configuration and functionality can be added to the
chatBuilder
, although the snippet provided does not show these details. - Finally, the
functionalCall()
method is called on thechatBuilder
with the parameterChatRequest.AUTO
. This indicates that the ChatGPT model should automatically handle any functional calls made during the conversation.
1.2 And include the set of functions defined in the functions parameter.
private static FunctionDef getFunctionDefinition() {
return FunctionDef.builder().name("get_current_weather")
.description("Get the current weather in a given location")
.setParameters(
ObjectParameter.objectParamBuilder()
.addParameter(Parameter.builder().name("location")
.description("The city and state, e.g. Austin, TX")
.build())
.addParameter(
EnumParameter.enumBuilder()
.name("unit")
.enumValues("celsius", "fahrenheit")
.build())
.required("location")
.build()
).build();
}
public void runConversation() {
...
// And include the set of functions defined in the functions parameter.
final var getCurrentWeatherFunc = getFunctionDefinition();// defined above
final var chatBuilder = ChatRequest.builder()
.model("gpt-3.5-turbo-0613")
.addMessage(message)
.addFunction(getCurrentWeatherFunc) //function definitions
.functionalCall(ChatRequest.AUTO);
The runConversation()
method is an entry point for executing a conversation with the ChatGPT model.
- The
runConversation
creates aMessage
object representing a user query. The query is set to "What's the weather like in Boston in Fahrenheit?" and is assigned the user's role. - The code defines a function called
getCurrentWeatherFunc
(not shown in the provided code) and retrieves its definition. - A
ChatRequest
builder object,chatBuilder
, is created. It specifies the model to be used as "gpt-3.5-turbo-0613". - The user query message is added to the
chatBuilder
using theaddMessage()
method. - The
getCurrentWeatherFunc
function definition is added to thechatBuilder
using theaddFunction()
method. - Finally, the
functionalCall()
method is called on thechatBuilder
with the parameterChatRequest.AUTO
. Specifying auto means that you want ChatGPT to decided which is the best method to call based on the message.
private static FunctionDef getFunctionDefinition() {
return FunctionDef.builder().name("get_current_weather")
.description("Get the current weather in a given location")
.setParameters(
ObjectParameter.objectParamBuilder()
.addParameter(Parameter.builder().name("location")
.description("The city and state, e.g. Austin, TX")
.build())
.addParameter(
EnumParameter.enumBuilder()
.name("unit")
.enumValues("celsius", "fahrenheit")
.build())
.required("location")
.build()
).build();
}
The method getFunctionDefinition()
, which returns a FunctionDef
object. This is a function definition for use in the ChatGPT conversation when we pass the menu of functions it can call.
Here's a breakdown of what the code does:
- The
getFunctionDefinition()
method returns an instance of theFunctionDef
class. - The
FunctionDef
builder is used to construct theFunctionDef
object. - The
name
property of the function is set to "get_current_weather". This defines the function's name that can be invoked during the conversation. - The
description
property provides a description of the function, indicating that it retrieves the current weather in a given location. - The
setParameters()
method is called to specify the parameters for the function. - Inside
setParameters()
, two parameters are defined:- The first parameter, “location" represents the city and state for which the weather is requested. It has a description explaining its purpose.
- The second parameter is an
EnumParameter
named "unit". It represents the unit in which the weather should be returned (either "celsius" or "fahrenheit"). It is defined as an enumeration with two possible values.
- The
required()
method is called on theObjectParameter
to specify that the "location" parameter is required for the function. - The
build()
method is called to finalize the construction of theFunctionDef
object.
This getFunctionDefinition
defines a function named "get_current_weather" that takes two parameters: "location" and "unit". It represents a function that retrieves the current weather for a given location in Celsius or Fahrenheit. This function can be used in the ChatGPT conversation to provide weather information based on user queries.
public void runConversation() {
final var chatRequest = ...
final var chatResponse = client.chat(chatRequest);
chatResponse.getResponse().ifPresent(
response -> handleFunctionCallback(chatBuilder, response));
...
}
private void handleFunctionCallback(final ChatRequest.Builder chatBuilder, final ChatResponse chatResponse) {
var responseMessage = chatResponse.getChoices().get(0).getMessage();
var functionCall = responseMessage.getFunctionCall();
var functionResponse = getFunctionResponse(functionCall);
....
The above code demonstrates how to handle a function callback within the runConversation()
method. Let's break it down:
-
final var chatRequest = ...
: This line represents the creation of thechatRequest
object, which contains the necessary configuration for the chat request to be sent to the ChatGPT model including the function definition that we defined earlier. -
final var chatResponse = client.chat(chatRequest)
: This line sends thechatRequest
to the ChatGPT model using thechat()
method of theclient
. It returns achatResponse
object that contains the response generated by the model. -
chatResponse.getResponse().ifPresent(response -> handleFunctionCallback(chatBuilder, response))
: This line checks if thechatResponse
contains a response by using thegetResponse()
method. If a response is present, it invokes thehandleFunctionCallback()
method and passes thechatBuilder
andresponse
as arguments. This is done to handle any function callbacks received from the ChatGPT model during the conversation. -
private void handleFunctionCallback(final ChatRequest.Builder chatBuilder, final ChatResponse chatResponse)
: This method receives thechatBuilder
andchatResponse
as parameters. It handles the function callback received from the ChatGPT model. -
var responseMessage = chatResponse.getChoices().get(0).getMessage()
: This line retrieves the first message choice from thechatResponse
. It assumes that the model provides multiple response choices and focuses on the first one. -
var functionCall = responseMessage.getFunctionCall()
: This line extracts theFunctionCall
object from theresponseMessage
. It represents a function call made by the ChatGPT model during the conversation. -
var functionResponse = getFunctionResponse(functionCall)
: This line invokes thegetFunctionResponse()
method, passing thefunctionCall
object as an argument, to retrieve the response generated by the function call.
This code demonstrates how to handle function callbacks within the runConversation()
method. It sends a chat request to the ChatGPT model, receives the response, and if a response is present, it invokes the handleFunctionCallback()
method to handle the function callback. The function callback is extracted from the response message, and the getFunctionResponse()
method is called to retrieve the function's response.
private final Map<String, Function<ObjectNode, String>> functionMap =
new HashMap<>();
/**
*
* Example dummy function hard coded to return the same weather for two cities
* and default for other cities.
* In production, this could be your backend API or an external API
* @param objectNode arguments from chat GPT.
* @return JSON string
*/
public String getCurrentWeather(final ObjectNode objectNode) {
final String location = objectNode.getString("location");
final String unit = Optional.ofNullable(objectNode.get("unit"))
.map(node->node.asScalar().stringValue()).orElse("fahrenheit");
final JsonSerializer json = new JsonSerializer();
json.startObject();
json.addAttribute("location", location);
json.addAttribute("unit", unit);
switch (location) {
case "Austin, TX":
json.addAttribute("temperature", 92);
json.endObject();
return json.toString();
case "Boston, MA":
json.addAttribute("temperature", 72);
json.endObject();
return json.toString();
default:
json.addAttribute("temperature", 70);
json.endObject();
return json.toString();
}
}
public WeatherFunctionCallExample(OpenAIClient client) {
this.client = client;
functionMap.put("get_current_weather", this::getCurrentWeather); //register
}
private String getFunctionResponse(FunctionalCall functionCall) {
String functionResponse = "";
if (functionCall !=null && functionMap.containsKey(functionCall.getName())) {
functionResponse = functionMap
.get(functionCall.getName())
.apply(functionCall.getArguments());
}
return functionResponse;
}
The provided code snippet is an example of a weather-related function implementation within a larger ChatGPT conversation. Let's break it down:
-
private final Map<String, Function<ObjectNode, String>> functionMap = new HashMap<>()
: This line declares and initializes aMap
namedfunctionMap
that maps function names (as strings) to functions that accept anObjectNode
parameter and return aString
. This map is used to associate function names with their respective implementations. TheObjectNode
is the argument to the function call that ChatGPT decided to call. -
public String getCurrentWeather(final ObjectNode objectNode)
: This method represents implementing theget_current_weather
function. It takes anObjectNode
as input, which contains arguments passed from the ChatGPT model. It retrieves thelocation
andunit
values from theObjectNode
and generates a JSON response based on the specified location. The temperature values for "Austin, TX", "Boston, MA", and the default location are hard coded. The JSON response is constructed using theJsonSerializer
class, and the function returns the generated JSON as a string. -
public WeatherFunctionCallExample(OpenAIClient client)
: This is a constructor for theWeatherFunctionCallExample
class, which takes anOpenAIClient
object as a parameter. It initializes theclient
field with the providedOpenAIClient
and registers thegetCurrentWeather
function by adding it to thefunctionMap
with the key "get_current_weather". -
private String getFunctionResponse(FunctionalCall functionCall)
: This method retrieves the function response based on aFunctionalCall
object. It first checks if thefunctionCall
object is not null and if thefunctionMap
contains the function name specified infunctionCall
. If both conditions are met, it invokes the associated function fromfunctionMap
using the function name as the key and passes the function call arguments to it. The result is then returned as the function response. This is how we map the function ChatGPT requested to call and the results.
Overall, this code demonstrates an example implementation of a weather-related function and its integration into a larger program using a functionMap
to associate function names with their respective implementations for easy access to a ChatGPT conversation.
3 Call the ChatGPT again by appending the function response as a new message, and let the model summarize the results to the user.
private void handleFunctionCallback(final ChatRequest.Builder chatBuilder,
final ChatResponse chatResponse) {
var responseMessage = chatResponse.getChoices().get(0).getMessage();
var functionCall = responseMessage.getFunctionCall();
var functionResponse = getFunctionResponse(functionCall);
chatBuilder.addMessage(Message.builder().name(functionCall.getName()).role(Role.FUNCTION)
.content(functionResponse)
.build());
var response = client.chat(chatBuilder.build());
response.getResponse().ifPresent(chatResponse1 ->
System.out.println(chatResponse1.getChoices().get(0).getMessage().getContent()));
}
The handleFunctionCallback
handles the function callback response received from the ChatGPT model. It retrieves the function call from the response, invokes the appropriate function to generate a response, adds the function response as a message in the chatBuilder
, sends the updated chatBuilder back to the model, and prints the subsequent response generated by the model to the console. Here's a breakdown of what the code does:
-
var responseMessage = chatResponse.getChoices().get(0).getMessage()
: This line retrieves the first message from the choices available in thechatResponse
object. ThechatResponse
likely contains multiple possible responses generated by the ChatGPT model, and here we are focusing on the first one. -
var functionCall = responseMessage.getFunctionCall()
: This line retrieves theFunctionCall
object from theresponseMessage
. TheFunctionCall
represents a function call made by the ChatGPT model during the conversation. -
var functionResponse = getFunctionResponse(functionCall)
: This line invokes thegetFunctionResponse()
method, passing thefunctionCall
object as an argument, to retrieve the response generated by the function call. -
chatBuilder.addMessage(Message.builder().name(functionCall.getName()).role(Role.FUNCTION).content(functionResponse).build())
: This line creates a newMessage
object representing the response from the function call. It sets the name of the message to the name of the function, assigns the role asRole.FUNCTION
, and sets the content of the message as thefunctionResponse
. The message is then added to thechatBuilder
. This enables ChatGPT model to mix in the response from our message. -
var response = client.chat(chatBuilder.build())
: This line sends the updatedchatBuilder
with the function response message to the ChatGPT model by invoking thechat()
method of theclient
. It likely initiates the next iteration of the conversation, including the function response. -
response.getResponse().ifPresent(chatResponse1 -> System.out.println(chatResponse1.getChoices().get(0).getMessage().getContent()))
: This line retrieves the response generated by the ChatGPT model in theresponse
object. It then extracts the first message choice from the response and prints its content to the console.
It is useful to look at the actual messages going to and fro ChatGPT to fully grok this example.
- Call the ChatGPT chat with the user query and a set of functions defined in the functions parameter.
Here is the initial message that we send to Chat GPT:
{
"model":"gpt-3.5-turbo-0613",
"messages":[
{
"role":"user",
"content":"What's the weather like in Boston in fahrenheit?"
}
],
"function_call":"auto",
"functions":[
{
"name":"get_current_weather",
"parameters":{
"type":"object",
"properties":{
"location":{
"type":"string"
},
"unit":{
"type":"string",
"enum":[
"celsius",
"fahrenheit"
]
}
},
"required":[
"location"
]
}
}
]
}
- ChatGPT can choose to call a function. ChatGPT selects this function by returning a
functionCall
from a message (from a choice). ThefunctionaCall
arguments is in a JSON object that you must deserialize.
Here is the response form ChatGPT
{
"id": "chatcmpl-7aWQG4KfBi7zLXkQXkGv0lp7YHGuu",
"object": "chat.completion",
"created": 1688938796,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_current_weather",
"arguments": "{\n \"location\": \"Boston\",\n \"unit\": \"fahrenheit\"\n}"
}
},
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 61,
"completion_tokens": 24,
"total_tokens": 85
}
}
Notice that ChatGPT returned message
that has a function_call
defined. This means it wants you to invoke your function called get_current_weather
.
From the functionaCall
you call a function in your code with the arguments provided, and get a function response.
- Call the ChatGPT again by appending the function response as a new message, and let the model summarize the results back to the user.
Here is the original ask with the function response mixed in.
{
"model":"gpt-3.5-turbo-0613",
"messages":[
{
"role":"user",
"content":"What's the weather like in Boston in fahrenheit?"
},
{
"role":"function",
"content":"{\"location\":\"Boston\",\"unit\":\"fahrenheit\",\"temperature\":70}",
"name":"get_current_weather"
}
]
...
}
Then lastly ChatGPT mixes the results with the content/context returned from your weather function.
The final response from ChatGPT mixing our get_current_weather
response.
{
"id": "chatcmpl-7aWQIWMzyaPDNtxJtmBQ43PYfEueh",
"object": "chat.completion",
"created": 1688938798,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The weather in Boston is currently 70 degrees Fahrenheit."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 81,
"completion_tokens": 12,
"total_tokens": 93
}
}
This developer notebook provides a comprehensive guide on implementing and integrating functions into a ChatGPT conversation with JAI. The first step is defining a function. This can be done by creating a dictionary that maps function names to their respective implementation. The implementation can be a simple function with arguments or a more complex function, such as one that makes API calls to retrieve data.
Next, we covered handling function callbacks. When ChatGPT calls a function, it returns a "function call" object containing the function's name and its arguments. The function call is extracted from the response message, and the appropriate function is invoked with the provided arguments. The function then generates a response, which is sent back to ChatGPT.
Once the function generates the response, we explain how to call the ChatGPT again by appending the function response as a new message. This allows ChatGPT to mix the results with the content/context returned from the function. The updated chat request is then sent back to the ChatGPT model, and the process continues until a final response is generated.
We also included an example implementation of a weather-related function and its integration into a larger program using a function map. The function map associates function names with their respective implementations for easy access in a ChatGPT conversation.
Overall, this guide explains how to implement and integrate functions into a ChatGPT conversation, from defining a function to handling function callbacks and mixing the results with the content/context returned.
As artificial intelligence and chatbots continue to gain popularity, integrating functions into chat conversations is becoming increasingly important. Functions are small units of code that can be reused and embedded into larger programs to perform a specific task. In this blog post, we will discuss how to implement and integrate functions into ChatGPT conversations using JAI, a Java Open AI API client. This guide will define a function, handle function callbacks, and mix function results with content/context returned from the function. Also, we'll be able to provide an example of a weather-related function and its integration into a larger program using a function map.
- Java Open AI Client
- Using ChatGpt embeddings and hyde to improve search results
- Anthropics Claude Chatbot Gets Upgrade
- Elon Musks XAi new frontier for artificial intelligence
- Using Mockito to test JAI Java Open AI Client
- Fine tuning journey with Open AI API
- Using Open AI to create callback functions, the basis for plugins
- Using Java Open AI Client Async
- Fastest Java JSON Parser
- Java Open AI API Client on Github
- Medium: Introducing Java Open AI Client
- Medium: Using ChatGPT, Embeddings, and HyDE to Improve Search Results