41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { _decorator, Component, EditBox, Node } from "cc";
|
|
import { DemoManager } from "./DemoManager";
|
|
import { ChatGPTService } from "./ChatGPTService";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("ChatPanel")
|
|
export class ChatPanel extends Component {
|
|
manager: DemoManager = null;
|
|
|
|
@property(EditBox)
|
|
editBox: EditBox = null;
|
|
|
|
protected onEnable(): void {
|
|
if (!this.manager) this.manager = DemoManager.getInstance();
|
|
}
|
|
|
|
public async OnClickSend() {
|
|
const str = this.editBox.string;
|
|
if (!str || str == "") return;
|
|
console.log("post:" + str);
|
|
|
|
this.editBox.string = "";
|
|
DemoManager.getInstance().updateDialog(true, str);
|
|
|
|
let ret = await ChatGPTService.getInstance().Post({
|
|
model: "llama3.1:8b",
|
|
messages: [{ role: "user", content: str }],
|
|
temperature: 0.8,
|
|
});
|
|
|
|
const rep = ret.choices[0].message.content;
|
|
if (rep == null) {
|
|
console.warn("rep null");
|
|
}
|
|
if (this.manager) {
|
|
this.manager.updateDialog(false, rep);
|
|
}
|
|
console.log("ret:" + rep);
|
|
}
|
|
}
|