This commit is contained in:
2025-07-21 22:14:06 +08:00
parent 2f7eb16f22
commit a90dce06f3
16 changed files with 1229 additions and 174 deletions
+21 -9
View File
@@ -1,13 +1,15 @@
import { _decorator, Component, EditBox, Label, Node } from "cc";
import { l10n } from "db://localization-editor/l10n";
import { DemoManager } from "./DemoManager";
const { ccclass, property } = _decorator;
@ccclass("ChatGPTService")
export class ChatGPTService extends Component {
@property(DemoManager)
manager: DemoManager = null;
@property(EditBox)
editBox: EditBox = null;
@property(Label)
reply: Label = null;
private apiurl: string = "https://cloud.fastgpt.cn/api/v1/chat/completions";
private apikey: string =
@@ -36,25 +38,35 @@ export class ChatGPTService extends Component {
}
protected async start(): Promise<void> {
console.log(l10n.t("hello"));
l10n.changeLanguage("zh-Hans-CN");
console.log(l10n.t("hello"));
l10n.changeLanguage("en");
console.log(l10n.t("hello"));
// console.log(l10n.t("hello"));
// l10n.changeLanguage("zh-Hans-CN");
// console.log(l10n.t("hello"));
// l10n.changeLanguage("en");
// console.log(l10n.t("hello"));
}
public async OnClickSend() {
const str = this.editBox.string;
if (!str || str == "") return;
console.log("post:" + str);
if (this.manager) {
this.manager.updateDialog(true, str);
}
let ret = await this.Post({
model: "llama3.1:8b",
messages: [{ role: "user", content: str }],
temperature: 0.0,
temperature: 0.8,
});
const rep = ret.choices[0].message.content;
this.reply.string = rep;
if (rep == null) {
console.warn("rep null");
}
if (this.manager) {
this.manager.updateDialog(false, rep);
}
console.log("ret:" + rep);
}
}