Added ability to use and generate new tools
To allow GPT model to use a tool you must explicitly provide -tool {NAME}
of that tool. This is a cost-saving measure as it's includes all tools input as part as input tokens.
To create a new tool create new class using inheritance
public partial class TOOL_NAME BaseGptTool, IExpressionGptTool<PARAMETERS>
Code generation will use XML summary comments to complete all necessary implementation details.
Eg:
/// <summary>
/// Generate an image based on the given prompt, returns the URL of the generated image.
/// </summary>
public partial class GenerateImageTool : BaseGptTool, IExpressionGptTool<string, string, QualityEnum?, SizeEnum?, StyleEnum?>
{
private readonly OpenAIClient _api;
public override string[] Aliases { get; } =
{
"image",
"generate-image",
};
public GenerateImageTool(OpenAIClient api) : this()
{
_api = api;
}
/// <summary>
/// Generate an image based on the given prompt, returns the byte array of the generated image, that is then
/// attached AUTOMATICALLY to the response message. Do not mention the image in the response message.
/// </summary>
/// <param name="prompt">
/// Prompt field guides the AI in generating images by providing a clear, concise description of the desired
/// scene or subject, including specific details like the setting, style, and mood. Use descriptive language to specify
/// key elements, context, and artistic styles to ensure the resulting image closely aligns with your vision.
/// </param>
/// <param name="name">
/// Short image name that will be used as file name. Use hyphen and leave out extension format. Use
/// hyphens to mark words
/// </param>
/// <param name="quality">
/// The quality of the image that will be generated. hd creates images with finer details and greater
/// consistency across the image.
/// </param>
/// <param name="size">The size of the generated images, default is square</param>
/// <param name="style">
/// The style of the generated images. Vivid causes the model to lean towards generating hyper-real and
/// dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. Defaults to
/// vivid
/// </param>
/// <returns></returns>
public async Task<CallExpressionResult> CallExpression(string prompt, string name, QualityEnum? quality,
SizeEnum? size, StyleEnum? style)
{
....
}
}
Will additionally generate, but you can also implement this yourself!
public partial class GenerateImageTool
{
public override string Name => "generateimagetool";
public override string Description => "Generate an image based on the given prompt, returns the byte array of the generated image, that is then attached AUTOMATICALLY to the response message. Do not mention the image in the response message.";
public GenerateImageTool()
{
Parameters = new GptToolParameter
{
Type = PropertyType.Object,
Properties = new Dictionary<string, GptToolParameter>
{
["prompt"] = new GptToolParameter
{
Type = PropertyType.String,
Description = "Prompt field guides the AI in generating images by providing a clear, concise description of the desired scene or subject, including specific details like the setting, style, and mood. Use descriptive language to specify key elements, context, and artistic styles to ensure the resulting image closely aligns with your vision.",
Index = 0,
Required = true
},
["name"] = new GptToolParameter
{
Type = PropertyType.String,
Description = "Short image name that will be used as file name. Use hyphen and leave out extension format. Use hyphens to mark words",
Index = 1,
Required = true
},
["quality"] = new GptToolParameter
{
Type = PropertyType.String,
Description = "The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image.",
Index = 2,
Enum = new List<string> { "Standard", "HighDefinition" },
Required = false
},
["size"] = new GptToolParameter
{
Type = PropertyType.String,
Description = "The size of the generated images, default is square",
Index = 3,
Enum = new List<string> { "Square", "Portrait", "Landscape" },
Required = false
},
["style"] = new GptToolParameter
{
Type = PropertyType.String,
Description = "The style of the generated images. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. Defaults to vivid",
Index = 4,
Enum = new List<string> { "Vivid", "Natural" },
Required = false
},
}
};
}
public override async Task<CallExpressionResult> CallExpressionInternal(string jsonParameters, Func<string, Type, object> deserialize)
{
var parameters = (InternalCallingParameters)deserialize(jsonParameters, typeof(InternalCallingParameters));
return await CallExpression(
parameters.prompt,
parameters.name,
parameters.quality,
parameters.size,
parameters.style
);
}
public struct InternalCallingParameters
{
public string prompt { get; set; }
public string name { get; set; }
public Slack_GPT_Socket.Functions.QualityEnum? quality { get; set; }
public Slack_GPT_Socket.Functions.SizeEnum? size { get; set; }
public Slack_GPT_Socket.Functions.StyleEnum? style { get; set; }
}
}
requires file:upload
to properly generate images