Skip to content

Commit

Permalink
test: 添加部分测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Aug 27, 2024
1 parent 33ae95a commit f9c1ddc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/agent/index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
})
}
13 changes: 13 additions & 0 deletions src/config/env.test.ts
Original file line number Diff line number Diff line change
@@ -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));
}
File renamed without changes.
15 changes: 15 additions & 0 deletions src/plugins/template.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 0 additions & 15 deletions src/plugins/template_test.ts

This file was deleted.

0 comments on commit f9c1ddc

Please sign in to comment.