Files
18xchat/assets/Scripts/test/ChatPanel.ts
T

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-07-25 15:20:02 +08:00
import { _decorator, Component, EditBox, Node,Label } from "cc";
2025-07-22 16:43:10 +08:00
import { DemoManager } from "./DemoManager";
import { ChatGPTService } from "./ChatGPTService";
2025-07-25 15:20:02 +08:00
import {characters} from "db://assets/Scripts/test/cfg/characters";
2025-07-22 16:43:10 +08:00
const { ccclass, property } = _decorator;
@ccclass("ChatPanel")
export class ChatPanel extends Component {
manager: DemoManager = null;
@property(EditBox)
editBox: EditBox = null;
2025-07-25 15:20:02 +08:00
@property(Label)
girlName: Label = null;
id:number
refresh(id:number) {
this.id = id;
const data = characters[id-1];
this.girlName.string = data.name;
}
2025-07-22 16:43:10 +08:00
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({
2025-07-22 17:32:24 +08:00
model: "Deepseek-reasoner",
2025-07-22 16:43:10 +08:00
messages: [{ role: "user", content: str }],
temperature: 0.8,
2025-07-22 17:48:45 +08:00
id: ChatGPTService.getInstance().GetId(),
2025-07-22 16:43:10 +08:00
});
2025-07-22 17:48:45 +08:00
console.log(ret);
2025-07-22 16:43:10 +08:00
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);
}
}