Skip to content

Commit

Permalink
Version 1.3.1 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 authored Jul 18, 2024
2 parents ff32ea7 + 1ec47da commit 13119cb
Show file tree
Hide file tree
Showing 31 changed files with 568 additions and 202 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## v1.3.1

[compare changes](https://github.com/zAlweNy26/ts-cat/compare/v1.3.0...v1.3.1)

### 🚀 Enhancements

- Improve HTTP errors ([9205a66](https://github.com/zAlweNy26/ts-cat/commit/9205a66))
- Add `afterSendMessage` hook ([7d54491](https://github.com/zAlweNy26/ts-cat/commit/7d54491))
- Add batch files uploading endpoint ([e5f6074](https://github.com/zAlweNy26/ts-cat/commit/e5f6074))
- Add models interactions and update hooks ([4f73bc0](https://github.com/zAlweNy26/ts-cat/commit/4f73bc0))

### 🩹 Fixes

- Update deps, docker compose and some fixes ([c61cd24](https://github.com/zAlweNy26/ts-cat/commit/c61cd24))

### 🌊 Types

- Fix typechecks ([f188791](https://github.com/zAlweNy26/ts-cat/commit/f188791))

### 🏡 Chore

- Export AgentManager and VectorMemory ([4d2b0bd](https://github.com/zAlweNy26/ts-cat/commit/4d2b0bd))

### ❤️ Contributors

- Dany <[email protected]>

## v1.3.0

[compare changes](https://github.com/zAlweNy26/ts-cat/compare/v1.2.6...v1.3.0)
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM oven/bun:1 as base
FROM oven/bun:1 AS base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
COPY /patches/ /temp/dev/patches/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
COPY /patches/ /temp/prod/patches/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
Expand All @@ -20,7 +22,6 @@ COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENV NODE_ENV=production
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ services:
- ${CORE_PORT:-1865}:80
volumes:
- ./:/app
command: pnpm dev
command: bun run start
restart: unless-stopped
ccat-ts-vector-memory:
image: qdrant/qdrant:v1.8.2
image: qdrant/qdrant:v1.10.0
container_name: ccat_ts_vector_memory
environment:
- QDRANT__LOG_LEVEL=INFO
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default antfu({
markdown: false, // TODO: Temporary fix until code blocks are correctly read
ignores: ['package.json', 'dist/', 'node_modules/', 'test/mocks/'],
rules: {
'unused-imports/no-unused-vars-ts': 'warn',
'unused-imports/no-unused-vars': 'warn',
'style/max-statements-per-line': 'off',
'regexp/no-unused-capturing-group': 'warn',
'regexp/optimal-quantifier-concatenation': 'warn',
Expand Down
39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts-cat",
"type": "module",
"version": "1.3.0",
"version": "1.3.1",
"private": true,
"description": "TypeScript version of the Cheshire Cat AI project",
"author": "zAlweNy26 & Contributors",
Expand Down Expand Up @@ -50,22 +50,22 @@
"@elysiajs/static": "^1.0.3",
"@elysiajs/stream": "^1.0.3",
"@elysiajs/swagger": "^1.0.5",
"@langchain/anthropic": "^0.2.3",
"@langchain/anthropic": "^0.2.6",
"@langchain/azure-openai": "^0.0.11",
"@langchain/cohere": "^0.1.0",
"@langchain/community": "^0.2.17",
"@langchain/core": "^0.2.13",
"@langchain/google-genai": "^0.0.21",
"@langchain/mistralai": "^0.0.25",
"@langchain/openai": "^0.2.1",
"@langchain/cohere": "^0.2.1",
"@langchain/community": "^0.2.19",
"@langchain/core": "^0.2.17",
"@langchain/google-genai": "^0.0.23",
"@langchain/mistralai": "^0.0.26",
"@langchain/openai": "^0.2.4",
"@mgcrea/pino-pretty-compact": "^1.3.0",
"@qdrant/js-client-rest": "^1.9.0",
"@qdrant/js-client-rest": "^1.10.0",
"callsites": "^4.2.0",
"cheerio": "1.0.0-rc.12",
"chokidar": "^3.6.0",
"consola": "^3.2.3",
"console-table-printer": "^2.12.1",
"croner": "8.0.2",
"croner": "8.1.0",
"d3-dsv": "^2.0.0",
"date-fns": "^3.6.0",
"defu": "^6.1.4",
Expand All @@ -77,39 +77,40 @@
"html-to-text": "^9.0.5",
"is-docker": "^3.0.0",
"js-tiktoken": "^1.0.12",
"langchain": "^0.2.8",
"langchain": "^0.2.10",
"lodash": "^4.17.21",
"logestic": "1.2.0",
"lowdb": "^7.0.1",
"mammoth": "^1.8.0",
"nodemon": "^3.1.0",
"ofetch": "^1.3.4",
"officeparser": "^4.1.1",
"pdf-parse": "^1.1.1",
"pkg-types": "^1.1.3",
"qs": "^6.12.2",
"qs": "^6.12.3",
"scule": "^1.3.0",
"turbowatch": "^2.29.4",
"uncrypto": "^0.1.3",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.1"
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.2",
"@antfu/eslint-config": "^2.23.0",
"@total-typescript/ts-reset": "^0.5.1",
"@types/bun": "^1.1.6",
"@types/lodash": "^4.17.6",
"@types/lodash": "^4.17.7",
"@types/nodemon": "^1.19.6",
"@types/qs": "^6.9.15",
"@types/ws": "^8.5.10",
"@vitest/ui": "^1.6.0",
"@types/ws": "^8.5.11",
"@vitest/ui": "^2.0.3",
"changelogen": "^0.5.5",
"eslint": "^8.57.0",
"magicast": "^0.3.4",
"nodemon": "^3.1.0",
"typescript": "^5.4.5",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
"vitest": "^2.0.3"
},
"patchedDependencies": {
"[email protected].8": "patches/[email protected].8.patch"
"[email protected].10": "patches/[email protected].10.patch"
}
}
4 changes: 2 additions & 2 deletions patches/[email protected] → patches/[email protected]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
diff --git a/dist/agents/index.d.ts b/dist/agents/index.d.ts
index f136611b5f08a3670edc3e6bda9fdb0878f9b0ee..fd85341804ac9f32f4dadc5e73dd6e7ff38e6d2c 100644
index f136611b5f08a3670edc3e6bda9fdb0878f9b0ee..58caf958f3397804764961a212614fcd03d5bb66 100644
--- a/dist/agents/index.d.ts
+++ b/dist/agents/index.d.ts
@@ -1,4 +1,4 @@
-export { Agent, type AgentArgs, BaseSingleActionAgent, BaseMultiActionAgent, RunnableAgent, LLMSingleActionAgent, type LLMSingleActionAgentInput, type OutputParserArgs, } from "./agent.js";
+export { Agent, type AgentArgs, BaseSingleActionAgent, BaseMultiActionAgent, RunnableAgent, LLMSingleActionAgent, type LLMSingleActionAgentInput, type OutputParserArgs, AgentRunnableSequence } from "./agent.js";
+export { Agent, type AgentArgs, BaseSingleActionAgent, BaseMultiActionAgent, RunnableAgent, LLMSingleActionAgent, AgentRunnableSequence, type LLMSingleActionAgentInput, type OutputParserArgs, } from "./agent.js";
export { JsonToolkit, OpenApiToolkit, RequestsToolkit, type VectorStoreInfo, VectorStoreRouterToolkit, VectorStoreToolkit, createJsonAgent, createOpenApiAgent, createVectorStoreAgent, createVectorStoreRouterAgent, } from "./toolkits/index.js";
export { Toolkit } from "./toolkits/base.js";
export { ChatAgent, type ChatAgentInput, type ChatCreatePromptArgs, } from "./chat/index.js";
Expand Down
91 changes: 55 additions & 36 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Elysia, t } from 'elysia'
import { Elysia, t } from 'elysia'
import { HttpError } from './errors'
import { parsedEnv } from './utils'
import { log } from './logger'

export const swaggerTags = {
status: {
Expand Down Expand Up @@ -33,22 +33,13 @@ export const swaggerTags = {
},
} as const

export class UnauthorizedError extends Error {
code = 'UNAUTHORIZED'
status = 401

constructor(message?: string) {
super(message ?? 'UNAUTHORIZED')
}
}

const jsonLiterals = t.Union([t.String(), t.Number(), t.Boolean(), t.Null()])

export function authMiddleware(app: Elysia) {
return app.onBeforeHandle(({ headers }) => {
const apiKey = headers.token, realKey = parsedEnv.apiKey
if (realKey && realKey !== apiKey)
throw new UnauthorizedError('Invalid API key')
throw HttpError.Unauthorized('Invalid API key')
})
}

Expand All @@ -59,7 +50,17 @@ export const modelInfo = t.Object({
link: t.Optional(t.String({ format: 'uri' })),
schema: t.Record(t.String(), t.Any()),
value: t.Record(t.String(), t.Any()),
}, { $id: 'modelInfo' })
}, {
$id: 'modelInfo',
examples: [{
name: 'OpenAILLM',
humanReadableName: 'OpenAI GPT',
description: 'More expensive but also more flexible model than ChatGPT',
link: 'https://platform.openai.com/docs/models/overview',
schema: {},
value: {},
}],
})

export const pluginManifest = t.Object({
name: t.String(),
Expand All @@ -70,7 +71,18 @@ export const pluginManifest = t.Object({
pluginUrl: t.Optional(t.String({ format: 'uri' })),
thumb: t.Optional(t.String({ format: 'uri' })),
tags: t.Array(t.String(), { default: ['miscellaneous', 'unknown'] }),
}, { $id: 'pluginManifest' })
}, {
$id: 'pluginManifest',
examples: [{
name: 'Core CCat',
description: 'The core Cat plugin used to define default hooks and tools. You don\'t see this plugin in the plugins folder, because it is an hidden plugin. It will be used to try out hooks and tools before they become available to other plugins. Written and delivered just for you, my furry friend.',
author_name: 'Cheshire Cat',
authorUrl: 'https://cheshirecat.ai',
pluginUrl: 'https://github.com/cheshire-cat-ai/core',
tags: ['core', 'cat', 'default', 'hidden'],
version: '0.0.1',
}],
})

export const pluginInfo = t.Object({
id: t.String(),
Expand All @@ -91,46 +103,53 @@ export const pluginInfo = t.Object({
name: t.String(),
priority: t.Number(),
})),
}, { $id: 'pluginInfo' })
}, {
$id: 'pluginInfo',
examples: [{
id: 'core_plugin',
active: true,
upgradable: false,
manifest: {},
forms: [],
tools: [],
hooks: [],
}],
})

export const pluginSettings = t.Object({
name: t.String(),
schema: t.Record(t.String(), t.Any()),
value: t.Record(t.String(), t.Any()),
}, { $id: 'pluginSettings' })
}, {
$id: 'pluginSettings',
examples: [{
name: 'Core CCat',
schema: {},
value: {},
}],
})

export function apiModels(app: Elysia) {
return app.onError(({ code, error }) => {
log.error(error)
return {
code,
message: error.message,
status: 'status' in error ? error.status : 400,
}
}).model({
error: t.Object({
code: t.String(),
message: t.String(),
status: t.Number(),
}, {
examples: [{
code: 'UNKNOWN',
message: 'The request was invalid.',
status: 400,
}],
export function apiModels() {
return new Elysia({ name: 'api-models' }).model({
generic: t.Record(t.String(), t.Any(), {
examples: [{ key: 'value' }],
$id: 'GenericObject',
}),
generic: t.Record(t.String(), t.Any(), { examples: [{ key: 'value' }] }),
json: t.Union([jsonLiterals, t.Array(jsonLiterals), t.Record(t.String(), jsonLiterals)], {
examples: [
{ key: 'value' },
['value'],
'example',
42,
],
$id: 'GenericJson',
}),
customSetting: t.Object({
name: t.String(),
value: t.Any(),
}, {
examples: [{ name: 'key', value: 'value' }],
$id: 'CustomSetting',
}),
modelInfo,
pluginManifest,
Expand Down
22 changes: 22 additions & 0 deletions src/dtos/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ export interface WorkingMemory {
[key: string]: MemoryDocument[]
}

export interface Interaction {
source: string
prompt: string
outputTokens: number
startedAt: number
endedAt: number
}

export type LLMInteraction = Interaction & {
model: 'llm'
inputTokens: number
reply: string
}

export type EmbedderInteraction = Interaction & {
model: 'embedder'
reply: number[]
}

export type ModelInteraction = LLMInteraction | EmbedderInteraction

/**
* The content of a memory message.
*/
Expand All @@ -53,6 +74,7 @@ export interface MemoryMessage {
input: string
intermediateSteps: IntermediateStep[]
memory?: WorkingMemory
interactions?: ModelInteraction[]
}
}

Expand Down
Loading

0 comments on commit 13119cb

Please sign in to comment.