Table of Contents

Class Function

Namespace
OpenAI
Assembly
OpenAI-DotNet.dll
public sealed class Function
Inheritance
Function
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

name string

Required. 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.

description string

An optional description of the function, used by the API to determine if it is useful to include in the response.

parameters string

An optional JSON describing the parameters of the function that the model can generate.

strict bool?

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

name string

Required. 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.

description string

An optional description of the function, used by the API to determine if it is useful to include in the response.

parameters JsonNode

An optional JSON object describing the parameters of the function that the model can generate.

strict bool?

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

JsonNode

Description

The optional description of the function.

[JsonInclude]
[JsonPropertyName("description")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Description { get; }

Property Value

string

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

string

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

JsonNode

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")]
public string Type { get; }

Property Value

string

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

name string
function Func<TResult>
description string
strict bool?

Returns

Function

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

name string
function Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
T7
T8
T9
TResult

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

name string
function Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
T7
T8
T9
T10
TResult

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

name string
function Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
T7
T8
T9
T10
T11
TResult

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

name string
function Func<T1, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
TResult

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

name string
function Func<T1, T2, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
TResult

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

name string
function Func<T1, T2, T3, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
TResult

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

name string
function Func<T1, T2, T3, T4, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
TResult

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

name string
function Func<T1, T2, T3, T4, T5, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
TResult

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

name string
function Func<T1, T2, T3, T4, T5, T6, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
TResult

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

name string
function Func<T1, T2, T3, T4, T5, T6, T7, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
T7
TResult

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

name string
function Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>
description string
strict bool?

Returns

Function

Type Parameters

T1
T2
T3
T4
T5
T6
T7
T8
TResult

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

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<string>

The result of the function as json.

InvokeAsync<T>(CancellationToken)

Invokes the function and returns the result.

public Task<T> InvokeAsync<T>(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<T>

The result of the function.

Type Parameters

T

Expected return type.

Invoke<T>()

Invokes the function and returns the result.

public T Invoke<T>()

Returns

T

The result of the function.

Type Parameters

T

The expected return type.