diff --git a/.gitignore b/.gitignore index c69a32c..dcf30d6 100644 --- a/.gitignore +++ b/.gitignore @@ -136,7 +136,6 @@ dist # vuepress v2.x temp and cache directory .temp -.cache # Docusaurus cache and generated files diff --git a/examples/beginner-chat.ts b/examples/beginner-chat.ts index 1a6ff56..96f6deb 100644 --- a/examples/beginner-chat.ts +++ b/examples/beginner-chat.ts @@ -25,8 +25,7 @@ export const aibitat = new AIbitat({ 'https://raw.githubusercontent.com/wladiston/aibitat/main/README.md', ) const html = await response.text() - const text = cheerio.load(html).text() - return text + return cheerio.load(html).text() }, }) .agent(Agent.HUMAN, { diff --git a/src/cli.ts b/src/cli.ts index 23bc64c..25857fb 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -59,12 +59,12 @@ const aibitat = new AIbitat() } if (typeof Bun !== 'undefined') { - Bun.write(filename, code) + await Bun.write(filename, code) return `File ${filename} created and can be executed with "bun ${filename}"` } const fs = await import('fs') - await fs.writeFile(filename, code, () => {}) + fs.writeFile(filename, code, () => {}) return `File ${filename} created and can be executed with "node ${filename}"` }, }) diff --git a/src/index.test.ts b/src/index.test.ts index 1b68d3b..5bbd016 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -3,7 +3,7 @@ import OpenAI from 'openai' import {RetryError} from './error.ts' import {AIbitat} from './index.ts' -import type {Provider} from './providers/index.ts' +import type {Provider} from './providers' // HACK: Mock the AI provider. // This is still needed because Bun doesn't support mocking modules yet. diff --git a/src/index.ts b/src/index.ts index 1872c95..0443d88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,7 @@ export type ChannelConfig = ProviderConfig & { role?: string /** - * The maximum number of rounds a agent can chat with the channel + * The maximum number of rounds an agent can chat with the channel * @default 10 */ maxRounds?: number @@ -307,7 +307,7 @@ export class AIbitat { /** * Interruption the chat. * - * @param chat The nodes that participated in the interruption. + * @param route The nodes that participated in the interruption. * @returns */ private interrupt(route: Route) { @@ -379,7 +379,8 @@ export class AIbitat { * Register an error in the chat history. * This will trigger the `onError` event. * - * @param message + * @param route + * @param error */ private newError(route: Route, error: unknown) { const chat = { @@ -426,7 +427,7 @@ export class AIbitat { /** * Recursively chat between two nodes. * - * @param chat The nodes that are going to participate in the chat. + * @param route * @param keepAlive Whether to keep the chat alive. */ private async chat(route: Route, keepAlive = true) { @@ -550,7 +551,7 @@ export class AIbitat { node => !this.hasReachedMaximumRounds(channel, node), ) - // remove the last node that chatted with the channel so it doesn't chat again + // remove the last node that chatted with the channel, so it doesn't chat again const lastChat = this._chats.filter(c => c.to === channel).at(-1) if (lastChat) { const index = availableNodes.indexOf(lastChat.from) diff --git a/src/plugins/cli.ts b/src/plugins/cli.ts index 1991acd..2f9c297 100644 --- a/src/plugins/cli.ts +++ b/src/plugins/cli.ts @@ -23,9 +23,8 @@ function cli({ setup(aibitat) { let printing: Promise[] = [] - aibitat.onError(error => { + aibitat.onError(async error => { console.error(chalk.red(` error: ${(error as Error).message}`)) - if (error instanceof RetryError) { console.error(chalk.red(` retrying in 60 seconds...`)) setTimeout(() => { diff --git a/src/plugins/web-browsing.ts b/src/plugins/web-browsing.ts index ff7bd5d..27ca2e9 100644 --- a/src/plugins/web-browsing.ts +++ b/src/plugins/web-browsing.ts @@ -12,6 +12,7 @@ import type {AIbitat} from '..' * **Requires an SERPER_API_KEY environment variable**. * * @param query + * @param options * @returns */ async function search( diff --git a/src/providers/ai-provider.ts b/src/providers/ai-provider.ts index 7551ab6..d21c491 100644 --- a/src/providers/ai-provider.ts +++ b/src/providers/ai-provider.ts @@ -4,9 +4,9 @@ import type {AIbitat} from '..' * A service that provides an AI client to create a completion. */ export abstract class Provider { - private _client: T + private readonly _client: T - constructor(client: T) { + protected constructor(client: T) { this._client = client } @@ -23,6 +23,7 @@ export abstract class Provider { * * @throws known treated errors from `src/error.ts`. * @param messages A list of messages to send. + * @param functions */ abstract complete( messages: Provider.Message[], diff --git a/src/providers/anthropic.ts b/src/providers/anthropic.ts index f21ee9d..bcd0ab8 100644 --- a/src/providers/anthropic.ts +++ b/src/providers/anthropic.ts @@ -52,6 +52,7 @@ export class AnthropicProvider extends Provider { * Create a completion based on the received messages. * * @param messages A list of messages to send to the Anthropic API. + * @param functions * @returns The completion. */ async complete( diff --git a/src/providers/openai.ts b/src/providers/openai.ts index 8279e3c..07dd0d6 100644 --- a/src/providers/openai.ts +++ b/src/providers/openai.ts @@ -70,6 +70,7 @@ export class OpenAIProvider extends Provider { * Create a completion based on the received messages. * * @param messages A list of messages to send to the OpenAI API. + * @param functions * @returns The completion. */ async complete( @@ -84,7 +85,7 @@ export class OpenAIProvider extends Provider { functions, }) - // Right now, we only support one completion + // Right now, we only support one completion, // so we just take the first one in the list const completion = response.choices[0].message const cost = this.getCost(response.usage) @@ -139,7 +140,7 @@ export class OpenAIProvider extends Provider { /** * Get the cost of the completion. * - * @param completion The completion to get the cost for. + * @param usage The completion to get the cost for. * @returns The cost of the completion. */ getCost(usage: OpenAI.Completions.CompletionUsage | undefined) {