-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
573 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
pull_request: | ||
branches: [main] | ||
types: [opened, synchronize, reopened, labeled, unlabeled] | ||
|
||
jobs: | ||
build: | ||
uses: cordiverse/workflows/.github/workflows/build.yml@main | ||
with: | ||
lint: true | ||
test: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish: | ||
uses: cordiverse/workflows/.github/workflows/publish.yml@main | ||
secrets: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ yarn-error.log | |
tsconfig.tsbuildinfo | ||
package-lock.json | ||
yarn.lock | ||
package.tgz | ||
|
||
.eslintcache | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,36 @@ | ||
{ | ||
"name": "koishi-plugin-yesimbot", | ||
"description": "Yes! I'm Bot! 机械壳,人类心", | ||
"version": "2.0.0", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"name": "@root/yesimbot", | ||
"version": "0.0.0", | ||
"private": true, | ||
"homepage": "https://github.com/HydroGest/YesImBot", | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"resources" | ||
], | ||
"contributors": [ | ||
"HydroGest <[email protected]>", | ||
"Dispure <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "jest", | ||
"generate": "ts-node scripts/generateSchema.ts" | ||
}, | ||
"keywords": [ | ||
"chatbot", | ||
"koishi", | ||
"plugin", | ||
"ai" | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/HydroGest/YesImBot.git" | ||
}, | ||
"dependencies": { | ||
"async-mutex": "^0.5.0", | ||
"axios": "^1.7.9", | ||
"sharp": "^0.33.5" | ||
}, | ||
"peerDependencies": { | ||
"koishi": "^4.18.5" | ||
"scripts": { | ||
"clean": "yakumo clean", | ||
"build": "yakumo build", | ||
"bump": "yakumo version", | ||
"dep": "yakumo upgrade", | ||
"pub": "yakumo publish", | ||
"lint": "eslint --ext .ts --ext .tsx . && prettier --check .", | ||
"lint:fix": "eslint --ext .ts --ext .tsx . --fix && prettier --write .", | ||
"format": "prettier --write .", | ||
"test": "yakumo mocha -r esbuild-register -r yml-register", | ||
"test:text": "shx rm -rf coverage && c8 -r text yarn test", | ||
"test:json": "shx rm -rf coverage && c8 -r json yarn test", | ||
"test:html": "shx rm -rf coverage && c8 -r html yarn test" | ||
}, | ||
"prettier": "@hamster-bot/prettier-config", | ||
"devDependencies": { | ||
"@koishijs/plugin-mock": "^2.6.6" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"default": "./lib/index.js" | ||
}, | ||
"./package.json": "./package.json", | ||
"./adapters": { | ||
"types": "./lib/adapters/index.d.ts", | ||
"default": "./lib/adapters/index.js" | ||
}, | ||
"./embeddings": { | ||
"types": "./lib/embeddings/index.d.ts", | ||
"default": "./lib/embeddings/index.js" | ||
}, | ||
"./managers": { | ||
"types": "./lib/managers/index.d.ts", | ||
"default": "./lib/managers/index.js" | ||
}, | ||
"./utils": { | ||
"types": "./lib/utils/index.d.ts", | ||
"default": "./lib/utils/index.js" | ||
} | ||
}, | ||
"koishi": { | ||
"description": { | ||
"zh": "让语言大模型机器人假装群友并和群友聊天!", | ||
"en": "A Koishi plugin that allows LLM chat in your guild." | ||
}, | ||
"browser": true, | ||
"service": { | ||
"required": [ | ||
"axios", | ||
"database" | ||
], | ||
"optional": [ | ||
"memory" | ||
], | ||
"implements": [ | ||
"yesimbot" | ||
] | ||
} | ||
"typescript": "^5.7.2", | ||
"yakumo": "^1.0.0-beta.20", | ||
"yakumo-esbuild": "^1.0.0-beta.7", | ||
"yakumo-tsc": "^1.0.0-beta.5", | ||
"yml-register": "^1.2.5" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"name": "koishi-plugin-yesimbot", | ||
"description": "Yes! I'm Bot! 机械壳,人类心", | ||
"version": "2.0.0", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"homepage": "https://github.com/HydroGest/YesImBot", | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"resources" | ||
], | ||
"contributors": [ | ||
"HydroGest <[email protected]>", | ||
"Dispure <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"keywords": [ | ||
"chatbot", | ||
"koishi", | ||
"plugin", | ||
"ai" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/HydroGest/YesImBot.git", | ||
"directory": "packages/core" | ||
}, | ||
"dependencies": { | ||
"async-mutex": "^0.5.0", | ||
"axios": "^1.7.9", | ||
"sharp": "^0.33.5" | ||
}, | ||
"peerDependencies": { | ||
"koishi": "^4.18.5" | ||
}, | ||
"devDependencies": { | ||
"@koishijs/plugin-mock": "^2.6.6" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"default": "./lib/index.js" | ||
}, | ||
"./package.json": "./package.json", | ||
"./adapters": { | ||
"types": "./lib/adapters/index.d.ts", | ||
"default": "./lib/adapters/index.js" | ||
}, | ||
"./embeddings": { | ||
"types": "./lib/embeddings/index.d.ts", | ||
"default": "./lib/embeddings/index.js" | ||
}, | ||
"./managers": { | ||
"types": "./lib/managers/index.d.ts", | ||
"default": "./lib/managers/index.js" | ||
}, | ||
"./utils": { | ||
"types": "./lib/utils/index.d.ts", | ||
"default": "./lib/utils/index.js" | ||
} | ||
}, | ||
"koishi": { | ||
"description": { | ||
"zh": "让语言大模型机器人假装群友并和群友聊天!", | ||
"en": "A Koishi plugin that allows LLM chat in your guild." | ||
}, | ||
"browser": true, | ||
"service": { | ||
"required": [ | ||
"axios", | ||
"database" | ||
], | ||
"optional": [ | ||
"memory" | ||
], | ||
"implements": [ | ||
"yesimbot" | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"emitDeclarationOnly": false, | ||
"moduleResolution": "node", | ||
"module": "CommonJS", | ||
"experimentalDecorators": true | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import fs from "fs"; | ||
import { Context } from "koishi"; | ||
|
||
|
||
export abstract class ExtFunction { | ||
readonly name: string; | ||
readonly description: string; | ||
readonly params: { [key: string]: SchemaNode }; | ||
|
||
constructor( | ||
protected readonly ctx: Context, | ||
protected readonly bot: Bot | ||
) { | ||
// 读取类的静态属性来初始化实例属性 | ||
const funcName = (this.constructor as any)["funcName"]; | ||
const description = (this.constructor as any)["description"]; | ||
const params = (this.constructor as any)["params"]; | ||
|
||
// 返回一个函数实例,使得类实例可以调用 | ||
const callable = (keyword: string) => this.apply(keyword); | ||
Object.defineProperty(callable, "name", { value: funcName }); | ||
Object.defineProperty(callable, "description", { value: description }); | ||
Object.defineProperty(callable, "params", { value: params }); | ||
return callable as any; | ||
} | ||
|
||
abstract apply(...args: any[]): any; | ||
|
||
get session() { | ||
return this.bot.session; | ||
} | ||
} | ||
|
||
export function getExtensions(ctx: Context, bot: Bot): ExtFunction[] { | ||
let extensions: ExtFunction[] = []; | ||
|
||
fs.readdirSync(__dirname) | ||
.filter((file) => file.startsWith("ext_")) | ||
.forEach((file) => { | ||
try { | ||
const extension = require(`./${file}`); | ||
for (const key in extension) { | ||
extensions.push(new extension[key](ctx, bot)); | ||
} | ||
logger.info(`Loaded extension: ${file}`); | ||
} catch (e) { | ||
logger.error(`Failed to load extension: ${file}`, e); | ||
} | ||
}); | ||
return extensions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function Name(funcName: string) { | ||
return function (target: Function) { | ||
target["funcName"] = funcName; | ||
}; | ||
} | ||
|
||
export function Description(description: string) { | ||
return function (target: Function) { | ||
target["description"] = description; | ||
}; | ||
} | ||
|
||
|
||
export function Param(param: string, schema: string | SchemaNode) { | ||
return function (target: Function) { | ||
if (!target["params"]) { | ||
target["params"] = {}; | ||
} | ||
if (typeof schema === "string") { | ||
schema = SchemaNode.String(schema); | ||
} | ||
target["params"][param] = schema; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Context, Service } from "koishi"; | ||
declare module "koishi" { | ||
interface Context { | ||
extension: Extension | ||
} | ||
} | ||
|
||
class Extension extends Service { | ||
constructor(ctx: Context) { | ||
super(ctx, "extension"); | ||
} | ||
|
||
apply(extName: string, ...args: any) {} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* 生成工具模板 | ||
* | ||
* https://platform.openai.com/docs/guides/function-calling | ||
* https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion | ||
* @param ext | ||
* @returns | ||
*/ | ||
export function getToolSchema(ext: Extension): ToolSchema { | ||
return { | ||
type: "function", | ||
function: { | ||
name: ext.name, | ||
description: ext.description, | ||
parameters: { | ||
type: "object", | ||
properties: ext.params, | ||
// 如果有默认值则非必填 | ||
required: Object.entries(ext.params).map(([key, value]) => value.default ? null : key).filter(Boolean), | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* 以文本形式给出的工具模板 | ||
* @param ext | ||
*/ | ||
export function getFunctionPrompt(ext: Extension): string { | ||
let lines = []; | ||
lines.push(`${ext.name}:`); | ||
lines.push(` description: ${ext.description}`); | ||
lines.push(` params:`); | ||
Object.entries(ext.params).forEach(([key, value]) => { | ||
lines.push(` ${key}: ${value.description}`); | ||
}) | ||
return lines.join("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"emitDeclarationOnly": false | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
} |
Oops, something went wrong.