forked from g4rg/tgi-kai-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kai.py
445 lines (314 loc) · 13.9 KB
/
kai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# generated by datamodel-codegen
from __future__ import annotations
from enum import Enum
from typing import Dict, List, Optional
from pydantic import BaseModel, Field, NonNegativeFloat, confloat, conint, constr
class AddSentenceSpacingSettings(BaseModel):
value: bool
class AuthorsNoteDepthSetting(BaseModel):
value: conint(ge=1, le=5)
class AuthorsNoteSetting(BaseModel):
value: str
class AuthorsNoteTemplateSetting(BaseModel):
value: str
class BasicBoolean(BaseModel):
value: bool
class BasicBooleanResult(BaseModel):
result: bool
class BasicError(BaseModel):
msg: str
type: str
class BasicResultInner(BaseModel):
result: str
class BasicResults(BaseModel):
results: List[BasicResultInner]
class BasicString(BaseModel):
value: str
class BasicUID(BaseModel):
uid: conint(ge=-2147483648, le=2147483647) = Field(
..., description='32-bit signed integer unique to this world info entry/folder.'
)
class Empty(BaseModel):
pass
class GenerationInput(BaseModel):
disable_input_formatting: Optional[bool] = Field(
True,
description='When enabled, all input formatting options default to `false` instead of the value in the KoboldAI GUI',
)
disable_output_formatting: Optional[bool] = Field(
True,
description='When enabled, all output formatting options default to `false` instead of the value in the KoboldAI GUI.',
)
frmtadsnsp: Optional[bool] = Field(
None,
description='Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at the end of the previous action.\n\nIf `disable_input_formatting` is `true`, this defaults to `false` instead of the value in the KoboldAI GUI.',
)
frmtrmblln: Optional[bool] = Field(
None,
description='Output formatting option. When enabled, replaces all occurrences of two or more consecutive newlines in the output with one newline.\n\nIf `disable_output_formatting` is `true`, this defaults to `false` instead of the value in the KoboldAI GUI.',
)
frmtrmspch: Optional[bool] = Field(
None,
description='Output formatting option. When enabled, removes `#/@%{}+=~|\\^<>` from the output.\n\nIf `disable_output_formatting` is `true`, this defaults to `false` instead of the value in the KoboldAI GUI.',
)
frmttriminc: Optional[bool] = Field(
None,
description="Output formatting option. When enabled, removes some characters from the end of the output such that the output doesn't end in the middle of a sentence. If the output is less than one sentence long, does nothing.\n\nIf `disable_output_formatting` is `true`, this defaults to `false` instead of the value in the KoboldAI GUI.",
)
max_context_length: Optional[conint(ge=1)] = Field(
None, description='Maximum number of tokens to send to the model.', examples=[2048]
)
max_length: Optional[conint(ge=1, le=512)] = Field(
None, description='Number of tokens to generate.', examples=[80]
)
n: Optional[conint(ge=1, le=5)] = Field(
None, description='Number of outputs to generate.', examples=[1]
)
prompt: str = Field(..., description='This is the submission.', examples=[ "Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze."])
quiet: Optional[bool] = Field(
None,
description='When enabled, Generated output will not be displayed in the console.',
)
rep_pen: Optional[confloat(ge=1.0)] = Field(
None, description='Base repetition penalty value.'
)
rep_pen_range: Optional[conint(ge=0)] = Field(
None, description='Repetition penalty range.'
)
rep_pen_slope: Optional[confloat(ge=0.0)] = Field(
None, description='Repetition penalty slope.'
)
sampler_full_determinism: Optional[bool] = Field(
None,
description='If enabled, the generated text will always be the same as long as you use the same RNG seed, input and settings. If disabled, only the *sequence* of generated texts that you get when repeatedly generating text will be the same given the same RNG seed, input and settings.',
)
sampler_order: Optional[List[int]] = Field(
None,
description='Sampler order to be used. If N is the length of this array, then N must be greater than or equal to 6 and the array must be a permutation of the first N non-negative integers.',
)
sampler_seed: Optional[conint(ge=0, le=18446744073709551615)] = Field(
None,
description='RNG seed to use for sampling. If not specified, the global RNG will be used.',
)
singleline: Optional[bool] = Field(
None,
description='Output formatting option. When enabled, removes everything after the first line of the output, including the newline.\n\nIf `disable_output_formatting` is `true`, this defaults to `false` instead of the value in the KoboldAI GUI.',
)
soft_prompt: Optional[constr(pattern=r'^[^/\\]*$')] = Field(
None,
description='Soft prompt to use when generating. If set to the empty string or any other string containing no non-whitespace characters, uses no soft prompt.',
)
stop_sequence: Optional[List[str]] = Field(
None,
description='An array of string sequences where the API will stop generating further tokens. The returned text WILL contain the stop sequence.',
max_items=10,
)
temperature: Optional[NonNegativeFloat] = Field(None, description='Temperature value.', examples=[0.6])
tfs: Optional[confloat(ge=0.0, le=1.0)] = Field(
None, description='Tail free sampling value.'
)
top_a: Optional[confloat(ge=0.0)] = Field(None, description='Top-a sampling value.')
top_k: Optional[conint(ge=0)] = Field(None, description='Top-k sampling value.')
top_p: Optional[confloat(ge=0.0, le=1.0)] = Field(
None, description='Top-p sampling value.', examples=[0.9]
)
typical: Optional[confloat(ge=0.0, le=1.0)] = Field(
None, description='Typical sampling value.'
)
use_authors_note: Optional[bool] = Field(
False,
description="Whether or not to use the author's note from the KoboldAI GUI when generating text. This has no effect unless `use_story` is also enabled.",
)
use_memory: Optional[bool] = Field(
False,
description='Whether or not to use the memory from the KoboldAI GUI when generating text.',
)
use_story: Optional[bool] = Field(
False,
description='Whether or not to use the story from the KoboldAI GUI when generating text.',
)
use_userscripts: Optional[bool] = Field(
False,
description='Whether or not to use the userscripts from the KoboldAI GUI when generating text.',
)
use_world_info: Optional[bool] = Field(
False,
description='Whether or not to use the world info from the KoboldAI GUI when generating text.',
)
use_default_badwordsids: Optional[bool] = Field(
None,
description="Ban tokens that commonly worsen the writing experience for continuous story writing"
)
class GenerationResult(BaseModel):
text: str = Field(..., description='Generated output as plain text.')
class GensPerActionSetting(BaseModel):
value: conint(ge=0, le=5)
class MaxContextLengthSetting(BaseModel):
value: conint(ge=512, le=2048)
class MaxLengthSetting(BaseModel):
value: conint(ge=1, le=512)
class MemorySetting(BaseModel):
value: str
class Backend(Enum):
KoboldAI_Old_Colab_Method = 'KoboldAI Old Colab Method'
Huggingface = 'Huggingface'
OpenAI = 'OpenAI'
Horde = 'Horde'
Huggingface_GPTQ = 'Huggingface GPTQ'
KoboldAI_API = 'KoboldAI API'
Read_Only = 'Read Only'
GooseAI = 'GooseAI'
ExLlama = 'ExLlama'
Basic_Huggingface = 'Basic Huggingface'
class ModelSelection(BaseModel):
backend: Optional[Backend] = None
model: str = Field(
...,
description='Hugging Face model ID, the path to a model folder (relative to the "models" folder in the KoboldAI root folder) or "ReadOnly" for no model',
)
class NotFoundError(BaseModel):
detail: BasicError
class NotImplementedError(BaseModel):
detail: BasicError
class OutOfMemoryError(BaseModel):
detail: BasicError
class RemoveBlankLinesSettings(BaseModel):
value: bool
class RemoveSpecialCharactersSettings(BaseModel):
value: bool
class SamplerFullDeterminismSetting(BaseModel):
value: bool
class SamplerOrderSetting(BaseModel):
value: List[int] = Field(..., min_items=6)
class SamplerSeedSetting(BaseModel):
value: conint(ge=0, le=18446744073709551615)
class ServerBusyError(BaseModel):
detail: BasicError
class SingleLineSettings(BaseModel):
value: bool
class SoftPromptSetting(BaseModel):
value: constr(pattern=r'^[^/\\]*$') = Field(
...,
description='Soft prompt name, or a string containing only whitespace for no soft prompt. If using the GET method and no soft prompt is loaded, this will always be the empty string.',
)
class SoftPromptsList(BaseModel):
values: List[SoftPromptSetting] = Field(
..., description='Array of available softprompts.'
)
class StoryChunk(BaseModel):
num: int = Field(
...,
description='Guaranteed to not equal the `num` of any other active story chunk. Equals 0 iff this is the first action of the story (the prompt).',
)
text: str = Field(..., description='The text inside this story chunk.')
class StoryChunkNum(BaseModel):
value: int
class StoryChunkResult(BaseModel):
result: StoryChunk
class StoryChunkSetText(BaseModel):
value: constr(pattern=r'^(.|\n)*\S$')
class StoryChunkText(BaseModel):
value: str
class StoryEmptyError(BaseModel):
detail: BasicError
class StoryLoad(BaseModel):
name: constr(pattern=r'^[^/\\]*$')
class StorySave(BaseModel):
name: str #constr(pattern=r'^(?=.*\S)(?!.*[/\\]).*$')
class StoryTooShortError(BaseModel):
detail: BasicError
class SubmissionInput(BaseModel):
disable_input_formatting: Optional[bool] = Field(
True,
description='When enabled, disables all input formatting options, overriding their individual enabled/disabled states.',
)
frmtadsnsp: Optional[bool] = Field(
None,
description='Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at the end of the previous action.',
)
prompt: constr(pattern=r'^[\S\s]*\S[\S\s]*$') = Field(
..., description='This is the submission.'
)
class TailFreeSamplingSetting(BaseModel):
value: confloat(ge=0.0, le=1.0)
class TemperatureSamplingSetting(BaseModel):
value: NonNegativeFloat
class TopASamplingSetting(BaseModel):
value: confloat(ge=0.0)
class TopKSamplingSetting(BaseModel):
value: conint(ge=0)
class TopPSamplingSetting(BaseModel):
value: confloat(ge=0.0, le=1.0)
class TrimIncompleteSentencesSettings(BaseModel):
value: bool
class TypicalSamplingSetting(BaseModel):
value: confloat(ge=0.0, le=1.0)
class ValidationError(BaseModel):
detail: Dict[str, List[str]]
class WorldInfoDepthSetting(BaseModel):
value: conint(ge=1, le=5)
class WorldInfoEntriesUIDs(BaseModel):
entries: List[conint(ge=-2147483648, le=2147483647)]
class WorldInfoEntry(BaseModel):
comment: str = Field(
..., description='The comment/description/title for this world info entry.'
)
constant: bool = Field(
...,
description='Whether or not constant mode is enabled for this world info entry.',
)
content: str = Field(..., description='The "What To Remember" for this entry.')
key: str = Field(
...,
description='Comma-separated list of keys, or of primary keys if selective mode is enabled.',
)
keysecondary: Optional[str] = Field(
None,
description='Comma-separated list of secondary keys if selective mode is enabled.',
)
selective: bool = Field(
...,
description='Whether or not selective mode is enabled for this world info entry.',
)
uid: conint(ge=-2147483648, le=2147483647) = Field(
..., description='32-bit signed integer unique to this world info entry.'
)
class WorldInfoFolder(BaseModel):
entries: List[WorldInfoEntry]
name: str = Field(..., description='Name of this world info folder.')
uid: conint(ge=-2147483648, le=2147483647) = Field(
..., description='32-bit signed integer unique to this world info folder.'
)
class WorldInfoFolderBasic(BaseModel):
name: str = Field(..., description='Name of this world info folder.')
uid: conint(ge=-2147483648, le=2147483647) = Field(
..., description='32-bit signed integer unique to this world info folder.'
)
class WorldInfoFolderUIDs(BaseModel):
entries: List[conint(ge=-2147483648, le=2147483647)]
uid: conint(ge=-2147483648, le=2147483647) = Field(
..., description='32-bit signed integer unique to this world info folder.'
)
class WorldInfoFolders(BaseModel):
folders: List[WorldInfoFolderBasic]
class WorldInfoFoldersUIDs(BaseModel):
folders: List[conint(ge=-2147483648, le=2147483647)]
class WorldInfoUIDs(BaseModel):
entries: List[conint(ge=-2147483648, le=2147483647)]
folders: List[WorldInfoFolderUIDs]
class BasicResult(BaseModel):
result: BasicResultInner
class GenerationOutput(BaseModel):
results: List[GenerationResult] = Field(
..., description='Array of generated outputs.'
)
class Story(BaseModel):
results: List[StoryChunk] = Field(
...,
description='Array of story actions. The array is sorted such that actions closer to the end of this array are closer to the end of the story.',
)
class WorldInfo(BaseModel):
entries: List[WorldInfoEntry]
folders: List[WorldInfoFolder]
class WorldInfoEntries(BaseModel):
entries: List[WorldInfoEntry]