测试流程、搭建多语言框架
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"importer": "ttf-font",
|
||||
"imported": true,
|
||||
"uuid": "d8ce1efe-4e78-453c-b14c-e43e6a60148e",
|
||||
"files": [
|
||||
".json",
|
||||
"NotoSans-Regular.ttf"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "scene",
|
||||
"imported": true,
|
||||
"uuid": "11f821b7-0408-4ecd-a1e3-b380e01cf759",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "fd1a5745-5f41-4797-8f7a-7dc1075d69a4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { _decorator, Component, EditBox, Label, Node } from "cc";
|
||||
import { l10n } from "db://localization-editor/l10n";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ChatGPTService")
|
||||
export class ChatGPTService extends Component {
|
||||
@property(EditBox)
|
||||
editBox: EditBox = null;
|
||||
@property(Label)
|
||||
reply: Label = null;
|
||||
|
||||
private apiurl: string = "https://cloud.fastgpt.cn/api/v1/chat/completions";
|
||||
private apikey: string =
|
||||
"fastgpt-gZSIl62Oznoqirj4zrs8tuvYH8Yk9C7GaOiOQtIh6UdLfup7QW2zSWS3";
|
||||
// 发送POST请求
|
||||
public async Post(data: GPTResquest): Promise<GPTResult> {
|
||||
const self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
|
||||
const response = xhr.responseText;
|
||||
if (response) {
|
||||
const d = JSON.parse(response);
|
||||
resolve(d);
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.open("POST", self.apiurl, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("Authorization", "Bearer " + self.apikey);
|
||||
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);
|
||||
let ret = await this.Post({
|
||||
model: "llama3.1:8b",
|
||||
messages: [{ role: "user", content: str }],
|
||||
temperature: 0.0,
|
||||
});
|
||||
|
||||
const rep = ret.choices[0].message.content;
|
||||
this.reply.string = rep;
|
||||
console.log("ret:" + rep);
|
||||
}
|
||||
}
|
||||
|
||||
export type GPTResquest = {
|
||||
model: string; //gpt-3.5-turbo
|
||||
messages: { role: string; content: string }[];
|
||||
temperature: number;
|
||||
};
|
||||
export type GPTResult = {
|
||||
id: string;
|
||||
object: string;
|
||||
created: number;
|
||||
model: string;
|
||||
usage: {
|
||||
prompt_tokens: number;
|
||||
completion_tokens: number;
|
||||
total_tokens: number;
|
||||
};
|
||||
choices: {
|
||||
message: {
|
||||
role: string;
|
||||
content: string;
|
||||
};
|
||||
finish_reason: string;
|
||||
index: number;
|
||||
}[];
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "edf054ac-c22c-4676-819a-d0755803ba57",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "4b506866-2b57-49ae-ac0d-2fa36590576d",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "Chat_UI"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "977c695b-0878-40c2-bd42-bd80e9b0fc60",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "010c3c6f-340c-42c8-b0ed-c77db59151d9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "*",
|
||||
"imported": true,
|
||||
"uuid": "4636a6c1-589d-49fd-a49a-5a9c5cffa22b",
|
||||
"files": [
|
||||
".json",
|
||||
".xlsx"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "*",
|
||||
"imported": true,
|
||||
"uuid": "f182779e-383c-478f-87bc-e66959517c10",
|
||||
"files": [
|
||||
".json",
|
||||
".xlsx"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "*",
|
||||
"imported": true,
|
||||
"uuid": "89413cb9-8101-42fe-96d4-52c600a2ddf4",
|
||||
"files": [
|
||||
".json",
|
||||
".xlsx"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user