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
PromptTemplateThe 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
content
stringThe content for the new turn.
countTokens
boolA 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
stringThe type of the new turn ("Human" or "Assistant").
content
stringThe content for the new turn.
countTokens
boolA 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
stringpromptTemplate
PromptTemplate
Returns
GetPrompt(Conversation, PromptTemplate)
Builds and returns the chat conversation prompt.
public static string GetPrompt(Conversation conversation, PromptTemplate promptTemplate)
Parameters
conversation
ConversationThe Conversation object from which the prompt will be built.
promptTemplate
PromptTemplateThe 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
stringThe conversation text to parse.
promptTemplate
PromptTemplateThe PromptTemplate instance containing the configuration.
countTokens
boolA 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
ConversationjsonFile
string