mirror of
https://github.com/Mintplex-Labs/abitat.git
synced 2026-07-01 10:05:27 -04:00
Just some cleanup to get familiar with the Repo
This commit is contained in:
@@ -136,7 +136,6 @@ dist
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
|
||||
@@ -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, {
|
||||
|
||||
+2
-2
@@ -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}"`
|
||||
},
|
||||
})
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+6
-5
@@ -64,7 +64,7 @@ export type ChannelConfig<T extends Provider = 'openai'> = ProviderConfig<T> & {
|
||||
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<T extends Provider> {
|
||||
/**
|
||||
* 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<T extends Provider> {
|
||||
* 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<T extends Provider> {
|
||||
/**
|
||||
* 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<T extends Provider> {
|
||||
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)
|
||||
|
||||
+1
-2
@@ -23,9 +23,8 @@ function cli({
|
||||
setup(aibitat) {
|
||||
let printing: Promise<void>[] = []
|
||||
|
||||
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(() => {
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {AIbitat} from '..'
|
||||
* **Requires an SERPER_API_KEY environment variable**.
|
||||
*
|
||||
* @param query
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
async function search(
|
||||
|
||||
@@ -4,9 +4,9 @@ import type {AIbitat} from '..'
|
||||
* A service that provides an AI client to create a completion.
|
||||
*/
|
||||
export abstract class Provider<T> {
|
||||
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<T> {
|
||||
*
|
||||
* @throws known treated errors from `src/error.ts`.
|
||||
* @param messages A list of messages to send.
|
||||
* @param functions
|
||||
*/
|
||||
abstract complete(
|
||||
messages: Provider.Message[],
|
||||
|
||||
@@ -52,6 +52,7 @@ export class AnthropicProvider extends Provider<Anthropic> {
|
||||
* 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(
|
||||
|
||||
@@ -70,6 +70,7 @@ export class OpenAIProvider extends Provider<OpenAI> {
|
||||
* 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<OpenAI> {
|
||||
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<OpenAI> {
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
Reference in New Issue
Block a user