New Features (new models and function calling) #296
Replies: 11 comments 1 reply
-
Vague idea: maybe use reflection and attributes to describe callable methods, e.g. [GptMethod(Class = "DbQueries", Description = "Retrieve product information by name")] (Attributes on parameters unfortunately only supported starting with C# 5) In the actual CreateCompletion call, just pass the class of functions relevant for this completion and the SDK infers the "functions=" JSON to pass to OpenAI? For the next step, a helper method could also provide support to call the corresponding method given the name of the method GPT wants to call and the JSON - get the MethodInfo by name, map the JSON, Invoke() ... |
Beta Was this translation helpful? Give feedback.
-
It would be great to have some sort of indication in streaming mode if the response is going to be a function call or a standard message. Easy to scan the deltas and figure it out but it would be still nice to have it built in. |
Beta Was this translation helpful? Give feedback.
-
If the goal itself is to pass a list of functions and the system generating the required schemas to pass into OpenAI API we can pass a list of functions: i.e void ParseFunction(List<(string, dynamic)> functions, string methodName, object[]? args)
{
//Given the method infos it can generate the schemas and then pass onto OpenAI API...
var lookup = functions.ToDictionary(i => i.Item1, i => i.Item2);
MethodInfo method = lookup[methodName].Method;
method.Invoke(null, args); // This would also invoke the method but I reckon this is beyond the scope..
}
//for example lets assume that we want to dynamically pass otherfunc plus some others..
void otherfunc()
{
Console.WriteLine("Empty");
}
//This is the ugly part but we can leverage source generators to have C# compiler generate this for us
List<(string, dynamic)> methods = new()
{
(nameof(SomeFunction), new Action<int>(SomeFunction)),
(nameof(otherfunc), new Action(otherfunc)),
(nameof(returnSum),new Func<int,int,int>(returnSum))
};
ParseFunction(methods, nameof(otherfunc), null); void Example(params object[] functions)
{
//source generator would convert wtv its passed to this function to the list above.
}
#pragma warning disable CS8974 // Converting method group to non-delegate type
Example(SomeFunction, otherfunc);
#pragma warning restore CS8974 // Converting method group to non-delegate type The attribute approach is really interesting but I do think that it is to bothersome for the developer to set it up. On the other hand, I assume most developers wouldnt be creating functions that frequently so it might be worth to see how it would work. |
Beta Was this translation helpful? Give feedback.
-
As an alternative we could explore the concept of 'Registering' a method beforehand, for example: void PreRegister<T>(T function)
{
dynamic value = function; //Hacky but simple
MethodInfo info = value.Method;
Register(info);
}
void Register(MethodInfo methodInfo)
{
//Add methodinfos to some registry
Console.WriteLine("Registering {0} with parameters {1}", methodInfo.Name, string.Join(",", methodInfo.GetParameters().Select(i => $"({i.ParameterType.Name} {i.Name})")));
//CreateCompletion could then query the registry and either return method and arguments or actually invoke it.
}
void AnotherFunction()
{
}
void AnotherFunction2(int someNumber)
{
}
PreRegister(AnotherFunction2);
//Registering <<Main>$>g__AnotherFunction2|0_3 with parameters (Int32 someNumber) |
Beta Was this translation helpful? Give feedback.
-
I would be happy with just an easy way to get the function name as a string and the parameters either as Json or as an object. Different functions can trigger different actions so tying them to specific methods or classes seems too limiting. |
Beta Was this translation helpful? Give feedback.
-
I have released a new beta version that includes "function calling", thanks to @rzubek's pull request. I will read the discussions and feedback in this thread and finalize the release version as soon as possible. |
Beta Was this translation helpful? Give feedback.
-
I implemented the function calling update on my own branch locally. In my project I used custom attributes, system.reflection, and JsonElement from System.Text.Json to fill out function_call. Best! |
Beta Was this translation helpful? Give feedback.
-
Does anyone know when function calling will be added? Can it be added directly to the ChatCompletionCreateRequest object? Thank you!! |
Beta Was this translation helpful? Give feedback.
-
Hey folks, I am pretty green to the whole AI thing, but I am mentally learning the blocks as I go along. I have implemented a basic conversation bot using the ChatCompletion method. I am storing the messages in Azure storage blob and all that good stuff. My overall goal is creating this Lead conversation bot per tenant in our Saas application. I have tenants testing right now and the goal would be to extract data from the lead and then interview them to get to the point of booking an appointment. I have been struggling to this point, but now with the functions coming out, this will solve my problem. Can somebody with the beta bump me in the right direction with this code with a basic function where email is required and I can call a function that would pass that email to the function? Here is my current code and I learn in small steps `
Appreciate your help. Thanks |
Beta Was this translation helpful? Give feedback.
-
Hello! when will this version be released? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I had too many personal things to do last week and couldn't find time to work on the repository. However, I will resolve them by the end of this week. This will allow me to have more free time to work on new features starting from next week. |
Beta Was this translation helpful? Give feedback.
-
Just like me, you must be buzzing about OpenAI's new features! I'll be adding them ASAP. Got thoughts or cool ideas? Let's chat about them under this post!
https://openai.com/blog/function-calling-and-other-api-updates
Beta Was this translation helpful? Give feedback.
All reactions