diff --git a/src/agent/index.test.ts b/src/agent/index.test.ts new file mode 100644 index 00000000..740e27de --- /dev/null +++ b/src/agent/index.test.ts @@ -0,0 +1,22 @@ +import '../config/env.test' +import type {LLMChatParams} from "./types"; +import {ENV} from "../config/env"; +import {loadChatLLM} from "./index"; + +{ + const agent = loadChatLLM({ + ...ENV.USER_CONFIG, + AI_PROVIDER: 'anthropic', + }) + const params: LLMChatParams = { + prompt: 'You are a useful assistant.', + message: 'What is your name?', + history: [] + } + console.log(agent?.name, agent?.model(ENV.USER_CONFIG)); + agent?.request(params, ENV.USER_CONFIG, async (text) => { + console.log(text); + }).then((res) => { + console.log(res); + }) +} diff --git a/src/config/env.test.ts b/src/config/env.test.ts new file mode 100644 index 00000000..71b7d12b --- /dev/null +++ b/src/config/env.test.ts @@ -0,0 +1,13 @@ +import { parse } from 'toml'; +import { readFileSync } from 'fs'; +import { ENV } from './env' + +{ + const toml = readFileSync('../../wrangler.toml', 'utf8'); + const config = parse(toml); + ENV.merge({ + ...config.vars, + DATABASE: {}, + }) + // console.log(JSON.stringify(ENV, null, 2)); +} diff --git a/src/plugins/interpolate_test.ts b/src/plugins/interpolate.test.ts similarity index 100% rename from src/plugins/interpolate_test.ts rename to src/plugins/interpolate.test.ts diff --git a/src/plugins/template.test.ts b/src/plugins/template.test.ts new file mode 100644 index 00000000..7e253621 --- /dev/null +++ b/src/plugins/template.test.ts @@ -0,0 +1,15 @@ +import * as fs from 'node:fs'; +import { executeRequest } from './template'; + +{ + const plugin = './plugins/dns.json'; + const template = JSON.parse(fs.readFileSync(plugin, 'utf8')); + executeRequest(template, { DATA: ['B', 'google.com'] }).then(console.log).catch(console.error); + executeRequest(template, { DATA: ['A', 'www.bilibili.com'] }).then(r => console.log(r.content)).catch(console.error); +} + +{ + const plugin = './plugins/dicten.json'; + const template = JSON.parse(fs.readFileSync(plugin, 'utf8')); + executeRequest(template, { DATA: 'example' }).then(console.log).catch(console.error); +} diff --git a/src/plugins/template_test.ts b/src/plugins/template_test.ts deleted file mode 100644 index fcfa8eb5..00000000 --- a/src/plugins/template_test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as fs from 'node:fs'; -import { executeRequest } from './template'; - -{ - const plugin = './plugins/dns.json'; - const template = JSON.parse(fs.readFileSync(plugin, 'utf8')); - // executeRequest(template, { DATA: ['B', 'google.com'] }).then(console.log).catch(console.error); - executeRequest(template, { DATA: ['A', 'www.bilibili.com'] }).then(r => console.log(r.content)).catch(console.error); -} - -// { -// const plugin = './plugins/dicten.json'; -// const template = JSON.parse(fs.readFileSync(plugin, 'utf8')); -// executeRequest(template, { DATA: 'example' }).then(console.log).catch(console.error); -// }