LLM for Unity  v2.3.0
Create characters in Unity with LLMs!
Loading...
Searching...
No Matches
LLMUnity.ChatTemplate Class Referenceabstract

Class implementing the skeleton of a chat template. More...

Inheritance diagram for LLMUnity.ChatTemplate:
[legend]

Public Member Functions

virtual string GetName ()
 Returns the chat template name.
 
virtual string GetDescription ()
 Returns the chat template description.
 
virtual string[] GetNameMatches ()
 Returns an array of names that can be used to match the chat template.
 
virtual string[] GetChatTemplateMatches ()
 Returns an array of jinja templates that can be used to match the chat template.
 
virtual string[] GetStop (string playerName, string AIName)
 Returns an array of the stopwords used by the template.
 
virtual string ComputePrompt (List< ChatMessage > messages, string playerName, string AIName, bool endWithPrefix=true)
 Constructs the prompt using the template based on a list of ChatMessages.
 

Static Public Member Functions

static string FromName (string name)
 Determines the chat template name from a search name. It searches if any of the chat template names is a substring of the provided name.
 
static string FromTemplate (string template)
 Determines the chat template name from a Jinja template.
 
static string FromGGUF (string path)
 Determines the chat template name from a GGUF file. It reads the GGUF file and then determines the chat template name based on:
 
static string FromGGUF (GGUFReader reader, string path)
 
static ChatTemplate GetTemplate (string template)
 Creates the chat template based on the provided chat template name.
 

Static Public Attributes

static string DefaultTemplate
 the default template used when it can't be determined ("chatml")
 
static Dictionary< string, ChatTemplatetemplates
 a dictionary from chat template name to chat template type. It can be used to get the chat template names supported with:
 

Detailed Description

Class implementing the skeleton of a chat template.

Definition at line 12 of file LLMChatTemplates.cs.

Member Function Documentation

◆ ComputePrompt()

virtual string LLMUnity.ChatTemplate.ComputePrompt ( List< ChatMessage > messages,
string playerName,
string AIName,
bool endWithPrefix = true )
inlinevirtual

Constructs the prompt using the template based on a list of ChatMessages.

Parameters
messageslist of ChatMessages e.g. the LLMCharacter chat
AINamethe AI name
endWithPrefixwhether to end the prompt with the AI prefix
Returns
prompt

Reimplemented in LLMUnity.GemmaTemplate, and LLMUnity.Phi3Template.

Definition at line 172 of file LLMChatTemplates.cs.

◆ FromGGUF() [1/2]

static string LLMUnity.ChatTemplate.FromGGUF ( GGUFReader reader,
string path )
inlinestatic

Definition at line 120 of file LLMChatTemplates.cs.

◆ FromGGUF() [2/2]

static string LLMUnity.ChatTemplate.FromGGUF ( string path)
inlinestatic

Determines the chat template name from a GGUF file. It reads the GGUF file and then determines the chat template name based on:

  • the jinja template defined in the file (if it exists and matched)
  • the model name defined in the file (if it exists and matched)
  • the filename defined in the file (if matched)
  • otherwises uses the DefaultTemplate
Parameters
pathGGUF file path
Returns
template name

Definition at line 115 of file LLMChatTemplates.cs.

◆ FromName()

static string LLMUnity.ChatTemplate.FromName ( string name)
inlinestatic

Determines the chat template name from a search name. It searches if any of the chat template names is a substring of the provided name.

Parameters
namesearch name
Returns
chat template name

Definition at line 80 of file LLMChatTemplates.cs.

◆ FromTemplate()

static string LLMUnity.ChatTemplate.FromTemplate ( string template)
inlinestatic

Determines the chat template name from a Jinja template.

Parameters
templateJinja template
Returns
chat template name

Definition at line 96 of file LLMChatTemplates.cs.

◆ GetChatTemplateMatches()

virtual string[] LLMUnity.ChatTemplate.GetChatTemplateMatches ( )
inlinevirtual

Returns an array of jinja templates that can be used to match the chat template.

Reimplemented in LLMUnity.ChatMLTemplate, LLMUnity.LLama3ChatTemplate, LLMUnity.MistralChatTemplate, LLMUnity.VicunaTemplate, LLMUnity.Phi3Template, LLMUnity.Phi3_5Template, and LLMUnity.ZephyrTemplate.

Definition at line 153 of file LLMChatTemplates.cs.

◆ GetDescription()

◆ GetName()

◆ GetNameMatches()

virtual string[] LLMUnity.ChatTemplate.GetNameMatches ( )
inlinevirtual

◆ GetStop()

virtual string[] LLMUnity.ChatTemplate.GetStop ( string playerName,
string AIName )
inlinevirtual

◆ GetTemplate()

static ChatTemplate LLMUnity.ChatTemplate.GetTemplate ( string template)
inlinestatic

Creates the chat template based on the provided chat template name.

Parameters
templatechat template name
Returns
chat template

Definition at line 141 of file LLMChatTemplates.cs.

Member Data Documentation

◆ DefaultTemplate

string LLMUnity.ChatTemplate.DefaultTemplate
static

the default template used when it can't be determined ("chatml")

Definition at line 15 of file LLMChatTemplates.cs.

◆ templates

Dictionary<string, ChatTemplate> LLMUnity.ChatTemplate.templates
static

a dictionary from chat template name to chat template type. It can be used to get the chat template names supported with:

Class implementing the skeleton of a chat template.
static Dictionary< string, ChatTemplate > templates
a dictionary from chat template name to chat template type. It can be used to get the chat template n...

Definition at line 22 of file LLMChatTemplates.cs.


The documentation for this class was generated from the following file: