mirror of
https://github.com/klxf/eda-copilot.git
synced 2025-09-21 15:43:26 +08:00
i18n, fix get netlist
This commit is contained in:
parent
53687fc5f9
commit
509cbf3ce0
13
CHANGELOG.md
Normal file
13
CHANGELOG.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# 1.2.0-pre1
|
||||||
|
|
||||||
|
1. Commence the i18n work.
|
||||||
|
2. Modify the code to be compatible with the new `SCH_Netlist.getNetlist()` API.
|
||||||
|
|
||||||
|
# 1.1.1
|
||||||
|
|
||||||
|
1. 输入框输入完成后可按回车发送
|
||||||
|
2. 在关于增加了检查更新功能
|
||||||
|
|
||||||
|
# 1.1.0
|
||||||
|
|
||||||
|
第一个公开版本
|
@ -18,10 +18,9 @@
|
|||||||
|
|
||||||
3. 在正式使用前需要先配置模型,点击 `模型` 选择模型,点击 `设置` 进行 API 配置
|
3. 在正式使用前需要先配置模型,点击 `模型` 选择模型,点击 `设置` 进行 API 配置
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 统计信息
|
## 星星历史
|
||||||
|
|
||||||
[](https://starchart.cc/klxf/eda-copilot)
|
[](https://starchart.cc/klxf/eda-copilot)
|
||||||
|
|
||||||
@ -30,3 +29,5 @@
|
|||||||
<a href="https://choosealicense.com/licenses/apache-2.0/" style="vertical-align: inherit;" target="_blank"><img src="https://img.shields.io/github/license/easyeda/pro-api-sdk" alt="GitHub License" class="not-medium-zoom-image" style="display: inline; vertical-align: inherit;" /></a>
|
<a href="https://choosealicense.com/licenses/apache-2.0/" style="vertical-align: inherit;" target="_blank"><img src="https://img.shields.io/github/license/easyeda/pro-api-sdk" alt="GitHub License" class="not-medium-zoom-image" style="display: inline; vertical-align: inherit;" /></a>
|
||||||
|
|
||||||
本项目使用 [Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/) 开源许可协议
|
本项目使用 [Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/) 开源许可协议
|
||||||
|
|
||||||
|
本项目使用了 [Marked](https://github.com/markedjs/marked) 渲染对话
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"uuid": "30c8ce0d81f546fea716ea111c508ab2",
|
"uuid": "30c8ce0d81f546fea716ea111c508ab2",
|
||||||
"displayName": "EDA Copilot",
|
"displayName": "EDA Copilot",
|
||||||
"description": "嘉立创 EDA 多模态大模型 AI 助手",
|
"description": "嘉立创 EDA 多模态大模型 AI 助手",
|
||||||
"version": "1.1.1",
|
"version": "1.2.0",
|
||||||
"publisher": "Mr_Fang <klxf[#]vip.qq.com>",
|
"publisher": "Mr_Fang",
|
||||||
"engines": {
|
"engines": {
|
||||||
"eda": "^2.2.37"
|
"eda": "^2.2.37"
|
||||||
},
|
},
|
||||||
@ -41,24 +41,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"pcb": [
|
|
||||||
{
|
|
||||||
"id": "copilot-pcb",
|
|
||||||
"title": "Copilot",
|
|
||||||
"menuItems": [
|
|
||||||
{
|
|
||||||
"id": "copilot-iframe",
|
|
||||||
"title": "打开聊天",
|
|
||||||
"registerFn": "openIframe"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "copilot-about",
|
|
||||||
"title": "关于...",
|
|
||||||
"registerFn": "openAbout"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
178
iframe/js/AI.js
178
iframe/js/AI.js
@ -8,16 +8,16 @@ async function getAIResponse(contents) {
|
|||||||
document.querySelector('.chat-body').appendChild(thinking);
|
document.querySelector('.chat-body').appendChild(thinking);
|
||||||
document.querySelector('.chat-body').scrollTop = document.querySelector('.chat-body').scrollHeight;
|
document.querySelector('.chat-body').scrollTop = document.querySelector('.chat-body').scrollHeight;
|
||||||
|
|
||||||
if (MODEL_GROUP === "Gemini") {
|
if (MODEL_GROUP === 'Gemini') {
|
||||||
response = await getGeminiResponse(contents);
|
response = await getGeminiResponse(contents);
|
||||||
} else if (MODEL_GROUP === "DeepSeek") {
|
} else if (MODEL_GROUP === 'DeepSeek') {
|
||||||
response = await getDeepSeekResponse(contents);
|
response = await getDeepSeekResponse(contents);
|
||||||
} else if (MODEL_GROUP === "QWen") {
|
} else if (MODEL_GROUP === 'QWen') {
|
||||||
response = await getQWenResponse(contents);
|
response = await getQWenResponse(contents);
|
||||||
} else if (MODEL_GROUP === "Custom") {
|
} else if (MODEL_GROUP === 'Custom') {
|
||||||
response = await getCustomResponse(contents);
|
response = await getCustomResponse(contents);
|
||||||
} else {
|
} else {
|
||||||
response = { err_code: 1, error: "模型不被支持" };
|
response = { err_code: 1, error: '模型不被支持' };
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
@ -28,51 +28,54 @@ async function getAIResponse(contents) {
|
|||||||
content = content.replace(/\u003cthink\u003e/, '<div class="think">').replace(/\u003c\/think\u003e/, '</div>');
|
content = content.replace(/\u003cthink\u003e/, '<div class="think">').replace(/\u003c\/think\u003e/, '</div>');
|
||||||
createBubble('model', content, undefined);
|
createBubble('model', content, undefined);
|
||||||
|
|
||||||
if (MODEL_GROUP === "Gemini") {
|
if (MODEL_GROUP === 'Gemini') {
|
||||||
chatHistory.push({ role: 'model', parts: [{ text: content }] });
|
chatHistory.push({ role: 'model', parts: [{ text: content }] });
|
||||||
} else if (MODEL_GROUP === "DeepSeek" || MODEL_GROUP === "Qwen" || MODEL_GROUP === "Custom") {
|
} else if (MODEL_GROUP === 'DeepSeek' || MODEL_GROUP === 'Qwen' || MODEL_GROUP === 'Custom') {
|
||||||
chatHistory.push({ role: 'assistant', content: content });
|
chatHistory.push({ role: 'assistant', content: content });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CHAT_TITLE === "新的对话") {
|
if (CHAT_TITLE === '新的对话') {
|
||||||
let temp = chatHistory.slice();
|
let temp = chatHistory.slice();
|
||||||
if (MODEL_GROUP === "Gemini") {
|
if (MODEL_GROUP === 'Gemini') {
|
||||||
temp.push({ role: 'user', parts: [{ text: "用几个字总结这个对话,将其作为对话的标题" }] });
|
temp.push({ role: 'user', parts: [{ text: '用几个字总结这个对话,将其作为对话的标题' }] });
|
||||||
|
|
||||||
getGeminiResponse(temp).then(response => {
|
getGeminiResponse(temp).then((response) => {
|
||||||
if (response.err_code === 0) {
|
if (response.err_code === 0) {
|
||||||
const summary = response.response;
|
const summary = response.response;
|
||||||
CHAT_TITLE = summary.replace('*', '');
|
CHAT_TITLE = summary.replace('*', '');
|
||||||
document.getElementById('title').innerText = summary;
|
document.getElementById('title').innerText = summary;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (MODEL_GROUP === "DeepSeek") {
|
} else if (MODEL_GROUP === 'DeepSeek') {
|
||||||
temp.push({ role: 'user', content: "用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字" });
|
temp.push({ role: 'user', content: '用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字' });
|
||||||
|
|
||||||
getDeepSeekResponse(temp).then(response => {
|
getDeepSeekResponse(temp).then((response) => {
|
||||||
if (response.err_code === 0) {
|
if (response.err_code === 0) {
|
||||||
const summary = response.response;
|
const summary = response.response;
|
||||||
CHAT_TITLE = summary.replace(/\u003cthink\u003e.*\u003c\/think\u003e/ms, '').replace('*', '');
|
CHAT_TITLE = summary.replace(/\u003cthink\u003e.*\u003c\/think\u003e/ms, '').replace('*', '');
|
||||||
document.getElementById('title').innerText = CHAT_TITLE;
|
document.getElementById('title').innerText = CHAT_TITLE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (MODEL_GROUP === "QWen") {
|
} else if (MODEL_GROUP === 'QWen') {
|
||||||
temp.push({ role: 'user', content: "用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字" });
|
temp.push({ role: 'user', content: '用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字' });
|
||||||
|
|
||||||
getQWenResponse(temp).then(response => {
|
getQWenResponse(temp).then((response) => {
|
||||||
if (response.err_code === 0) {
|
if (response.err_code === 0) {
|
||||||
const summary = response.response;
|
const summary = response.response;
|
||||||
CHAT_TITLE = summary.replace(/\u003cthink\u003e.*\u003c\/think\u003e/ms, '').replace('*', '');
|
CHAT_TITLE = summary.replace(/\u003cthink\u003e.*\u003c\/think\u003e/ms, '').replace('*', '');
|
||||||
document.getElementById('title').innerText = CHAT_TITLE;
|
document.getElementById('title').innerText = CHAT_TITLE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (MODEL_GROUP === "Custom") {
|
} else if (MODEL_GROUP === 'Custom') {
|
||||||
temp.push({ role: 'user', content: "用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字" });
|
temp.push({ role: 'user', content: '用几个字总结这个对话,将其作为对话的标题,除此以外不要有任何其他文字' });
|
||||||
|
|
||||||
getCustomResponse(temp).then((response) => {
|
getCustomResponse(temp).then((response) => {
|
||||||
if (response.err_code === 0) {
|
if (response.err_code === 0) {
|
||||||
const summary = response.response;
|
const summary = response.response;
|
||||||
CHAT_TITLE = summary.replace(/<think>.*<\/think>/ms, '').replaceAll('*', '').replaceAll('\n', '');
|
CHAT_TITLE = summary
|
||||||
|
.replace(/<think>.*<\/think>/ms, '')
|
||||||
|
.replaceAll('*', '')
|
||||||
|
.replaceAll('\n', '');
|
||||||
document.getElementById('title').innerText = CHAT_TITLE;
|
document.getElementById('title').innerText = CHAT_TITLE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -80,78 +83,76 @@ async function getAIResponse(contents) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('thinking').remove();
|
document.getElementById('thinking').remove();
|
||||||
createBubble('model', response.error, "异常");
|
createBubble('model', response.error, '异常');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async function setAICache(cache) {
|
async function setAICache(cache) {
|
||||||
if (MODEL_GROUP === "Gemini" && MODEL_NAME !== "gemini-2.0-flash-001") {
|
if (MODEL_GROUP === 'Gemini' && MODEL_NAME !== 'gemini-2.0-flash-001') {
|
||||||
return await setGeminiCache(cache);
|
return await setGeminiCache(cache);
|
||||||
} else if (MODEL_GROUP === "QWen" || MODEL_GROUP === "DeepSeek" || MODEL_GROUP === "Custom") {
|
} else if (MODEL_GROUP === 'QWen' || MODEL_GROUP === 'DeepSeek' || MODEL_GROUP === 'Custom') {
|
||||||
return await setOtherCache(decodeURIComponent(atob(cache)));
|
return await setOtherCache(decodeURIComponent(atob(cache)));
|
||||||
} else if (MODEL_GROUP === "Gemini" && MODEL_NAME === "gemini-2.0-flash-001") {
|
} else if (MODEL_GROUP === 'Gemini' && MODEL_NAME === 'gemini-2.0-flash-001') {
|
||||||
return await setOtherCache(decodeURIComponent(atob(cache)));
|
return await setOtherCache(decodeURIComponent(atob(cache)));
|
||||||
} else {
|
} else {
|
||||||
createBubble('model', "抱歉,该模型不支持缓存长上下文", "异常");
|
createBubble('model', '抱歉,该模型不支持缓存长上下文', '异常');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGeminiResponse(contents) {
|
async function getGeminiResponse(contents) {
|
||||||
const API = GOOGLE_SETTINGS.HOST + "/v1beta/models/" + MODEL_NAME + ":generateContent?key=" + GOOGLE_SETTINGS.API_KEY;
|
const API = GOOGLE_SETTINGS.HOST + '/v1beta/models/' + MODEL_NAME + ':generateContent?key=' + GOOGLE_SETTINGS.API_KEY;
|
||||||
console.log(chatHistory);
|
console.log(chatHistory);
|
||||||
const data = {
|
const data = {
|
||||||
contents: [
|
contents: [contents],
|
||||||
contents
|
|
||||||
],
|
|
||||||
safetySettings: [
|
safetySettings: [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"category": "HARM_CATEGORY_HARASSMENT",
|
'category': 'HARM_CATEGORY_HARASSMENT',
|
||||||
"threshold": "BLOCK_ONLY_HIGH"
|
'threshold': 'BLOCK_ONLY_HIGH',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||||||
"threshold": "BLOCK_ONLY_HIGH"
|
'threshold': 'BLOCK_ONLY_HIGH',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||||||
"threshold": "BLOCK_ONLY_HIGH"
|
'threshold': 'BLOCK_ONLY_HIGH',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||||||
"threshold": "BLOCK_ONLY_HIGH"
|
'threshold': 'BLOCK_ONLY_HIGH',
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (CACHE_NAME !== null) {
|
if (CACHE_NAME !== null) {
|
||||||
data.cachedContent = CACHE_NAME;
|
data.cachedContent = CACHE_NAME;
|
||||||
} else {
|
} else {
|
||||||
data.systemInstruction = { parts: [{ "text": "You are an electronic engineer. Use Chinese to answer." }] }
|
data.systemInstruction = { parts: [{ 'text': 'You are an electronic engineer. Use Chinese to answer.' }] };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await eda.sys_ClientUrl.request(API, "POST", JSON.stringify(data), { headers: GOOGLE_SETTINGS.HEADER });
|
const response = await eda.sys_ClientUrl.request(API, 'POST', JSON.stringify(data), { headers: GOOGLE_SETTINGS.HEADER });
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return {
|
return {
|
||||||
response: result.candidates[0].content.parts[0].text,
|
response: result.candidates[0].content.parts[0].text,
|
||||||
err_code: 0
|
err_code: 0,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
error: error.message || "请求失败",
|
error: error.message || '请求失败',
|
||||||
err_code: 1
|
err_code: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDeepSeekResponse(contents) {
|
async function getDeepSeekResponse(contents) {
|
||||||
const API = DS_SETTINGS.HOST + "/chat/completions";
|
const API = DS_SETTINGS.HOST + '/chat/completions';
|
||||||
let HEADERS = DS_SETTINGS.HEADER;
|
let HEADERS = DS_SETTINGS.HEADER;
|
||||||
|
|
||||||
HEADERS['Authorization'] = 'Bearer ' + DS_SETTINGS.API_KEY;
|
HEADERS['Authorization'] = 'Bearer ' + DS_SETTINGS.API_KEY;
|
||||||
@ -159,29 +160,29 @@ async function getDeepSeekResponse(contents) {
|
|||||||
const data = {
|
const data = {
|
||||||
model: MODEL_NAME,
|
model: MODEL_NAME,
|
||||||
messages: contents,
|
messages: contents,
|
||||||
stream: false
|
stream: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await eda.sys_ClientUrl.request(API, "POST", JSON.stringify(data), { headers: HEADERS });
|
const response = await eda.sys_ClientUrl.request(API, 'POST', JSON.stringify(data), { headers: HEADERS });
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return {
|
return {
|
||||||
response: result.choices[0].message.content,
|
response: result.choices[0].message.content,
|
||||||
err_code: 0
|
err_code: 0,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
error: error.message || "请求失败",
|
error: error.message || '请求失败',
|
||||||
err_code: 1
|
err_code: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getQWenResponse(contents) {
|
async function getQWenResponse(contents) {
|
||||||
const API = QWEN_SETTINGS.HOST + "/compatible-mode/v1/chat/completions";
|
const API = QWEN_SETTINGS.HOST + '/compatible-mode/v1/chat/completions';
|
||||||
let HEADERS = QWEN_SETTINGS.HEADER;
|
let HEADERS = QWEN_SETTINGS.HEADER;
|
||||||
|
|
||||||
HEADERS['Authorization'] = 'Bearer ' + QWEN_SETTINGS.API_KEY;
|
HEADERS['Authorization'] = 'Bearer ' + QWEN_SETTINGS.API_KEY;
|
||||||
@ -189,22 +190,22 @@ async function getQWenResponse(contents) {
|
|||||||
const data = {
|
const data = {
|
||||||
model: MODEL_NAME,
|
model: MODEL_NAME,
|
||||||
messages: contents,
|
messages: contents,
|
||||||
}
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await eda.sys_ClientUrl.request(API, "POST", JSON.stringify(data), { headers: HEADERS });
|
const response = await eda.sys_ClientUrl.request(API, 'POST', JSON.stringify(data), { headers: HEADERS });
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return {
|
return {
|
||||||
response: result.choices[0].message.content,
|
response: result.choices[0].message.content,
|
||||||
err_code: 0
|
err_code: 0,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
error: error.message || "请求失败",
|
error: error.message || '请求失败',
|
||||||
err_code: 1
|
err_code: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,43 +216,49 @@ async function getCustomResponse(contents) {
|
|||||||
const data = {
|
const data = {
|
||||||
model: CUSTOM_SETTINGS.MODEL,
|
model: CUSTOM_SETTINGS.MODEL,
|
||||||
messages: contents,
|
messages: contents,
|
||||||
stream: false
|
stream: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await eda.sys_ClientUrl.request(API, "POST", JSON.stringify(data), { headers: CUSTOM_SETTINGS.HEADER });
|
const response = await eda.sys_ClientUrl.request(API, 'POST', JSON.stringify(data), { headers: CUSTOM_SETTINGS.HEADER });
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return {
|
return {
|
||||||
response: result.choices[0].message.content,
|
response: result.choices[0].message.content,
|
||||||
err_code: 0
|
err_code: 0,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
error: error.message || "请求失败",
|
error: error.message || '请求失败',
|
||||||
err_code: 1
|
err_code: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setGeminiCache(cache) {
|
async function setGeminiCache(cache) {
|
||||||
let API = GOOGLE_SETTINGS.HOST + "/v1beta/cachedContents?key=" + GOOGLE_SETTINGS.API_KEY;
|
let API = GOOGLE_SETTINGS.HOST + '/v1beta/cachedContents?key=' + GOOGLE_SETTINGS.API_KEY;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
model: "models/" + MODEL_NAME,
|
model: 'models/' + MODEL_NAME,
|
||||||
contents: [
|
contents: [
|
||||||
{ role: 'user', parts: [{ inline_data: { mime_type: "text/plain", data: cache} }, {text: "Here's a netlist file describing the circuit diagram, and I'm going to ask you questions about it."}] }
|
{
|
||||||
|
role: 'user',
|
||||||
|
parts: [
|
||||||
|
{ inline_data: { mime_type: 'text/plain', data: cache } },
|
||||||
|
{ text: "Here's a netlist file describing the circuit diagram, and I'm going to ask you questions about it." },
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
systemInstruction: {
|
systemInstruction: {
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
"text": "You are an electronic engineer. The text describes a netlist of circuit diagrams. When asked a question about a component, it is displayed if there is a URL in the netlist, otherwise it is not. Use Chinese to answer."
|
'text': 'You are an electronic engineer. The text describes a netlist of circuit diagrams. When asked a question about a component, it is displayed if there is a URL in the netlist, otherwise it is not. Use Chinese to answer.',
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
}
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let thinking = document.createElement('div');
|
let thinking = document.createElement('div');
|
||||||
thinking.className = 'message-bubble model';
|
thinking.className = 'message-bubble model';
|
||||||
@ -260,31 +267,35 @@ async function setGeminiCache(cache) {
|
|||||||
document.querySelector('.chat-body').appendChild(thinking);
|
document.querySelector('.chat-body').appendChild(thinking);
|
||||||
document.querySelector('.chat-body').scrollTop = document.querySelector('.chat-body').scrollHeight;
|
document.querySelector('.chat-body').scrollTop = document.querySelector('.chat-body').scrollHeight;
|
||||||
|
|
||||||
eda.sys_ClientUrl.request(API, "POST", JSON.stringify(data), { headers: GOOGLE_SETTINGS.HEADER }).then(response => {
|
eda.sys_ClientUrl
|
||||||
|
.request(API, 'POST', JSON.stringify(data), { headers: GOOGLE_SETTINGS.HEADER })
|
||||||
|
.then((response) => {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(result => {
|
})
|
||||||
|
.then((result) => {
|
||||||
document.getElementById('thinking').remove();
|
document.getElementById('thinking').remove();
|
||||||
createBubble('model', "好的,接下来你可以围绕这张原理图向我提问", undefined);
|
createBubble('model', '好的,接下来你可以围绕这张原理图向我提问', undefined);
|
||||||
CACHE_NAME = result.name;
|
CACHE_NAME = result.name;
|
||||||
}).catch(error => {
|
})
|
||||||
|
.catch((error) => {
|
||||||
document.getElementById('thinking').remove();
|
document.getElementById('thinking').remove();
|
||||||
createBubble('model', error.toString(), "异常");
|
createBubble('model', error.toString(), '异常');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setOtherCache(cache) {
|
async function setOtherCache(cache) {
|
||||||
chatHistory.push({ role: 'user', content: '这是一个电路图的网表,后续回答依照这个网表回答:' + cache });
|
chatHistory.push({ role: 'user', content: '这是一个电路图的网表,后续回答依照这个网表回答:' + cache });
|
||||||
chatHistory.push({ role: 'assistant', content: '好的,我了解了'});
|
chatHistory.push({ role: 'assistant', content: '好的,我了解了' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
function getNetlist() {
|
function getNetlist() {
|
||||||
let netlist = '';
|
let netlist = '';
|
||||||
eda.sch_Netlist.getNetlist().then(data => {
|
eda.sch_Netlist.getNetlist().then((data) => {
|
||||||
netlist = data[0].toString();
|
netlist = data.toString();
|
||||||
const cache = btoa(encodeURIComponent(netlist));
|
const cache = btoa(encodeURIComponent(netlist));
|
||||||
// 获取 cache 的字节数
|
// 获取 cache 的字节数
|
||||||
let size = cache.length;
|
let size = cache.length;
|
||||||
@ -306,17 +317,17 @@ function getNetlist() {
|
|||||||
</div>`;
|
</div>`;
|
||||||
document.querySelector('.chat-body').appendChild(fileBubble);
|
document.querySelector('.chat-body').appendChild(fileBubble);
|
||||||
setAICache(cache);
|
setAICache(cache);
|
||||||
})
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async function setAIFile() {
|
async function setAIFile() {
|
||||||
if (MODEL_GROUP !== "Gemini") {
|
if (MODEL_GROUP !== 'Gemini') {
|
||||||
eda.sys_Message.showToastMessage('当前模型尚未支持该功能', 'warn');
|
eda.sys_Message.showToastMessage('当前模型尚未支持该功能', 'warn');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const file = await eda.sys_FileSystem.openReadFileDialog("pdf");
|
|
||||||
|
const file = await eda.sys_FileSystem.openReadFileDialog('.pdf');
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function (event) {
|
reader.onload = function (event) {
|
||||||
const base64 = event.target.result;
|
const base64 = event.target.result;
|
||||||
@ -386,4 +397,3 @@ async function getDatasheetData(url) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,24 @@
|
|||||||
{
|
{
|
||||||
"About": "About",
|
"iframe.settings.title": "Settings",
|
||||||
"EasyEDA extension SDK v": "EasyEDA extension SDK v${1}"
|
"iframe.settings.api_host": "API Host",
|
||||||
|
"iframe.settings.api_key": "API Key",
|
||||||
|
"iframe.settings.header": "Request Header",
|
||||||
|
"iframe.settings.endpoint": "Endpoint",
|
||||||
|
"iframe.settings.model": "Model",
|
||||||
|
"iframe.settings.model.choose": "Choose Model",
|
||||||
|
"iframe.settings.model.custom": "Custom",
|
||||||
|
"iframe.button.cancel": "Cancel",
|
||||||
|
"iframe.button.save": "Save",
|
||||||
|
"iframe.button.analysis_netlist": "Netlist",
|
||||||
|
"iframe.button.add_file": "Add File",
|
||||||
|
"iframe.button.new_chat": "New Chat",
|
||||||
|
"iframe.button.model": "Model",
|
||||||
|
"iframe.button.setting": "Settings",
|
||||||
|
"iframe.button.send": "Send",
|
||||||
|
"iframe.chat.default_title": "New Chat",
|
||||||
|
"iframe.chat.default_message": "Can I help you?",
|
||||||
|
"iframe.chat.default_message_meta": "Prompt",
|
||||||
|
"iframe.chat.context_cleared": "Context Cleared",
|
||||||
|
"iframe.input.chat_input": "Send image, file or netlist can resolve complex issues.",
|
||||||
|
"toast.network_error": "This extension requires enabling the 'External Interactions' permission!"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,24 @@
|
|||||||
{
|
{
|
||||||
"About": "关于",
|
"iframe.settings": "设置",
|
||||||
"EasyEDA extension SDK v": "嘉立创EDA 扩展 SDK v${1}"
|
"iframe.settings.api_host": "接口地址",
|
||||||
|
"iframe.settings.api_key": "API Key",
|
||||||
|
"iframe.settings.header": "自定义请求头",
|
||||||
|
"iframe.settings.endpoint": "终结点",
|
||||||
|
"iframe.settings.model": "模型",
|
||||||
|
"iframe.settings.model.choose": "选择模型",
|
||||||
|
"iframe.settings.model.custom": "自定义",
|
||||||
|
"iframe.button.cancel": "取消",
|
||||||
|
"iframe.button.save": "保存",
|
||||||
|
"iframe.button.analysis_netlist": "解析网表",
|
||||||
|
"iframe.button.add_file": "添加文件",
|
||||||
|
"iframe.button.new_chat": "新的聊天",
|
||||||
|
"iframe.button.model": "模型",
|
||||||
|
"iframe.button.setting": "设置",
|
||||||
|
"iframe.button.send": "发送",
|
||||||
|
"iframe.chat.default_title": "新的聊天",
|
||||||
|
"iframe.chat.default_message": "有什么可以帮你的吗?",
|
||||||
|
"iframe.chat.default_message_meta": "预设提示词",
|
||||||
|
"iframe.chat.context_cleared": "上下文已清除",
|
||||||
|
"iframe.input.chat_input": "解析网表、上传图片或文件可解决复杂问题",
|
||||||
|
"toast.network_error": "本拓展需要启用外部交互权限!"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user