@@ -5,28 +5,20 @@ import {CommandModule} from "yargs";
5
5
import chalk from "chalk" ;
6
6
import fs from "fs-extra" ;
7
7
import { 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" ;
14
8
import { getIsInDocumentationMode } from "../../state.js" ;
15
9
import { ReplHistory } from "../../utils/ReplHistory.js" ;
16
10
import withStatusLogs from "../../utils/withStatusLogs.js" ;
17
- import { AlpacaChatWrapper } from "../../chatWrappers/AlpacaChatWrapper.js" ;
18
- import { FunctionaryChatWrapper } from "../../chatWrappers/FunctionaryChatWrapper.js" ;
19
11
import { defineChatSessionFunction } from "../../evaluator/LlamaChatSession/utils/defineChatSessionFunction.js" ;
20
12
import { getLlama } from "../../bindings/getLlama.js" ;
21
13
import { LlamaGrammar } from "../../evaluator/LlamaGrammar.js" ;
22
- import { ModelTypeDescription } from "../../bindings/AddonTypes.js" ;
23
14
import { LlamaChatSession } from "../../evaluator/LlamaChatSession/LlamaChatSession.js" ;
24
15
import { LlamaModel } from "../../evaluator/LlamaModel.js" ;
25
16
import { LlamaContext } from "../../evaluator/LlamaContext/LlamaContext.js" ;
26
17
import { LlamaJsonSchemaGrammar } from "../../evaluator/LlamaJsonSchemaGrammar.js" ;
27
18
import { 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" ;
30
22
31
23
type ChatCommand = {
32
24
model : string ,
@@ -35,7 +27,7 @@ type ChatCommand = {
35
27
systemPromptFile ?: string ,
36
28
prompt ?: string ,
37
29
promptFile ?: string ,
38
- wrapper : ( typeof modelWrappers ) [ number ] ,
30
+ wrapper : ChatWrapperTypeName ,
39
31
contextSize : number ,
40
32
batchSize ?: number ,
41
33
grammar : "text" | Parameters < typeof LlamaGrammar . getFor > [ 1 ] ,
@@ -108,7 +100,7 @@ export const ChatCommand: CommandModule<object, ChatCommand> = {
108
100
alias : "w" ,
109
101
type : "string" ,
110
102
default : "auto" as ChatCommand [ "wrapper" ] ,
111
- choices : modelWrappers ,
103
+ choices : chatWrapperTypeNames ,
112
104
description : "Chat wrapper to use. Use `auto` to automatically select a wrapper based on the model's BOS token" ,
113
105
group : "Optional:"
114
106
} )
@@ -343,7 +335,7 @@ async function RunChat({
343
335
: undefined ;
344
336
const bos = model . tokens . bosString ; // bos = beginning of sequence
345
337
const eos = model . tokens . bosString ; // eos = end of sequence
346
- const chatWrapper = getChatWrapper ( wrapper , {
338
+ const chatWrapper = resolveChatWrapperBasedOnWrapperTypeName ( wrapper , {
347
339
bosString : bos ,
348
340
filename : model . filename ,
349
341
typeDescription : model . typeDescription
@@ -477,46 +469,3 @@ const defaultEnvironmentFunctions = {
477
469
}
478
470
} )
479
471
} ;
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