chore: adjust eslint rules

old-agentic-v1^2
Travis Fischer 2023-06-10 17:50:52 -07:00
rodzic eba1060ba5
commit ddcbe1f7f3
7 zmienionych plików z 27 dodań i 2 usunięć

Wyświetl plik

@ -22,7 +22,12 @@
"no-useless-catch": "warn", "no-useless-catch": "warn",
"@typescript-eslint/no-extra-semi": "off", "@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off" "@typescript-eslint/no-explicit-any": "off",
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": ["block", "block-like"], "next": "*" },
{ "blankLine": "always", "prev": "*", "next": ["block", "block-like"] }
]
}, },
"overrides": [ "overrides": [
{ {

Wyświetl plik

@ -109,6 +109,7 @@ export abstract class BaseLLM<
} }
const tokenizer = await this._tokenizerP const tokenizer = await this._tokenizerP
if (tokenizer) { if (tokenizer) {
return tokenizer.encode(text).length return tokenizer.encode(text).length
} }
@ -255,6 +256,7 @@ export abstract class BaseChatModel<
} }
const booleanOutput = booleanOutputs[output] const booleanOutput = booleanOutputs[output]
if (booleanOutput !== undefined) { if (booleanOutput !== undefined) {
output = booleanOutput output = booleanOutput
} else { } else {

Wyświetl plik

@ -26,6 +26,7 @@ type SeverityType = (typeof Severity)[keyof typeof Severity]
* Define minimum LOG_LEVEL, defaulting to Severity.INFO if not provided or if an invalid value is provided. Any events below that level won't be logged to the console. * Define minimum LOG_LEVEL, defaulting to Severity.INFO if not provided or if an invalid value is provided. Any events below that level won't be logged to the console.
*/ */
let LOG_LEVEL: SeverityType = Severity.INFO let LOG_LEVEL: SeverityType = Severity.INFO
if ( if (
process.env.DEBUG_LOG_LEVEL && process.env.DEBUG_LOG_LEVEL &&
Severity[process.env.DEBUG_LOG_LEVEL.toUpperCase()] !== undefined Severity[process.env.DEBUG_LOG_LEVEL.toUpperCase()] !== undefined

Wyświetl plik

@ -32,6 +32,7 @@ export class NovuClient {
if (!apiKey) { if (!apiKey) {
throw new Error(`Error NovuClient missing required "apiKey"`) throw new Error(`Error NovuClient missing required "apiKey"`)
} }
this.apiKey = apiKey this.apiKey = apiKey
this.baseUrl = baseUrl this.baseUrl = baseUrl
} }

Wyświetl plik

@ -148,11 +148,13 @@ export class TwilioConversationClient {
`Error TwilioConversationClient missing required "accountSid" and/or "authToken"` `Error TwilioConversationClient missing required "accountSid" and/or "authToken"`
) )
} }
if (!phoneNumber) { if (!phoneNumber) {
throw new Error( throw new Error(
`Error TwilioConversationClient missing required "phoneNumber"` `Error TwilioConversationClient missing required "phoneNumber"`
) )
} }
this.phoneNumber = phoneNumber this.phoneNumber = phoneNumber
this.api = ky.create({ this.api = ky.create({
prefixUrl: baseUrl, prefixUrl: baseUrl,
@ -262,36 +264,45 @@ export class TwilioConversationClient {
const { sid: conversationSid } = await this.createConversation(name) const { sid: conversationSid } = await this.createConversation(name)
await this.addParticipant({ conversationSid, recipientPhoneNumber }) await this.addParticipant({ conversationSid, recipientPhoneNumber })
await this.sendMessage({ conversationSid, text }) await this.sendMessage({ conversationSid, text })
const start = Date.now() const start = Date.now()
let nUserMessages = 0 let nUserMessages = 0
do { do {
if (aborted) { if (aborted) {
await this.deleteConversation(conversationSid) await this.deleteConversation(conversationSid)
const reason = stopSignal?.reason || 'Aborted waiting for reply' const reason = stopSignal?.reason || 'Aborted waiting for reply'
if (reason instanceof Error) { if (reason instanceof Error) {
throw reason throw reason
} else { } else {
throw new Error(reason) throw new Error(reason)
} }
} }
const response = await this.fetchMessages(conversationSid) const response = await this.fetchMessages(conversationSid)
if (response.messages.length > 1) { if (response.messages.length > 1) {
const candidates = response.messages.filter( const candidates = response.messages.filter(
(message) => message.author !== BOT_NAME (message) => message.author !== BOT_NAME
) )
const candidate = candidates[candidates.length - 1] const candidate = candidates[candidates.length - 1]
if (validate(candidate)) { if (validate(candidate)) {
await this.deleteConversation(conversationSid) await this.deleteConversation(conversationSid)
return candidate return candidate
} }
if (nUserMessages !== candidates.length) { if (nUserMessages !== candidates.length) {
await this.sendMessage({ await this.sendMessage({
text: `Invalid response: ${candidate.body}. Please try again with a valid response format.`, text: `Invalid response: ${candidate.body}. Please try again with a valid response format.`,
conversationSid conversationSid
}) })
} }
nUserMessages = candidates.length nUserMessages = candidates.length
} }
await sleep(intervalMs) await sleep(intervalMs)
} while (Date.now() - start < timeoutMs) } while (Date.now() - start < timeoutMs)

1
test/_utils.ts vendored
Wyświetl plik

@ -27,6 +27,7 @@ const keyv = new Keyv({ store: keyvRedis, namespace: 'agentic-test' })
// TODO: this is a lil hacky // TODO: this is a lil hacky
const keyvHas = (keyv.has as any).bind(keyv) const keyvHas = (keyv.has as any).bind(keyv)
keyv.has = async (key, ...rest) => { keyv.has = async (key, ...rest) => {
if (refreshTestCache) { if (refreshTestCache) {
return undefined return undefined

Wyświetl plik

@ -8,6 +8,7 @@ test('TwilioConversationClient.createConversation', async (t) => {
if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) {
return t.pass() return t.pass()
} }
const client = new TwilioConversationClient() const client = new TwilioConversationClient()
const friendlyName = 'create-conversation-test' const friendlyName = 'create-conversation-test'
@ -25,6 +26,7 @@ test('TwilioConversationClient.addParticipant', async (t) => {
) { ) {
return t.pass() return t.pass()
} }
const client = new TwilioConversationClient() const client = new TwilioConversationClient()
const { sid: conversationSid } = await client.createConversation( const { sid: conversationSid } = await client.createConversation(
@ -43,6 +45,7 @@ test('TwilioConversationClient.sendMessage', async (t) => {
if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) {
return t.pass() return t.pass()
} }
const client = new TwilioConversationClient() const client = new TwilioConversationClient()
const text = 'Hello, world!' const text = 'Hello, world!'
@ -59,6 +62,7 @@ test('TwilioConversationClient.fetchMessages', async (t) => {
if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) {
return t.pass() return t.pass()
} }
const client = new TwilioConversationClient() const client = new TwilioConversationClient()
const { sid: conversationSid } = await client.createConversation( const { sid: conversationSid } = await client.createConversation(