Skip to content

Commit 630a7ef

Browse files
committed
Merge branch 'dev'
git commit -m "feat: Implement AI question-answering functionality"
2 parents 261cc07 + b581f21 commit 630a7ef

10 files changed

+29447
-60
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
- [x] **重新回答选项**:如果对 AI 回复不满意,用户可以轻松重新提问,获取新的回答。
1414
- [x] **代码复制功能**:增强代码片段复制功能。
1515
- [x] **语言切换功能**:允许用户根据偏好切换回答的语言类型。
16+
- [x] **多轮对话**:支持多轮对话功能,使用户可以与 AI 进行连续的深度互动,不局限于一次性问题。
1617

1718

1819

1920
## 即将实现的功能
2021

21-
- [ ] **多轮对话**:支持多轮对话功能,使用户可以与 AI 进行连续的深度互动,不局限于一次性问题。
2222
- [ ] **更多功能**:根据用户的需求和反馈,我们将在未来的版本中添加更多功能。
2323

2424
## 安装步骤

get-pip.py

+28,425
Large diffs are not rendered by default.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"compression-webpack-plugin": "^11.1.0",
1616
"copy-webpack-plugin": "^12.0.2",
1717
"css-loader": "^7.1.2",
18+
"css-minimizer-webpack-plugin": "^7.0.0",
1819
"highlight.js": "^11.10.0",
1920
"image-webpack-loader": "^8.1.0",
2021
"interactjs": "^1.10.27",

pnpm-lock.yaml

+711-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/content/api.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { md } from "./markdown";
22
import { getAllowAutoScroll } from "./scrollControl";
33

4+
let conversation = [];
5+
46
export async function getAIResponse(
57
text,
68
responseElement,
79
signal,
810
ps,
911
iconContainer,
10-
aiResponseContainer
12+
aiResponseContainer,
13+
isRefresh = false
1114
) {
1215
responseElement.innerHTML = "";
1316
let allowAutoScroll = true;
@@ -25,6 +28,11 @@ export async function getAIResponse(
2528
}
2629

2730
try {
31+
if(isRefresh){
32+
conversation = conversation.slice(0, -1);
33+
}else{
34+
conversation.push({ role: "user", content: text });
35+
}
2836
const response = await fetch("https://api.deepseek.com/chat/completions", {
2937
method: "POST",
3038
headers: {
@@ -42,7 +50,7 @@ export async function getAIResponse(
4250
: `The user's preferred language is ${language}. Regardless of the input language, you must respond in ${language} from now on.`
4351
} Always prioritize clear and effective communication.`,
4452
},
45-
{ role: "user", content: text },
53+
...conversation,
4654
],
4755
stream: true,
4856
}),
@@ -91,6 +99,7 @@ export async function getAIResponse(
9199
}
92100
}
93101
}
102+
conversation.push({ role: "assistant", content: aiResponse });
94103
responseElement.appendChild(iconContainer);
95104
iconContainer.dataset.ready = "true";
96105
} catch (error) {
@@ -110,4 +119,4 @@ function handleError(status, responseElement) {
110119
503: "服务器负载过高,请稍后重试。",
111120
};
112121
responseElement.innerHTML = errorMessages[status] || "请求失败,请稍后重试。";
113-
}
122+
}

src/content/icon.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ export function createIcon(x, y) {
1313
export function createSvgIcon(text, title) {
1414
const wrapper = document.createElement("div");
1515
wrapper.className = "icon-wrapper tooltip";
16-
wrapper.style.position = "relative";
1716
wrapper.style.display = "inline-block";
1817
const icon = document.createElement("img");
19-
icon.style.width = "17px";
20-
icon.style.height = "17px";
18+
icon.style.width = "15px";
19+
icon.style.height = "15px";
2120
icon.src = chrome.runtime.getURL(`icons/${text}.svg`);
2221
icon.style.border = "none";
2322
icon.style.cursor = "pointer";
@@ -56,6 +55,5 @@ export function createSvgIcon(text, title) {
5655
wrapper.addEventListener("mouseleave", () => {
5756
tooltip.style.visibility = "hidden";
5857
});
59-
6058
return wrapper;
61-
}
59+
}

src/content/markdown.js

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
5858
// 否则,创建新的 PerfectScrollbar 实例
5959
const ps = new PerfectScrollbar(pre, {
6060
suppressScrollY: true,
61-
useBothWheelAxes: true,
6261
});
6362
scrollbars.set(pre, ps);
6463
}

0 commit comments

Comments
 (0)