chore: 移除历史测试文件

This commit is contained in:
WJG 2024-08-26 21:33:54 +08:00
parent 5d455e2ffe
commit d14ce3bfaf
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
5 changed files with 0 additions and 277 deletions

View File

@ -1,51 +0,0 @@
import { MyBot } from "../src/services/bot";
import { AISpeaker } from "../src/services/speaker/ai";
export async function testMyBot() {
// await testStreamResponse();
await testRunBot();
}
async function testRunBot() {
const name = "傻妞";
const speaker = new AISpeaker({
name,
tts: "custom",
userId: process.env.MI_USER!,
password: process.env.MI_PASS!,
did: process.env.MI_DID,
});
const bot = new MyBot({
speaker,
bot: {
name,
profile: `性别女,性格乖巧可爱,喜欢搞怪,爱吃醋。`,
},
master: {
name: "陆小千",
profile: `性别男,善良正直,总是舍己为人,是傻妞的主人。`,
},
});
const res = await bot.run();
console.log("✅ done");
}
async function testStreamResponse() {
const stream = await MyBot.chatWithStreamResponse({
user: "地球为什么是圆的?",
onFinished: (text) => {
console.log("\nFinal result 111:\n", text);
},
});
const config: any = {
userId: process.env.MI_USER!,
password: process.env.MI_PASS!,
did: process.env.MI_DID,
tts: "custom",
};
const speaker = new AISpeaker(config);
await speaker.initMiServices();
await speaker.response({ stream });
const res = await stream.getFinalResult();
console.log("\nFinal result 222:\n", res);
}

View File

@ -1,58 +0,0 @@
import { assert } from "console";
import {
ConversationManager,
MessageContext,
} from "../src/services/bot/conversation";
import { println } from "../src/utils/base";
import { MessageCRUD } from "../src/services/db/message";
export async function testDB() {
const manager = new ConversationManager({
bot: {
name: "小爱同学",
profile: "我是小爱同学,机器人",
},
master: {
name: "陆小千",
profile: "我是陆小千,人类",
},
room: {
name: "客厅",
description: "陆小千的客厅,小爱同学放在角落里",
},
});
const { room, bot, master, memory } = await manager.get();
assert(room, "❌ 初始化用户失败");
const ctx = { bot, master, room } as MessageContext;
let message = await manager.onMessage(ctx, {
sender: master!,
text: "你好!",
});
assert(message?.text === "你好!", "❌ 插入消息失败");
message = await manager.onMessage(ctx, {
sender: bot!,
text: "你好!很高兴认识你",
});
await manager.onMessage(ctx, {
sender: master!,
text: "你是谁?",
});
await manager.onMessage(ctx, {
sender: bot!,
text: "我是小爱同学,你可以叫我小爱!",
});
const messages = await manager.getMessages({ take: 100 });
assert(messages.length === 4, "❌ 查询消息数量异常");
assert(messages[0].text === "你好!", "❌ 查询消息排序异常");
const newMessages = await MessageCRUD.gets({
take: 100,
cursorId: message!.id,
order: "asc",
});
assert(newMessages.length === 2, "❌ 查询消息数量异常(游标)");
assert(
newMessages[1].text === "我是小爱同学,你可以叫我小爱!",
"❌ 查询消息排序异常(游标)"
);
println("✅ hello world");
}

View File

@ -1,9 +0,0 @@
import { Logger } from "../src/utils/log";
export function testLog() {
Logger.log("你好", ["世界"], { hello: "world!" });
Logger.success("你好", ["世界"], { hello: "world!" });
Logger.error("你好", ["世界"], { hello: "world!" });
Logger.assert(true, "你好 111", ["世界"], { hello: "world!" });
Logger.assert(false, "你好 222", ["世界"], { hello: "world!" });
}

View File

