mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 05:46:16 +00:00
feat(apis/websocket): support training without label
This commit is contained in:
@@ -23,12 +23,12 @@ export const wit = {
|
||||
|
||||
if (!res.ok) throw new Error(`Failed to fetch from Wit.ai: ${res.statusText} (${res.status})`)
|
||||
|
||||
return await res.json()
|
||||
return (await res.json()) as WitMessageResponse
|
||||
},
|
||||
message(text: string) {
|
||||
return this.fetch(`/message?q=${encodeURIComponent(text)}&n=8`) as Promise<WitMessageResponse>
|
||||
},
|
||||
async train(text: string, label: string) {
|
||||
async train(text: string, label?: string) {
|
||||
await this.fetch('/utterances', {
|
||||
body: JSON.stringify([
|
||||
{
|
||||
@@ -41,7 +41,14 @@ export const wit = {
|
||||
method: 'POST',
|
||||
})
|
||||
},
|
||||
} as const
|
||||
} satisfies Wit
|
||||
|
||||
export interface Wit {
|
||||
token: string
|
||||
fetch(route: string, options?: RequestInit): Promise<WitMessageResponse>
|
||||
message(text: string): Promise<WitMessageResponse>
|
||||
train(text: string, label?: string): Promise<void>
|
||||
}
|
||||
|
||||
export interface WitMessageResponse {
|
||||
text: string
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ClientOperation, Logger } from '@revanced/bot-shared'
|
||||
import type { Worker as TesseractWorker } from 'tesseract.js'
|
||||
import type { ClientPacketObject } from '../classes/Client'
|
||||
import type { WitMessageResponse } from '../context'
|
||||
import type { Wit } from '../context'
|
||||
import type { Config } from '../utils/config'
|
||||
|
||||
export { default as parseImageEventHandler } from './parseImage'
|
||||
@@ -14,10 +14,7 @@ export type EventHandler<POp extends ClientOperation> = (
|
||||
) => void | Promise<void>
|
||||
|
||||
export type EventContext = {
|
||||
wit: {
|
||||
train(text: string, label: string): Promise<void>
|
||||
message(text: string): Promise<WitMessageResponse>
|
||||
}
|
||||
wit: Wit
|
||||
tesseract: TesseractWorker
|
||||
logger: Logger
|
||||
config: Config
|
||||
|
||||
@@ -10,7 +10,7 @@ const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = asy
|
||||
const nextSeq = client.currentSequence++
|
||||
const actualText = text.slice(0, 279)
|
||||
|
||||
logger.debug(`${client.id} requested to train label ${label} (${nextSeq}) with:`, actualText)
|
||||
logger.debug(`${client.id} requested to train label ${label ?? '<out of scope>'} (${nextSeq}) with:`, actualText)
|
||||
|
||||
try {
|
||||
await wit.train(actualText, label)
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import {
|
||||
type AnySchema,
|
||||
array,
|
||||
type BooleanSchema,
|
||||
boolean,
|
||||
custom,
|
||||
enum_,
|
||||
type InferOutput,
|
||||
type NullSchema,
|
||||
null_,
|
||||
type ObjectSchema,
|
||||
object,
|
||||
optional,
|
||||
parse,
|
||||
pipe,
|
||||
string,
|
||||
@@ -75,13 +72,9 @@ export const PacketDataSchemas = {
|
||||
}),
|
||||
[ClientOperation.TrainMessage]: object({
|
||||
text: string(),
|
||||
label: string(),
|
||||
label: optional(string()),
|
||||
}),
|
||||
} as const satisfies Record<
|
||||
Operation,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it
|
||||
ObjectSchema<any, any> | AnySchema | NullSchema<any> | BooleanSchema<any>
|
||||
>
|
||||
} as const
|
||||
|
||||
export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation
|
||||
? PacketWithSequenceNumber<TOp>
|
||||
|
||||
Reference in New Issue
Block a user