@@ -5,28 +5,20 @@ import {CommandModule} from "yargs";
55import chalk from "chalk" ;
66import fs from "fs-extra" ;
77import { chatCommandHistoryFilePath , defaultChatSystemPrompt } from "../../config.js" ;
8- import { LlamaChatWrapper } from "../../chatWrappers/LlamaChatWrapper.js" ;
9- import { GeneralChatWrapper } from "../../chatWrappers/GeneralChatWrapper.js" ;
10- import { ChatMLChatWrapper } from "../../chatWrappers/ChatMLChatWrapper.js" ;
11- import { resolveChatWrapperBasedOnModel } from "../../chatWrappers/resolveChatWrapperBasedOnModel.js" ;
12- import { ChatWrapper } from "../../ChatWrapper.js" ;
13- import { FalconChatWrapper } from "../../chatWrappers/FalconChatWrapper.js" ;
148import { getIsInDocumentationMode } from "../../state.js" ;
159import { ReplHistory } from "../../utils/ReplHistory.js" ;
1610import withStatusLogs from "../../utils/withStatusLogs.js" ;
17- import { AlpacaChatWrapper } from "../../chatWrappers/AlpacaChatWrapper.js" ;
18- import { FunctionaryChatWrapper } from "../../chatWrappers/FunctionaryChatWrapper.js" ;
1911import { defineChatSessionFunction } from "../../evaluator/LlamaChatSession/utils/defineChatSessionFunction.js" ;
2012import { getLlama } from "../../bindings/getLlama.js" ;
2113import { LlamaGrammar } from "../../evaluator/LlamaGrammar.js" ;
22- import { ModelTypeDescription } from "../../bindings/AddonTypes.js" ;
2314import { LlamaChatSession } from "../../evaluator/LlamaChatSession/LlamaChatSession.js" ;
2415import { LlamaModel } from "../../evaluator/LlamaModel.js" ;
2516import { LlamaContext } from "../../evaluator/LlamaContext/LlamaContext.js" ;
2617import { LlamaJsonSchemaGrammar } from "../../evaluator/LlamaJsonSchemaGrammar.js" ;
2718import { LlamaLogLevel } from "../../bindings/types.js" ;
28-
29- const modelWrappers = [ "auto" , "general" , "llamaChat" , "alpacaChat" , "functionary" , "chatML" , "falconChat" ] as const ;
19+ import {
20+ resolveChatWrapperBasedOnWrapperTypeName , chatWrapperTypeNames , ChatWrapperTypeName
21+ } from "../../bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.js" ;
3022
3123type ChatCommand = {
3224 model : string ,
@@ -35,7 +27,7 @@ type ChatCommand = {
3527 systemPromptFile ?: string ,
3628 prompt ?: string ,
3729 promptFile ?: string ,
38- wrapper : ( typeof modelWrappers ) [ number ] ,
30+ wrapper : ChatWrapperTypeName ,
3931 contextSize : number ,
4032 batchSize ?: number ,
4133 grammar : "text" | Parameters < typeof LlamaGrammar . getFor > [ 1 ] ,
@@ -108,7 +100,7 @@ export const ChatCommand: CommandModule<object, ChatCommand> = {
108100 alias : "w" ,
109101 type : "string" ,
110102 default : "auto" as ChatCommand [ "wrapper" ] ,
111- choices : modelWrappers ,
103+ choices : chatWrapperTypeNames ,
112104 description : "Chat wrapper to use. Use `auto` to automatically select a wrapper based on the model's BOS token" ,
113105 group : "Optional:"
114106 } )
@@ -343,7 +335,7 @@ async function RunChat({
343335 : undefined ;
344336 const bos = model . tokens . bosString ; // bos = beginning of sequence
345337 const eos = model . tokens . bosString ; // eos = end of sequence
346- const chatWrapper = getChatWrapper ( wrapper , {
338+ const chatWrapper = resolveChatWrapperBasedOnWrapperTypeName ( wrapper , {
347339 bosString : bos ,
348340 filename : model . filename ,
349341 typeDescription : model . typeDescription
@@ -477,46 +469,3 @@ const defaultEnvironmentFunctions = {
477469 }
478470 } )
479471} ;
480-
481- function getChatWrapper ( wrapper : ChatCommand [ "wrapper" ] , {
482- bosString,
483- filename,
484- typeDescription
485- } : {
486- bosString ?: string | null ,
487- filename ?: string ,
488- typeDescription ?: ModelTypeDescription
489- } ) : ChatWrapper {
490- switch ( wrapper ) {
491- case "general" :
492- return new GeneralChatWrapper ( ) ;
493- case "llamaChat" :
494- return new LlamaChatWrapper ( ) ;
495- case "alpacaChat" :
496- return new AlpacaChatWrapper ( ) ;
497- case "functionary" :
498- return new FunctionaryChatWrapper ( ) ;
499- case "chatML" :
500- return new ChatMLChatWrapper ( ) ;
501- case "falconChat" :
502- return new FalconChatWrapper ( ) ;
503- default :
504- }
505-
506- if ( wrapper === "auto" ) {
507- const chatWrapper = resolveChatWrapperBasedOnModel ( {
508- bosString,
509- filename,
510- typeDescription
511- } ) ;
512-
513- if ( chatWrapper != null )
514- return new chatWrapper ( ) ;
515-
516- return new GeneralChatWrapper ( ) ;
517- }
518-
519- void ( wrapper satisfies never ) ;
520-
521- throw new Error ( "Unknown wrapper: " + wrapper ) ;
522- }
0 commit comments