@ -1,37 +0,0 @@
import { randomUUID } from "crypto";
import { openai } from "../src/services/openai";
export async function testOpenAI() {
await testChat();
// await testStreamChat();
}
async function testChat() {
const res = await openai.chat({ user: "地球为什么是圆的?" });
console.log("\nFinal result:\n", res?.content);
}
async function testStreamChat() {
const requestId = randomUUID();
const res = await openai.chatStream({
requestId,
user: "地球为什么是圆的?",
onStream: (text) => {
console.log(text);
},
});
console.log("\nFinal result:\n", res);
}
async function testAbortStreamChat() {
const requestId = randomUUID();
const res = await openai.chatStream({
requestId,
user: "hello!",
onStream: (text) => {
console.log(text);
openai.cancel(requestId);
},
});
console.log("xxx", res);
}

View File

@ -1,122 +0,0 @@
import { AISpeaker } from "../src/services/speaker/ai";
import { StreamResponse } from "../src/services/speaker/stream";
import { sleep } from "../src/utils/base";
export async function testSpeaker() {
const speaker = new AISpeaker({
userId: process.env.MI_USER!,
password: process.env.MI_PASS!,
did: process.env.MI_DID,
tts: "xiaoai",
debug: true,
});
await speaker.initMiServices();
await testTTS(speaker);
// await testAISpeakerStatus(speaker);
// await testSpeakerResponse(speaker);
// await testSpeakerStreamResponse(speaker);
// await testSpeakerGetMessages(speaker);
// await testSwitchSpeaker(speaker);
// await testSpeakerUnWakeUp(speaker);
// await testAISpeaker(speaker);
}
async function testTTS(speaker: AISpeaker) {
const res1 = await speaker.MiIOT!.doAction(5, 1, "你好,很高兴认识你");
const res2 = await speaker.MiNA!.play({ tts: "你好,很高兴认识你" });
console.log("finished");
}
async function testAISpeakerStatus(speaker: AISpeaker) {
const playingCommand = [5, 3, 1];
const res1 = await speaker.MiIOT!.getProperty(
playingCommand[0],
playingCommand[1]
);
const res2 = await speaker.MiNA!.getStatus();
console.log("finished");
}
async function testAISpeaker(speaker: AISpeaker) {
speaker.askAI = async (msg) => {
return { text: "你说:" + msg.text };
};
await speaker.run();
console.log("finished");
}
async function testSpeakerUnWakeUp(speaker: AISpeaker) {
await speaker.wakeUp();
await sleep(1000);
await speaker.unWakeUp();
console.log("hello");
}
async function testSwitchSpeaker(speaker: AISpeaker) {
await speaker.response({ text: "你好,我是傻妞,很高兴认识你!" });
const success = await speaker.switchSpeaker("魅力苏菲");
console.log("switchSpeaker 魅力苏菲", success);
await speaker.response({ text: "你好,我是傻妞,很高兴认识你!" });
console.log("hello");
}
async function testSpeakerGetMessages(speaker: AISpeaker) {
let msgs = await speaker.getMessages({ filterTTS: true });
console.log("filterTTS msgs", msgs);
msgs = await speaker.getMessages({ filterTTS: false });
console.log("no filterTTS msgs", msgs);
}
async function testSpeakerResponse(speaker: AISpeaker) {
let status = await speaker.MiNA!.getStatus();
console.log("curent status", status);
await speaker.response({ text: "你好,我是傻妞,很高兴认识你!" });
sleep(1000);
status = await speaker.MiNA!.getStatus();
console.log("tts status", status);
}
async function testSpeakerStreamResponse(speaker: AISpeaker) {
const stream = new StreamResponse();
const text = `
###
1. ****
2. ****
3. ****西
4. ****
5. ****
###
1. ****
2. **西**西
3. ****
4. ****
5. ****
`;
const add = async (text: string) => {
stream.addResponse(text);
await sleep(100);
};
setTimeout(async () => {
for (const s of text.split("")) {
await add(s);
}
stream.finish();
});
await speaker.response({ stream });
console.log("hello!");
}