Table of Contents

Class Conversation

Namespace
OobaboogaAPIHelper
Assembly
DougWare.OobaboogaAPIHelper.dll

Represents a conversation.

public class Conversation
Inheritance
Conversation
Inherited Members

Constructors

Conversation()

public Conversation()

Conversation(PromptTemplate)

Initializes a new instance of the Conversation class.

public Conversation(PromptTemplate promptTemplate)

Parameters

promptTemplate PromptTemplate

The PromptTemplate instance containing the configuration.

Properties

SystemPrompt

Gets or sets the initial system prompt.

public string SystemPrompt { get; set; }

Property Value

string

SystemPromptTokenCount

Gets or sets the number of tokens in the system prompt. 13 is the number of tokens in the default system prompt.

public int SystemPromptTokenCount { get; set; }

Property Value

int

TokenCount

Gets the number of tokens in the conversation.

public int TokenCount { get; }

Property Value

int

Turns

Gets or sets the list of turns in the conversation.

public List<Turn> Turns { get; set; }

Property Value

List<Turn>

Methods

AddTurn(string, bool)

Adds a new turn to the conversation with the provided content.

public Task AddTurn(string content, bool countTokens = true)

Parameters

content string

The content for the new turn.

countTokens bool

A boolean indicating whether or not to count tokens.

Returns

Task

A Task that represents the asynchronous operation.

AddTurn(string, string, bool)

Adds a new turn to the conversation with the provided turn type and content.

public Task AddTurn(string turnType, string content, bool countTokens = true)

Parameters

turnType string

The type of the new turn ("Human" or "Assistant").

content string

The content for the new turn.

countTokens bool

A boolean indicating whether or not to count tokens.

Returns

Task

A Task that represents the asynchronous operation.

Exceptions

ArgumentException

Thrown if turnType is not valid.

FromJsonFile(string, PromptTemplate)

public static Conversation FromJsonFile(string jsonFile, PromptTemplate promptTemplate = null)

Parameters

jsonFile string
promptTemplate PromptTemplate

Returns

Conversation

GetPrompt(Conversation, PromptTemplate)

Builds and returns the chat conversation prompt.

public static string GetPrompt(Conversation conversation, PromptTemplate promptTemplate)

Parameters

conversation Conversation

The Conversation object from which the prompt will be built.

promptTemplate PromptTemplate

The PromptTemplate instance containing the configuration.

Returns

string

The resulting prompt as a string.

ParseConversationAsync(string, PromptTemplate, bool)

Parses a conversation from a string of conversation text.

public static Task<Conversation> ParseConversationAsync(string conversationText, PromptTemplate promptTemplate, bool countTokens = false)

Parameters

conversationText string

The conversation text to parse.

promptTemplate PromptTemplate

The PromptTemplate instance containing the configuration.

countTokens bool

A boolean indicating whether or not to count tokens.

Returns

Task<Conversation>

A Task that represents the asynchronous operation. The Task.Result property returns a Conversation object representing the conversation.

Examples

string conversationText = "Human: Hello\nAssistant: Hi";
PromptTemplate template = new PromptTemplate();
Conversation conv = await Conversation.ParseConversationAsync(conversationText, template);

Exceptions

ArgumentNullException

Thrown if conversationText is null.

FormatException

Thrown if the conversation text is improperly formatted.

ToJsonFile(Conversation, string)

public static void ToJsonFile(Conversation conversation, string jsonFile)

Parameters

conversation Conversation
jsonFile string