Class Function
- Namespace
- OpenAI
- Assembly
- OpenAI-DotNet.dll
public sealed class Function : ITool
- Inheritance
-
Function
- Implements
- Inherited Members
Constructors
Function()
public Function()
Function(string, string, string, bool?)
Creates a new function description to insert into a chat conversation.
public Function(string name, string description, string parameters, bool? strict = null)
Parameters
namestringRequired. The name of the function to generate arguments for based on the context in a message.
May contain a-z, A-Z, 0-9, underscores and dashes, with a maximum length of 64 characters. Recommended to not begin with a number or a dash.descriptionstringAn optional description of the function, used by the API to determine if it is useful to include in the response.
parametersstringAn optional JSON describing the parameters of the function that the model can generate.
strictbool?Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is true. Learn more about Structured Outputs in the function calling guide.
https://platform.openai.com/docs/api-reference/assistants/docs/guides/function-calling
Function(string, string, JsonNode, bool?)
Creates a new function description to insert into a chat conversation.
public Function(string name, string description = null, JsonNode parameters = null, bool? strict = null)
Parameters
namestringRequired. The name of the function to generate arguments for based on the context in a message.
May contain a-z, A-Z, 0-9, underscores and dashes, with a maximum length of 64 characters. Recommended to not begin with a number or a dash.descriptionstringAn optional description of the function, used by the API to determine if it is useful to include in the response.
parametersJsonNodeAn optional JSON object describing the parameters of the function that the model can generate.
strictbool?Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is true. Learn more about Structured Outputs in the function calling guide.
https://platform.openai.com/docs/api-reference/assistants/docs/guides/function-calling
Properties
Arguments
The arguments to use when calling the function.
[JsonInclude]
[JsonPropertyName("arguments")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public JsonNode Arguments { get; }
Property Value
Description
The optional description of the function.
[JsonInclude]
[JsonPropertyName("description")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Description { get; }
Property Value
Name
The name of the function to generate arguments for.
May contain a-z, A-Z, 0-9, and underscores and dashes, with a maximum length of 64 characters.
Recommended to not begin with a number or a dash.
[JsonInclude]
[JsonPropertyName("name")]
public string Name { get; }
Property Value
Parameters
The optional parameters of the function. Describe the parameters that the model should generate in JSON schema format (json-schema.org).
[JsonInclude]
[JsonPropertyName("parameters")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public JsonNode Parameters { get; }
Property Value
Strict
Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field.
[JsonInclude]
[JsonPropertyName("strict")]
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool? Strict { get; }
Property Value
- bool?
Remarks
Only a subset of JSON Schema is supported when strict is true.
Type
[JsonInclude]
[JsonPropertyName("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Type { get; }
Property Value
Methods
FromFunc<TResult>(string, Func<TResult>, string, bool?)
public static Function FromFunc<TResult>(string name, Func<TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
TResult
FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(string, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> function, string description = null, bool? strict = null)
Parameters
namestringfunctionFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>descriptionstringstrictbool?
Returns
Type Parameters
T1T2T3T4T5T6T7T8T9TResult
FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(string, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> function, string description = null, bool? strict = null)
Parameters
namestringfunctionFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>descriptionstringstrictbool?
Returns
Type Parameters
T1T2T3T4T5T6T7T8T9T10TResult
FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(string, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> function, string description = null, bool? strict = null)
Parameters
namestringfunctionFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>descriptionstringstrictbool?
Returns
Type Parameters
T1T2T3T4T5T6T7T8T9T10T11TResult
FromFunc<T1, TResult>(string, Func<T1, TResult>, string, bool?)
public static Function FromFunc<T1, TResult>(string name, Func<T1, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1TResult
FromFunc<T1, T2, TResult>(string, Func<T1, T2, TResult>, string, bool?)
public static Function FromFunc<T1, T2, TResult>(string name, Func<T1, T2, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2TResult
FromFunc<T1, T2, T3, TResult>(string, Func<T1, T2, T3, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, TResult>(string name, Func<T1, T2, T3, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3TResult
FromFunc<T1, T2, T3, T4, TResult>(string, Func<T1, T2, T3, T4, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, TResult>(string name, Func<T1, T2, T3, T4, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3T4TResult
FromFunc<T1, T2, T3, T4, T5, TResult>(string, Func<T1, T2, T3, T4, T5, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, TResult>(string name, Func<T1, T2, T3, T4, T5, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3T4T5TResult
FromFunc<T1, T2, T3, T4, T5, T6, TResult>(string, Func<T1, T2, T3, T4, T5, T6, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3T4T5T6TResult
FromFunc<T1, T2, T3, T4, T5, T6, T7, TResult>(string, Func<T1, T2, T3, T4, T5, T6, T7, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, T7, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, T7, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3T4T5T6T7TResult
FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(string, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>, string, bool?)
public static Function FromFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(string name, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> function, string description = null, bool? strict = null)
Parameters
Returns
Type Parameters
T1T2T3T4T5T6T7T8TResult
Invoke()
Invokes the function and returns the result as json.
public string Invoke()
Returns
- string
The result of the function as json.
InvokeAsync(CancellationToken)
Invokes the function and returns the result as json.
public Task<string> InvokeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
InvokeAsync<T>(CancellationToken)
Invokes the function and returns the result.
public Task<T> InvokeAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
- Task<T>
The result of the function.
Type Parameters
TExpected return type.
Invoke<T>()
Invokes the function and returns the result.
public T Invoke<T>()
Returns
- T
The result of the function.
Type Parameters
TThe expected return type.