Skip to content

Commit 3655ff3

Browse files
com.openai.unity 7.7.3 (#200)
- Updated ChatRequest toolChoice to only send type and name of function, reducing token usage
1 parent 19e5bab commit 3655ff3

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Runtime/Chat/ChatRequest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public ChatRequest(
3232
string user = null)
3333
: this(messages, model, frequencyPenalty, logitBias, maxTokens, number, presencePenalty, responseFormat, seed, stops, temperature, topP, topLogProbs, user)
3434
{
35-
var tooList = tools?.ToList();
35+
var toolList = tools?.ToList();
3636

37-
if (tooList != null && tooList.Any())
37+
if (toolList != null && toolList.Any())
3838
{
3939
if (string.IsNullOrWhiteSpace(toolChoice))
4040
{
@@ -45,8 +45,9 @@ public ChatRequest(
4545
if (!toolChoice.Equals("none") &&
4646
!toolChoice.Equals("auto"))
4747
{
48-
var tool = tooList.FirstOrDefault(t => t.Function.Name.Contains(toolChoice));
49-
ToolChoice = tool ?? throw new ArgumentException($"The specified tool choice '{toolChoice}' was not found in the list of tools");
48+
var tool = toolList.FirstOrDefault(t => t.Function.Name.Contains(toolChoice)) ??
49+
throw new ArgumentException($"The specified tool choice '{toolChoice}' was not found in the list of tools");
50+
ToolChoice = new { type = "function", function = new { name = tool.Function.Name } };
5051
}
5152
else
5253
{
@@ -55,7 +56,7 @@ public ChatRequest(
5556
}
5657
}
5758

58-
Tools = tooList?.ToList();
59+
Tools = toolList?.ToList();
5960
}
6061

6162
/// <summary>

Tests/Weather/WeatherService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal enum WeatherUnit
1616
[Function("Get the current weather in a given location")]
1717
public static async Task<string> GetCurrentWeatherAsync(
1818
[FunctionParameter("The location the user is currently in.")] string location,
19-
[FunctionParameter("The units the use has requested temperature in. Typically this is based on the users location.")] WeatherUnit unit)
19+
[FunctionParameter("The units the user has requested temperature in. Typically this is based on the users location.")] WeatherUnit unit)
2020
{
2121
var temp = new Random().Next(-10, 40);
2222

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "OpenAI",
44
"description": "A OpenAI package for the Unity Game Engine to use GPT-4, GPT-3.5, GPT-3 and Dall-E though their RESTful API (currently in beta).\n\nIndependently developed, this is not an official library and I am not affiliated with OpenAI.\n\nAn OpenAI API account is required.",
55
"keywords": [],
6-
"version": "7.7.2",
6+
"version": "7.7.3",
77
"unity": "2021.3",
88
"documentationUrl": "https://github.com/RageAgainstThePixel/com.openai.unity#documentation",
99
"changelogUrl": "https://github.com/RageAgainstThePixel/com.openai.unity/releases",

0 commit comments

Comments
 (0)