Skip to content

Add support of presence_penalty and frequency_penalty parameter #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 3 additions & 1 deletion src/_locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Typ",
"Mode": "Modus",
"Custom": "Benutzerdefiniert"
"Custom": "Benutzerdefiniert",
"Presence Penalty": "Präsenzstrafe",
"Frequency Penalty": "Frequenzstrafe"
}
4 changes: 3 additions & 1 deletion src/_locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Type",
"Mode": "Mode",
"Custom": "Custom"
"Custom": "Custom",
"Presence Penalty": "Presence Penalty",
"Frequency Penalty": "Frequency Penalty"
}
4 changes: 3 additions & 1 deletion src/_locales/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Tipo",
"Mode": "Modo",
"Custom": "Personalizado"
"Custom": "Personalizado",
"Presence Penalty": "Penalización por presencia",
"Frequency Penalty": "Penalización por frecuencia"
}
4 changes: 3 additions & 1 deletion src/_locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Type",
"Mode": "Mode",
"Custom": "Personnalisé"
"Custom": "Personnalisé",
"Presence Penalty": "Pénalité de présence",
"Frequency Penalty": "Pénalité de fréquence"
}
4 changes: 3 additions & 1 deletion src/_locales/in/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Jenis",
"Mode": "Mode",
"Custom": "Kustom"
"Custom": "Kustom",
"Presence Penalty": "Penalti Kehadiran",
"Frequency Penalty": "Penalti Frekuensi"
}
4 changes: 3 additions & 1 deletion src/_locales/it/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Tipo",
"Mode": "Modalità",
"Custom": "Personalizzato"
"Custom": "Personalizzato",
"Presence Penalty": "Penalità di presenza",
"Frequency Penalty": "Penalità di frequenza"
}
4 changes: 3 additions & 1 deletion src/_locales/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "タイプ",
"Mode": "モード",
"Custom": "カスタム"
"Custom": "カスタム",
"Presence Penalty": "存在ペナルティ",
"Frequency Penalty": "頻度ペナルティ"
}
4 changes: 3 additions & 1 deletion src/_locales/ko/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (웹)",
"Type": "유형",
"Mode": "모드",
"Custom": "사용자 정의"
"Custom": "사용자 정의",
"Presence Penalty": "존재 패널티",
"Frequency Penalty": "빈도 패널티"
}
4 changes: 3 additions & 1 deletion src/_locales/pt/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Tipo",
"Mode": "Modo",
"Custom": "Personalizado"
"Custom": "Personalizado",
"Presence Penalty": "Penalidade de presença",
"Frequency Penalty": "Penalidade de frequência"
}
4 changes: 3 additions & 1 deletion src/_locales/ru/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Веб)",
"Type": "Тип",
"Mode": "Режим",
"Custom": "Пользовательский"
"Custom": "Пользовательский",
"Presence Penalty": "Штраф за присутствие",
"Frequency Penalty": "Штраф за частоту"
}
4 changes: 3 additions & 1 deletion src/_locales/tr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (Web)",
"Type": "Tür",
"Mode": "Mod",
"Custom": "Özel"
"Custom": "Özel",
"Presence Penalty": "Varlık Cezası",
"Frequency Penalty": "Frekans Cezası"
}
4 changes: 3 additions & 1 deletion src/_locales/zh-hans/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,7 @@
"ChatGLM (GLM-4-Air, 128k)": "ChatGLM (GLM4Air, 性价比, 128k)",
"ChatGLM (GLM-4-0520, 128k)": "ChatGLM (GLM4-0520, 最智能, 128k)",
"ChatGLM (Emohaa)": "ChatGLM (Emohaa, 专业情绪咨询)",
"ChatGLM (CharGLM-3)": "ChatGLM (CharGLM-3, 角色扮演)"
"ChatGLM (CharGLM-3)": "ChatGLM (CharGLM-3, 角色扮演)",
"Presence Penalty": "存在惩罚",
"Frequency Penalty": "频率惩罚"
}
4 changes: 3 additions & 1 deletion src/_locales/zh-hant/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"Gemini (Web)": "Gemini (網頁版)",
"Type": "類型",
"Mode": "模式",
"Custom": "自訂"
"Custom": "自訂",
"Presence Penalty": "出現懲罰 (Presence Penalty)",
"Frequency Penalty": "頻率懲罰 (Frequency Penalty)"
}
2 changes: 2 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ export const defaultConfig = {
maxResponseTokenLength: 1000,
maxConversationContextLength: 9,
temperature: 1,
presence_penalty: 0,
frequency_penalty: 0,
customChatGptWebApiUrl: 'https://chatgpt.com',
customChatGptWebApiPath: '/backend-api/conversation',
customOpenAiApiUrl: 'https://api.openai.com',
Expand Down
28 changes: 28 additions & 0 deletions src/popup/sections/AdvancedPart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ function ApiParams({ config, updateConfig }) {
}}
/>
</label>
<label>
{t('Presence Penalty') + `: ${config.presence_penalty}`}
<input
type="range"
min="-2"
max="2"
step="0.1"
value={config.presence_penalty}
onChange={(e) => {
const value = parseFloatWithClamp(e.target.value, 0, -2, 2)
updateConfig({ presence_penalty: value })
}}
/>
</label>
<label>
{t('Frequency Penalty') + `: ${config.frequency_penalty}`}
<input
type="range"
min="-2"
max="2"
step="0.1"
value={config.frequency_penalty}
onChange={(e) => {
const value = parseFloatWithClamp(e.target.value, 0, -2, 2)
updateConfig({ frequency_penalty: value })
}}
/>
</label>
</>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/apis/azure-openai-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export async function generateAnswersWithAzureOpenaiApi(port, question, session)
stream: true,
max_tokens: config.maxResponseTokenLength,
temperature: config.temperature,
presence_penalty: config.presence_penalty,
frequency_penalty: config.frequency_penalty,
}),
onMessage(message) {
console.debug('sse message', message)
Expand Down
4 changes: 4 additions & 0 deletions src/services/apis/openai-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export async function generateAnswersWithGptCompletionApi(port, question, sessio
stream: true,
max_tokens: config.maxResponseTokenLength,
temperature: config.temperature,
presence_penalty: config.presence_penalty,
frequency_penalty: config.frequency_penalty,
stop: '\nHuman',
}),
onMessage(message) {
Expand Down Expand Up @@ -145,6 +147,8 @@ export async function generateAnswersWithChatgptApiCompat(
stream: true,
max_tokens: config.maxResponseTokenLength,
temperature: config.temperature,
presence_penalty: config.presence_penalty,
frequency_penalty: config.frequency_penalty,
...extraBody,
}),
onMessage(message) {
Expand Down