Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions common/guidance/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ type OutboundJsonSchema<T extends JsonSchemaFormat> = T extends 'openai'
}
}
: T extends 'gemini'
? GeminiResponseSchema
: {
type: 'object'
properties: Record<string, any>
required: string[]
}
? GeminiResponseSchema
: {
type: 'object'
properties: Record<string, any>
required: string[]
}

export function getJsonSchemaPayload<T extends JsonSchemaFormat>(
json: JsonField[],
Expand Down
7 changes: 4 additions & 3 deletions common/horde-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export async function generateImage(
let key = user.hordeKey
? user.hordeKey
: user.userHordeKey
? decryptText(user.userHordeKey)
: HORDE_GUEST_KEY
? decryptText(user.userHordeKey)
: HORDE_GUEST_KEY

const image = await generate({
type: 'image',
Expand Down Expand Up @@ -295,7 +295,8 @@ function wait(secs: number) {

function decryptText(text: string) {
try {
const decipher = crypto.createDecipher(ALGO, HORDE_SEED)
const iv = Buffer.alloc(16, 0)
const decipher = crypto.createDecipheriv(ALGO, HORDE_SEED.slice(0, 32), iv)
const decrypted = decipher.update(text, 'hex', 'utf8') + decipher.final('utf8')
return decrypted
} catch (ex) {
Expand Down
4 changes: 2 additions & 2 deletions common/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export function getImageSettings(
chat?.imageSource === 'main-character' || chat?.imageSource === 'last-character'
? character?.imageSettings
: chat?.imageSource === 'chat'
? chat?.imageSettings
: user?.images
? chat?.imageSettings
: user?.images

if (!imageSettings) {
imageSettings = user?.images
Expand Down
4 changes: 2 additions & 2 deletions common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const transport =
typeof window !== 'undefined'
? { target: 'pino-pretty', options: { translateTime: `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` } }
: process.env.NODE_ENV !== 'production'
? { target: 'pino-pretty', options: { translateTime: `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` } }
: undefined
? { target: 'pino-pretty', options: { translateTime: `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` } }
: undefined

function getLogLevel() {
if (typeof window !== 'undefined') {
Expand Down
16 changes: 8 additions & 8 deletions common/mode-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ export const cyoaTemplate = (service: AIAdapter, model?: string) => {
const jailbreak = !INSTRUCT_SERVICES[service as AIAdapter]
? ''
: service !== 'openai'
? ''
: model === OPENAI_MODELS.Turbo0613 || model === OPENAI_MODELS.Turbo
? modernJailbreak
: originalJailbreak
? ''
: model === OPENAI_MODELS.Turbo0613 || model === OPENAI_MODELS.Turbo
? modernJailbreak
: originalJailbreak
return (
service === 'claude'
? claudeCyoa
: service === 'novel'
? novelCyoa
: service === 'agnaistic' || service === 'kobold' || service === 'ooba'
? alpacaCyoa
: typicalCyoa
? novelCyoa
: service === 'agnaistic' || service === 'kobold' || service === 'ooba'
? alpacaCyoa
: typicalCyoa
).replace(/{{jailbreak}}/gi, jailbreak || '')
}

Expand Down
4 changes: 2 additions & 2 deletions common/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export async function buildPromptPlaceholders(
persona: replace(
formatCharacter(
replyAs.name,
replyAs._id === char._id ? chat.overrides ?? replyAs.persona : replyAs.persona
replyAs._id === char._id ? (chat.overrides ?? replyAs.persona) : replyAs.persona
)
),
prefill: opts.settings?.prefill || '',
Expand Down Expand Up @@ -565,7 +565,7 @@ export async function buildPromptPlaceholders(

const sampleChat =
replyAs._id === char._id && !!chat.overrides
? chat.sampleChat ?? replyAs.sampleChat
? (chat.sampleChat ?? replyAs.sampleChat)
: replyAs.sampleChat

parts.sampleChat = (sampleChat || '')
Expand Down
4 changes: 2 additions & 2 deletions common/requests/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const DEBUG =
typeof window !== 'undefined'
? false
: typeof process !== 'undefined'
? process.env.LOG_LEVEL === 'debug' && !!process.env.LOG_CHUNKS
: false
? process.env.LOG_LEVEL === 'debug' && !!process.env.LOG_CHUNKS
: false

export const streamGenerator: CompletionGenerator = async function* (opts) {
const { signal, url, headers, body, format } = opts
Expand Down
8 changes: 4 additions & 4 deletions common/template-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export async function toChatMessages(req: GenerateRequestV2, counter: TokenCount
line.type !== 'history'
? 'user'
: req.history
? lineRole
: (unparsed || text || '').startsWith(sender)
? 'user'
: 'assistant'
? lineRole
: (unparsed || text || '').startsWith(sender)
? 'user'
: 'assistant'

const id = line.type === 'history' ? line.id : undefined
const attachments = getAttachments(req, id)
Expand Down
93 changes: 47 additions & 46 deletions common/valid/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export type FromTupleLiteral<T> = T extends [...string[], null] | readonly [...string[], null]
? Exclude<T[number], null> | undefined
: T extends [...string[]] | readonly [...string[]]
? T[number]
: never
? T[number]
: never

export type OptionalToPrimitive<T extends OptionalPrimitive> = T extends 'string?'
? string
: T extends 'number?'
? number
: T extends 'boolean?'
? boolean
: never
? number
: T extends 'boolean?'
? boolean
: never
export type OptionalPrimitive = 'string?' | 'number?' | 'boolean?' | 'any?' | 'unknown?'
export type Primitive = 'string' | 'number' | 'boolean' | 'any' | 'unknown'

Expand All @@ -34,26 +34,26 @@ export type Validator = { [key: string]: Reference } | { readonly [key: string]:
export type FromOptional<T extends OptionalPrimitive> = T extends 'string?'
? string | undefined
: T extends 'boolean?'
? boolean | undefined
: T extends 'number?'
? number | undefined
: T extends 'any?'
? any | undefined
: T extends 'unknown?'
? unknown | undefined
: never
? boolean | undefined
: T extends 'number?'
? number | undefined
: T extends 'any?'
? any | undefined
: T extends 'unknown?'
? unknown | undefined
: never

export type FromPrimitive<T extends Primitive> = T extends 'string'
? string
: T extends 'boolean'
? boolean
: T extends 'number'
? number
: T extends 'any'
? any
: T extends 'unknown'
? unknown
: never
? boolean
: T extends 'number'
? number
: T extends 'any'
? any
: T extends 'unknown'
? unknown
: never

export type FromTuple<T> = T extends
| [infer U]
Expand All @@ -80,32 +80,33 @@ export type FromTupleBody<T> = T extends [infer U, infer O]
: Array<UnwrapBody<U>>
: never
: T extends readonly [infer U]
? U extends Validator
? Array<UnwrapBody<U>>
? U extends Validator
? Array<UnwrapBody<U>>
: never
: never
: never

export type UnwrapBody<T extends Validator> = T extends OptionalValidator<T>
? UnwrapBody<Omit<T, '__optional__'>> | undefined
: {
-readonly [key in keyof T]: T[key] extends Primitive
? FromPrimitive<T[key]>
: T[key] extends OptionalPrimitive
? FromOptional<T[key]>
: T[key] extends [Primitive, '?'] | readonly [Primitive, '?']
? FromTuple<T[key]>
: T[key] extends [Primitive] | readonly [Primitive]
? FromTuple<T[key]>
: T[key] extends [OptionalPrimitive] | readonly [OptionalPrimitive]
? FromOptionalTuple<T[key]>
: T[key] extends [Validator, '?'] | readonly [Validator, '?']
? Array<UnwrapBody<T[key][0]>> | undefined
: T[key] extends [Validator] | readonly [Validator]
? FromTupleBody<T[key]>
: T[key] extends Validator
? UnwrapBody<T[key]>
: FromTupleLiteral<T[key]>
}
export type UnwrapBody<T extends Validator> =
T extends OptionalValidator<T>
? UnwrapBody<Omit<T, '__optional__'>> | undefined
: {
-readonly [key in keyof T]: T[key] extends Primitive
? FromPrimitive<T[key]>
: T[key] extends OptionalPrimitive
? FromOptional<T[key]>
: T[key] extends [Primitive, '?'] | readonly [Primitive, '?']
? FromTuple<T[key]>
: T[key] extends [Primitive] | readonly [Primitive]
? FromTuple<T[key]>
: T[key] extends [OptionalPrimitive] | readonly [OptionalPrimitive]
? FromOptionalTuple<T[key]>
: T[key] extends [Validator, '?'] | readonly [Validator, '?']
? Array<UnwrapBody<T[key][0]>> | undefined
: T[key] extends [Validator] | readonly [Validator]
? FromTupleBody<T[key]>
: T[key] extends Validator
? UnwrapBody<T[key]>
: FromTupleLiteral<T[key]>
}

type OptionalValidator<T extends Validator> = T & { __optional__: any }

Expand Down
5 changes: 4 additions & 1 deletion common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export class VersionController<T extends { _id: string }, U extends Array<keyof
current: Pick<T, U[number]>
changes: ObjectPatch<Pick<T, U[number]>>[] = []

constructor(public base: T, private keys: U) {
constructor(
public base: T,
private keys: U
) {
this.current = getBase(base, keys)
console.log(`[vers] ${inline(this.current)}`)
}
Expand Down
Loading