Table of Contents

Class OpenAiChat

Namespace
BotManager.OpenAi.Expressions
Assembly
BotManager.OpenAi.dll

Executes a char request to the OpenAI api. The OpenAiInit must be initialized.

Return type is string.

This json example sends an OpenAI chat request and returns the result:
{ "$OpenAiChat": { "Messages": [
  { "Role": "System", "Text": "Create a recipe suggestion for the following ingredient list:" },
  { "Role": "User", "Text": "Cheesecake" }
] } }
public sealed class OpenAiChat : IExpression
Inheritance
OpenAiChat
Implements
Inherited Members

Constructors

OpenAiChat()

public OpenAiChat()

Properties

Messages

The chat messages to respond to.

You should provide your ruleset as a separate OpenAI.GPT3.ObjectModels.StaticValues.ChatMessageRoles.System message and not concat it with user input. Use a message with OpenAI.GPT3.ObjectModels.StaticValues.ChatMessageRoles.User role for user input. This prioritizes your ruleset over the user input and protects against prompt injection.

public OpenAiChatMessage[]? Messages { get; set; }

Property Value

OpenAiChatMessage[]

Methods

ExecuteAsync(RuntimeContext, Type?)

Executes the expression in the given RuntimeContext. Please do not use this method to run an expression. Use ExecuteAsync(IExpression?) instead.

public Task<object?> ExecuteAsync(RuntimeContext context, Type? returnType)

Parameters

context RuntimeContext

The current runtime context.

returnType Type

The expected return type. Use typeof(object) for a generic result. Use null if you don't need the return value.

Returns

Task<object>

Returns the result of the expression.