xiaokuaisong-xiaochengxu/uniapp04/unpackage/dist/dev/mp-alipay/pages/testAI/testAI.js

55 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2025-04-11 06:42:29 +00:00
"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
data() {
return {
inputText: "",
answer: ""
};
},
methods: {
async sendQuestion() {
var _a, _b;
try {
const res = await common_vendor.index.request({
url: "https://api.siliconflow.com/v1/chat/completions",
method: "POST",
header: {
"Content-Type": "application/json",
"Authorization": "Bearer sk-rbbgeretfnwjpnmqyzutorjfwvzysnuykeowudkhuaeuokdm"
},
data: {
model: "deepseek-ai/DeepSeek-R1",
messages: [{ role: "user", content: this.inputText }]
}
});
if (res.statusCode === 200) {
this.answer = res.data.choices[0].message.content;
} else {
const errorMsg = ((_b = (_a = res.data) == null ? void 0 : _a.error) == null ? void 0 : _b.message) || "API返回未知错误";
this.answer = `请求失败:${errorMsg} (状态码:${res.statusCode})`;
console.error("API错误详情:", res.data);
}
} catch (error) {
this.answer = `网络异常:${error.errMsg || "请检查网络连接"}`;
console.error("请求异常:", error);
} finally {
common_vendor.index.hideLoading();
}
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.o((...args) => $options.sendQuestion && $options.sendQuestion(...args)),
b: $data.inputText,
c: common_vendor.o(($event) => $data.inputText = $event.detail.value),
d: common_vendor.o((...args) => $options.sendQuestion && $options.sendQuestion(...args)),
e: $data.answer
}, $data.answer ? {
f: common_vendor.t($data.answer)
} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
my.createPage(MiniProgramPage);