com.openai.unity 7.7.1 #197
Replies: 3 comments 17 replies
-
Could someone elaborate on the public class GetPositionTool
{
public class Args
{
public string ObjectName { get; set; }
}
public static OpenAI.Function FunctionSchema = new OpenAI.Function(
nameof(GetPositionCmd),
"Gets the position of an object",
new JObject
{
["type"] = "object",
["properties"] = new JObject
{
[nameof(Args.ObjectName)] = new JObject
{
["type"] = "string",
["description"] = "Name of the object."
},
},
["required"] = new JArray { nameof(Args.ObjectName) }
});
internal static string GetPositionCmd(Args functionArgs)
{
var go = GameObject.Find(functionArgs.ObjectName);
if (go != null)
{
return $"World space position: {go.transform.position}";
}
else
{
return $"Could't find object named {functionArgs.ObjectName}!";
}
}
}
--- (elsewhere in ChatBehavior.cs) ----
private readonly List<Tool> assistantTools = new List<Tool>();
assistantTools.Add(GetPositionTool.FunctionSchema);
var request = new ChatRequest(conversation.Messages, tools: assistantTools); Now with 7.7 this is appearing easier, and at first glance I thought the Function attribute would make this much tidier... but I'm missing out on how to pass argument descriptions and if they are required. At first glance I was thinking I could refactor my code and write something like the below. Maybe another way of stating it: can [Function("Gets the position of an object")]
internal static string GetPositionCmd(
[FunctionProperty("Name of the object.")]
[Required]
string ObjectName
{
...
}
--- (elsewhere in ChatBehavior.cs) ---
var tools = Tool.GetAllAvailableTools();
var request = new ChatRequest(conversation.Messages, tools: tools); |
Beta Was this translation helpful? Give feedback.
-
Wow this is so much nicer - Thanks for the extra explanations! |
Beta Was this translation helpful? Give feedback.
-
Any hints on how to use arrays or lists as function parameters? I had Arrays working the old way, but it wasn't obvious how to migrate to the new stuff, I've tried I suppose I could just change the signature to have 3 floats in this particular case.... 🤔 You mentioned FunctionPropertyAttribute, but it didn't look like it supported Array types, or at least in a way obvious to me.
Error: ArgumentException: Object of type 'Newtonsoft.Json.Linq.JArray' cannot be converted to type 'System.Single[]'. |
Beta Was this translation helpful? Give feedback.
-
What's Changed
Full Changelog: 7.7.0...7.7.1
This discussion was created from the release com.openai.unity 7.7.1.
Beta Was this translation helpful? Give feedback.
All reactions