54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { _decorator, Component, EditBox, Node,Label } from "cc";
|
|
import { DemoManager } from "./DemoManager";
|
|
import { ChatGPTService } from "./ChatGPTService";
|
|
import {characters} from "db://assets/Scripts/test/cfg/characters";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("ChatPanel")
|
|
export class ChatPanel extends Component {
|
|
manager: DemoManager = null;
|
|
|
|
@property(EditBox)
|
|
editBox: EditBox = null;
|
|
|
|
@property(Label)
|
|
girlName: Label = null;
|
|
|
|
id:number
|
|
refresh(id:number) {
|
|
this.id = id;
|
|
const data = characters[id-1];
|
|
this.girlName.string = data.name;
|
|
}
|
|
|
|
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: "Deepseek-reasoner",
|
|
messages: [{ role: "user", content: str }],
|
|
temperature: 0.8,
|
|
id: ChatGPTService.getInstance().GetId(),
|
|
});
|
|
console.log(ret);
|
|
|
|
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);
|
|
}
|
|
}
|