update
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user