Skip to content

Commit

Permalink
🔨 chore: AI 功能的 API 地址自定义优化
Browse files Browse the repository at this point in the history
  • Loading branch information
dlzmoe committed Sep 23, 2024
1 parent 0dd9692 commit ef0aabb
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- 修复:聊天框与快捷按钮冲突问题
- 优化:AI 功能的 API 地址自定义优化
49 changes: 35 additions & 14 deletions dist/linuxdo-scripts.user.js

Large diffs are not rendered by default.

49 changes: 35 additions & 14 deletions linuxdo-scripts.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linuxdo-scripts",
"version": "0.3.43",
"version": "0.3.44",
"author": "dlzmoe",
"description": "An enhanced script for the linux.do forum",
"type": "module",
Expand Down
15 changes: 12 additions & 3 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export default {
btn: true,
apikey: "",
baseurl: "https://api.openai.com",
full_url: "/v1/chat/completions",
model: "gpt-4o-mini",
prompt:
"根据以下帖子内容进行总结,请使用 markdown 格式返回回答,没有字数限制,但要求文字精炼,简介准确,语言要求返回简体中文,并且进行中英文混排优化。可以通过编号列表(1,2,3)列出核心要点。注意不要输出标题,例如:核心要点总结,帖子总结等,直接输出文本段落。",
Expand Down Expand Up @@ -433,10 +434,18 @@ export default {
const linxudoscriptssetting = localStorage.getItem("linxudoscriptssetting");
if (linxudoscriptssetting) {
// 从 localStorage 获取现有的设置数据
function deepMerge(target, source) {
for (const key in source) {
if (source[key] instanceof Object && key in target) {
target[key] = deepMerge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}
let existingData = JSON.parse(localStorage.getItem("linxudoscriptssetting"));
this.settingData = { ...this.settingData, ...existingData };
this.settingData = deepMerge(this.settingData, existingData);
localStorage.setItem("linxudoscriptssetting", JSON.stringify(this.settingData));
this.showautoread = this.settingData.checked8.value1;
Expand Down
16 changes: 12 additions & 4 deletions src/components/AIConfig/GPTconfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
</div>
<input type="text" v-model="localChecked.apikey" placeholder="sk-xxxxxxxx" />
<input
style="width: 49%"
type="text"
v-model="localChecked.baseurl"
placeholder="https://api.openai.com"
/>
<input
style="width: 49%; margin-left: 2%"
type="text"
v-model="localChecked.full_url"
placeholder="接口后缀"
/>
<input type="text" v-model="localChecked.model" placeholder="模型,如:gpt-4o-mini" />
<div>6. AI 总结帖子 prompt:</div>
<textarea v-model="localChecked.prompt"></textarea>
Expand All @@ -33,7 +40,7 @@
<div>8. AI 生成标题 prompt:</div>
<textarea v-model="localChecked.prompt2"></textarea>
<div style="margin-top: 10px">
注意:baseurl 不带后缀和 '/',不支持 http,请使用 https
注意:请按照指定格式填写参数;不支持 http,请使用 https
</div>
</div>
</template>
Expand All @@ -51,6 +58,7 @@ export default {
btn: true,
apikey: "",
baseurl: "https://api.openai.com",
full_url: "/v1/chat/completions",
model: "gpt-4o-mini",
prompt:
"根据以下帖子内容进行总结,请使用 markdown 格式返回回答,没有字数限制,但要求文字精炼,简介准确,语言要求返回简体中文,并且进行中英文混排优化。可以通过编号列表(1,2,3)列出核心要点。注意不要输出标题,例如:核心要点总结,帖子总结等,直接输出文本段落。",
Expand Down Expand Up @@ -101,7 +109,7 @@ export default {
const prompt = `${config.prompt}
帖子内容如下:
${str}`;
fetch(`${config.baseurl}/v1/chat/completions`, {
fetch(`${config.baseurl}${config.full_url}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -165,7 +173,7 @@ ${str}`;
帖子内容如下:
${str}`;
fetch(`${config.baseurl}/v1/chat/completions`, {
fetch(`${config.baseurl}${config.full_url}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -211,7 +219,7 @@ ${str}`;
帖子内容如下:
${topic_contentdata}`;
fetch(`${config.baseurl}/v1/chat/completions`, {
fetch(`${config.baseurl}${config.full_url}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 4 additions & 0 deletions version-log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.44

- 优化:AI 功能的 API 地址自定义优化。

## 0.3.43

- 修复:聊天框与快捷按钮冲突问题。
Expand Down

0 comments on commit ef0aabb

Please sign in to comment.