Skip to content

Commit ca2de40

Browse files
authored
Merge branch 'codexu:dev' into fix_444
2 parents 3e7b472 + 4fd6502 commit ca2de40

File tree

8 files changed

+45
-9
lines changed

8 files changed

+45
-9
lines changed

messages/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@
341341
"modelBaseUrlDesc": "You only need to configure the version number, for example: https://api.openai.com/v1, the suffix will be automatically added.",
342342
"modelDesc": "Some models support getting model list, if not supported please manually configure.",
343343
"temperatureDesc": "Controls randomness of output. Lower values make generated content more deterministic.",
344-
"topPDesc": "A nucleus sampling method, where the model considers the results of tokens with top_p probability mass. So 0.1 means only consider the top 10% probability mass. Usually we suggest to change this or temperature but not both."
344+
"topPDesc": "A nucleus sampling method, where the model considers the results of tokens with top_p probability mass. So 0.1 means only consider the top 10% probability mass. Usually we suggest to change this or temperature but not both.",
345+
"customHeaders": "Custom Headers",
346+
"customHeadersDesc": "Add custom HTTP headers as JSON object. "
345347
},
346348
"ocr": {
347349
"title": "OCR",

messages/ja.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@
339339
"modelBaseUrlDesc": "バージョン番号まで設定すればOKです(例:https://api.openai.com/v1)。サフィックスは自動で追加されます。",
340340
"modelDesc": "一部モデルはリスト取得に対応しています。未対応の場合は手動で設定してください。",
341341
"temperatureDesc": "サンプリング温度は0から2の間で設定します。高い値(例:0.8)は出力をよりランダムに、低い値(例:0.2)はより決定的にします。通常、この値かtop_pのみを調整してください。",
342-
"topPDesc": "top_p(核サンプリング)は温度の代替手法です。top_p=0.1なら上位10%確率のトークンのみ考慮します。通常、この値かtemperatureのみを調整してください。"
342+
"topPDesc": "top_p(核サンプリング)は温度の代替手法です。top_p=0.1なら上位10%確率のトークンのみ考慮します。通常、この値かtemperatureのみを調整してください。",
343+
"customHeaders": "カスタムヘッダー",
344+
"customHeadersDesc": "JSONオブジェクト形式でカスタムHTTPヘッダーを追加します。"
343345
},
344346
"ocr": {
345347
"title": "OCR",

messages/zh.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@
323323
"modelBaseUrlDesc": "你只需要配置到版本号即可,例如:https://api.openai.com/v1,后缀会自动添加。",
324324
"modelDesc": "部分模型支持获取模型列表,如果不支持请手动配置。",
325325
"temperatureDesc": "使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或top_p但不是两者。",
326-
"topPDesc": "一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或temperature但不是两者。"
326+
"topPDesc": "一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或temperature但不是两者。",
327+
"customHeaders": "自定义请求头",
328+
"customHeadersDesc": "添加自定义 HTTP 请求头,格式为 JSON 对象。"
327329
},
328330
"imageMethod": {
329331
"title": "图像识别",

src/app/core/article/file/file-item.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function FileItem({ item }: { item: DirTree }) {
5454
async function handleDeleteFile() {
5555
// 添加确认弹窗
5656
const answer = await ask(t('deleteConfirm'), {
57-
title: 'NoteGen',
57+
title: item.name,
5858
kind: 'warning',
5959
});
6060

@@ -112,7 +112,7 @@ export function FileItem({ item }: { item: DirTree }) {
112112

113113
async function handleDeleteSyncFile() {
114114
const answer = await ask(t('context.deleteSyncFile') + '?', {
115-
title: 'NoteGen',
115+
title: item.name,
116116
kind: 'warning',
117117
});
118118
if (answer) {
@@ -345,7 +345,7 @@ export function FileItem({ item }: { item: DirTree }) {
345345
const fileExists = await exists(targetPath, { baseDir: BaseDirectory.AppData })
346346
if (fileExists) {
347347
const confirmOverwrite = await ask(t('clipboard.confirmOverwrite'), {
348-
title: 'NoteGen',
348+
title: item.name,
349349
kind: 'warning',
350350
})
351351
if (!confirmOverwrite) return

src/app/core/article/file/folder-item/delete-folder.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function DeleteFolder({ item }: DeleteFolderProps) {
3434

3535
// 确认删除操作
3636
const confirmed = await ask(t('context.confirmDelete', { name: item.name }), {
37-
title: 'NoteGen',
37+
title: item.name,
3838
kind: 'warning',
3939
});
4040

@@ -44,9 +44,9 @@ export function DeleteFolder({ item }: DeleteFolderProps) {
4444
const pathOptions = await getFilePathOptions(path);
4545

4646
if (workspace.isCustom) {
47-
await remove(pathOptions.path);
47+
await remove(pathOptions.path, { recursive: true });
4848
} else {
49-
await remove(pathOptions.path, { baseDir: pathOptions.baseDir });
49+
await remove(pathOptions.path, { baseDir: pathOptions.baseDir, recursive: true });
5050
}
5151

5252
// 如果删除的文件夹包含当前活动文件,清除活动文件路径

src/app/core/setting/ai/page.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client'
22
import { Input } from "@/components/ui/input";
3+
import { Textarea } from "@/components/ui/textarea";
34
import { FormItem, SettingRow, SettingType } from "../components/setting-base";
45
import { useTranslations } from 'next-intl';
56
import { useEffect, useState } from "react";
@@ -44,6 +45,7 @@ export default function AiPage() {
4445
const [topP, setTopP] = useState<number>(1.0)
4546
const [modelType, setModelType] = useState<ModelType>('chat')
4647
const [apiKeyVisible, setApiKeyVisible] = useState<boolean>(false)
48+
const [customHeaders, setCustomHeaders] = useState<string>('')
4749

4850
// 通过本地存储查询当前的模型配置
4951
async function getModelByStore(key: string) {
@@ -67,6 +69,7 @@ export default function AiPage() {
6769
setTemperature(model.temperature || 0.7)
6870
setTopP(model.topP || 0.1)
6971
setModelType(model.modelType || 'chat')
72+
setCustomHeaders(model.customHeaders ? JSON.stringify(model.customHeaders, null, 2) : '{}')
7073
}
7174

7275
// 数据变化保存
@@ -95,6 +98,9 @@ export default function AiPage() {
9598
case 'modelType':
9699
setModelType(value as ModelType)
97100
break;
101+
case 'customHeaders':
102+
setCustomHeaders(JSON.stringify(value, null, 2))
103+
break;
98104
}
99105
const model = await getModelByStore(currentAi)
100106
if (!model) return
@@ -282,6 +288,28 @@ export default function AiPage() {
282288
</RadioGroup>
283289
</FormItem>
284290
</SettingRow>
291+
{/* 自定义Headers */}
292+
{!baseAiConfig.find(config => config.baseURL === baseURL) && (
293+
<SettingRow>
294+
<FormItem title={t('customHeaders')} desc={t('customHeadersDesc')}>
295+
<Textarea
296+
value={customHeaders}
297+
onChange={(e) => {
298+
setCustomHeaders(e.target.value)
299+
}}
300+
onBlur={(e) => {
301+
try {
302+
const headers = JSON.parse(e.target.value || '{}')
303+
valueChangeHandler('customHeaders', headers)
304+
} catch {
305+
valueChangeHandler('customHeaders', {})
306+
}
307+
}}
308+
className="h-24 resize-none font-mono text-sm"
309+
/>
310+
</FormItem>
311+
</SettingRow>
312+
)}
285313
{
286314
modelType === 'chat' && (
287315
<>

src/app/core/setting/config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export interface AiConfig {
9393
modelType?: ModelType
9494
icon?: string
9595
apiKeyUrl?: string
96+
customHeaders?: Record<string, string>
9697
}
9798

9899
export interface Model {

src/lib/ai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export async function createOpenAIClient(AiConfig?: AiConfig) {
364364
"x-stainless-runtime": null,
365365
"x-stainless-runtime-version": null,
366366
"x-stainless-timeout": null,
367+
...(AiConfig?.customHeaders || {})
367368
},
368369
...(proxyUrl ? { httpAgent: proxyUrl } : {})
369370
})

0 commit comments

Comments
 (0)