Skip to content
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

feat: Add Context Length Slider for Ollama Models #1805

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions src/renderer/components/ContextLengthSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Box, Slider, Typography } from '@mui/material'

interface Props {
value: number
onChange: (value: number) => void
}

export default function ContextLengthSlider({ value, onChange }: Props) {
const marks = [
{ value: 8192, label: '8K' },
{ value: 32768, label: '32K' },
{ value: 65536, label: '64K' },
{ value: 131072, label: '128K' },
]

return (
<Box sx={{ width: '100%', paddingTop: '16px' }}>
<Typography gutterBottom>Context Length</Typography>
<Slider
value={value}
onChange={(_, newValue) => onChange(newValue as number)}
min={8192}
max={131072}
step={8192}
marks={marks}
valueLabelDisplay="auto"
valueLabelFormat={(value) => `${(value / 1024).toFixed(0)}K`}
aria-label="Context Length"
/>
</Box>
)
}
2 changes: 2 additions & 0 deletions src/renderer/packages/models/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Options {
ollamaHost: string
ollamaModel: string
temperature: number
ollamaContextLength: number
}

export default class Ollama extends Base {
Expand Down Expand Up @@ -45,6 +46,7 @@ export default class Ollama extends Base {
stream: true,
options: {
temperature: this.options.temperature,
num_ctx: this.options.ollamaContextLength
}
},
signal,
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/pages/SettingDialog/ModelSettingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SiliconFlowSetting from './SiliconFlowSetting'
import MaxContextMessageCountSlider from '@/components/MaxContextMessageCountSlider'
import TemperatureSlider from '@/components/TemperatureSlider'
import ClaudeSetting from './ClaudeSetting'
import ContextLengthSlider from '@/components/ContextLengthSlider'

interface ModelConfigProps {
settingsEdit: ModelSettings
Expand Down Expand Up @@ -49,6 +50,10 @@ export default function ModelSettingTab(props: ModelConfigProps) {
value={settingsEdit.temperature}
onChange={(v) => setSettingsEdit({ ...settingsEdit, temperature: v })}
/>
<ContextLengthSlider
value={settingsEdit.ollamaContextLength}
onChange={(v) => setSettingsEdit({ ...settingsEdit, ollamaContextLength: v })}
/>
</>
)}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/pages/SettingDialog/OllamaSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function OllamaModelSelect(props: {
ollamaHost: props.ollamaHost,
ollamaModel: props.ollamaModel,
temperature: 0.5,
ollamaContextLength: 8192,
})
model.listModels().then((models) => {
setModels(models)
Expand Down
1 change: 1 addition & 0 deletions src/shared/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function settings(): Settings {

ollamaHost: 'http://127.0.0.1:11434',
ollamaModel: '',
ollamaContextLength: 8192,

lmStudioHost: 'http://127.0.0.1:1234',
lmStudioModel: '',
Expand Down
1 change: 1 addition & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface ModelSettings {
// ollama
ollamaHost: string
ollamaModel: string
ollamaContextLength: number

// siliconflow
siliconCloudHost: string
Expand Down