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
promptTemplatePromptTemplateThe PromptTemplate instance containing the configuration.
Properties
SystemPrompt
Gets or sets the initial system prompt.
public string SystemPrompt { get; set; }
Property Value
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
TokenCount
Gets the number of tokens in the conversation.
public int TokenCount { get; }
Property Value
Turns
Gets or sets the list of turns in the conversation.
public List<Turn> Turns { get; set; }
Property Value
Methods
AddTurn(string, bool)
Adds a new turn to the conversation with the provided content.
public Task AddTurn(string content, bool countTokens = true)
Parameters
contentstringThe content for the new turn.
countTokensboolA 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
turnTypestringThe type of the new turn ("Human" or "Assistant").
contentstringThe content for the new turn.
countTokensboolA 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
jsonFilestringpromptTemplatePromptTemplate
Returns
GetPrompt(Conversation, PromptTemplate)
Builds and returns the chat conversation prompt.
public static string GetPrompt(Conversation conversation, PromptTemplate promptTemplate)
Parameters
conversationConversationThe Conversation object from which the prompt will be built.
promptTemplatePromptTemplateThe 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
conversationTextstringThe conversation text to parse.
promptTemplatePromptTemplateThe PromptTemplate instance containing the configuration.
countTokensboolA 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
conversationConversationjsonFilestring