Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/adapter-openai-like/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface Config extends ChatLunaPlugin.Config {
}[]
blacklistModels: string[]
additionCookies: [string, string][]
additionHeaders: [string, string][]
maxContextRatio: number
temperature: number
presencePenalty: number
Expand Down Expand Up @@ -122,6 +123,9 @@ export const Config: Schema<Config> = Schema.intersect([
.role('table'),
additionCookies: Schema.array(
Schema.tuple([Schema.string(), Schema.string()])
).default([]),
additionHeaders: Schema.array(
Schema.tuple([Schema.string(), Schema.string()])
).default([])
}),
Schema.object({
Expand Down
5 changes: 5 additions & 0 deletions packages/adapter-openai-like/src/locales/en-US.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ $inner:
- 'Cookie name'
- 'Cookie value'
$desc: 'Additional cookies'
additionHeaders:
$inner:
- 'Header name'
- 'Header value'
$desc: 'Additional request headers'

- $desc: 'Model Parameters'
maxContextRatio: 'Maximum context usage ratio (0-1). Controls the maximum percentage of model context window available for use. For example, 0.35 means at most 35% of the model context can be used.'
Expand Down
5 changes: 5 additions & 0 deletions packages/adapter-openai-like/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ $inner:
- Cookie 名称
- Cookie 值
$desc: 设置额外的 Cookie。
additionHeaders:
$inner:
- Header 名称
- Header 值
$desc: 设置额外的请求头。

- $desc: 模型设置
maxContextRatio: 最大上下文使用比例(0~1),控制可用的模型上下文窗口大小的最大百分比。例如 0.35 表示最多使用模型上下文的 35%。
Expand Down
23 changes: 12 additions & 11 deletions packages/adapter-openai-like/src/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,19 @@ export class OpenAIRequester
}

public buildHeaders() {
const result = {
Authorization: `Bearer ${this._config.value.apiKey}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://github.com/ChatLunaLab/chatluna', // Optional. Site URL for rankings on openrouter.ai.
'X-Title': 'ChatLuna' // Optional. Site title for rankings on openrouter.ai.
}
const result = Object.assign(
Object.fromEntries(this._pluginConfig.additionHeaders),
{
Authorization: `Bearer ${this._config.value.apiKey}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://github.com/ChatLunaLab/chatluna', // Optional. Site URL for rankings on openrouter.ai.
'X-Title': 'ChatLuna' // Optional. Site title for rankings on openrouter.ai.
}
)

if (Object.keys(this._pluginConfig.additionCookies).length > 0) {
result['Cookie'] = Object.keys(this._pluginConfig.additionCookies)
.map((key) => {
return `${key}=${this._pluginConfig.additionCookies[key]}`
})
if (this._pluginConfig.additionCookies.length > 0) {
result.Cookie = this._pluginConfig.additionCookies
.map(([key, value]) => `${key}=${value}`)
.join('; ')
}

Expand Down
Loading