This commit is contained in:
2025-07-22 16:43:10 +08:00
parent a90dce06f3
commit 52bae0735f
36 changed files with 10224 additions and 1658 deletions
+9 -43
View File
@@ -1,15 +1,14 @@
import { _decorator, Component, EditBox, Label, Node } from "cc";
import { l10n } from "db://localization-editor/l10n";
import { DemoManager } from "./DemoManager";
const { ccclass, property } = _decorator;
import { _decorator, Component } from "cc";
@ccclass("ChatGPTService")
export class ChatGPTService extends Component {
@property(DemoManager)
manager: DemoManager = null;
export class ChatGPTService {
private static _instance: ChatGPTService;
@property(EditBox)
editBox: EditBox = null;
public static getInstance() {
if (!this._instance) {
this._instance = new ChatGPTService();
}
return this._instance;
}
private apiurl: string = "https://cloud.fastgpt.cn/api/v1/chat/completions";
private apikey: string =
@@ -36,39 +35,6 @@ export class ChatGPTService extends Component {
xhr.send(JSON.stringify(data));
});
}
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"));
}
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.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);
}
}
export type GPTResquest = {