Skip to content

Commit 27276ce

Browse files
Votre NomVotre Nom
Votre Nom
authored and
Votre Nom
committed
merge easy config select
2 parents e1c9b61 + 72926d5 commit 27276ce

File tree

4 files changed

+152
-118
lines changed

4 files changed

+152
-118
lines changed

examples/server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ by server.cpp. This is done by building `llama-server` as described in the
246246
[build](#build) section above.
247247

248248
Prompt and other configuration parameters are easily customisable with the json file `public/prompts.config.json`.
249+
You can rename `public/prompts.config.json.example` to `public/prompts.config.json` to make it work.
249250
Examples from https://github.com/f/awesome-chatgpt-prompts have been already written in it.
250251

251-
252252
NOTE: if you are using the vite dev server, you can change the API base URL to llama.cpp. To do that, run this code snippet in browser's console:
253253

254254
```js

examples/server/public/prompts.config.json renamed to examples/server/public/prompts.config.json.example

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
{
22
"prompts": [
3+
{
4+
"name": "Configuration example",
5+
"lang": "en",
6+
"config": {
7+
"apiKey": "",
8+
"custom": "",
9+
"dry_allowed_length": 2,
10+
"dry_base": 1.75,
11+
"dry_multiplier": 0,
12+
"dry_penalty_last_n": -1,
13+
"dynatemp_exponent": 1,
14+
"dynatemp_range": 0,
15+
"excludeThoughtOnReq": true,
16+
"frequency_penalty": 0,
17+
"max_tokens": -1,
18+
"min_p": 0.05,
19+
"presence_penalty": 0,
20+
"pyIntepreterEnabled": false,
21+
"repeat_last_n": 64,
22+
"repeat_penalty": 1,
23+
"samplers": "edkypmxt",
24+
"showThoughtInProgress": false,
25+
"showTokensPerSecond": false,
26+
"systemMessage": "You are a helpful assistant.",
27+
"temperature": 0.8,
28+
"top_k": 40,
29+
"top_p": 0.95,
30+
"typical_p": 1,
31+
"xtc_probability": 0,
32+
"xtc_threshold": 0.1
33+
}
34+
},
335
{
436
"name": "Ethereum Developer",
537
"lang": "en",
@@ -1695,38 +1727,6 @@
16951727
"systemMessage": "You are a ${Title:Senior} DevOps engineer working at ${Company Type: Big Company}. Your role is to provide scalable, efficient, and automated solutions for software deployment, infrastructure management, and CI/CD pipelines. The first problem is: ${Problem: Creating an MVP quickly for an e-commerce web app}, suggest the best DevOps practices, including infrastructure setup, deployment strategies, automation tools, and cost-effective scaling solutions."
16961728
},
16971729
"for_devs": "TRUE"
1698-
},
1699-
{
1700-
"name": "Full prompt config example",
1701-
"lang": "en",
1702-
"config": {
1703-
"apiKey": "",
1704-
"custom": "",
1705-
"dry_allowed_length": 2,
1706-
"dry_base": 1.75,
1707-
"dry_multiplier": 0,
1708-
"dry_penalty_last_n": -1,
1709-
"dynatemp_exponent": 1,
1710-
"dynatemp_range": 0,
1711-
"excludeThoughtOnReq": true,
1712-
"frequency_penalty": 0,
1713-
"max_tokens": -1,
1714-
"min_p": 0.05,
1715-
"presence_penalty": 0,
1716-
"pyIntepreterEnabled": false,
1717-
"repeat_last_n": 64,
1718-
"repeat_penalty": 1,
1719-
"samplers": "edkypmxt",
1720-
"showThoughtInProgress": false,
1721-
"showTokensPerSecond": false,
1722-
"systemMessage": "Imagine you are an experienced Ethereum developer tasked with creating a smart contract for a blockchain messenger. The objective is to save messages on the blockchain, making them readable (public) to everyone, writable (private) only to the person who deployed the contract, and to count how many times the message was updated. Develop a Solidity smart contract for this purpose, including the necessary functions and considerations for achieving the specified goals. Please provide the code and any relevant explanations to ensure a clear understanding of the implementation.",
1723-
"temperature": 0.8,
1724-
"top_k": 40,
1725-
"top_p": 0.95,
1726-
"typical_p": 1,
1727-
"xtc_probability": 0,
1728-
"xtc_threshold": 0.1
1729-
}
17301730
}
17311731
]
17321732
}

examples/server/webui/public/prompts.config.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
{
22
"prompts": [
3+
{
4+
"name": "Configuration example",
5+
"lang": "en",
6+
"config": {
7+
"apiKey": "",
8+
"custom": "",
9+
"dry_allowed_length": 2,
10+
"dry_base": 1.75,
11+
"dry_multiplier": 0,
12+
"dry_penalty_last_n": -1,
13+
"dynatemp_exponent": 1,
14+
"dynatemp_range": 0,
15+
"excludeThoughtOnReq": true,
16+
"frequency_penalty": 0,
17+
"max_tokens": -1,
18+
"min_p": 0.05,
19+
"presence_penalty": 0,
20+
"pyIntepreterEnabled": false,
21+
"repeat_last_n": 64,
22+
"repeat_penalty": 1,
23+
"samplers": "edkypmxt",
24+
"showThoughtInProgress": false,
25+
"showTokensPerSecond": false,
26+
"systemMessage": "You are a helpful assistant.",
27+
"temperature": 0.8,
28+
"top_k": 40,
29+
"top_p": 0.95,
30+
"typical_p": 1,
31+
"xtc_probability": 0,
32+
"xtc_threshold": 0.1
33+
}
34+
},
335
{
436
"name": "Ethereum Developer",
537
"lang": "en",
@@ -1695,38 +1727,6 @@
16951727
"systemMessage": "You are a ${Title:Senior} DevOps engineer working at ${Company Type: Big Company}. Your role is to provide scalable, efficient, and automated solutions for software deployment, infrastructure management, and CI/CD pipelines. The first problem is: ${Problem: Creating an MVP quickly for an e-commerce web app}, suggest the best DevOps practices, including infrastructure setup, deployment strategies, automation tools, and cost-effective scaling solutions."
16961728
},
16971729
"for_devs": "TRUE"
1698-
},
1699-
{
1700-
"name": "Full prompt config example",
1701-
"lang": "en",
1702-
"config": {
1703-
"apiKey": "",
1704-
"custom": "",
1705-
"dry_allowed_length": 2,
1706-
"dry_base": 1.75,
1707-
"dry_multiplier": 0,
1708-
"dry_penalty_last_n": -1,
1709-
"dynatemp_exponent": 1,
1710-
"dynatemp_range": 0,
1711-
"excludeThoughtOnReq": true,
1712-
"frequency_penalty": 0,
1713-
"max_tokens": -1,
1714-
"min_p": 0.05,
1715-
"presence_penalty": 0,
1716-
"pyIntepreterEnabled": false,
1717-
"repeat_last_n": 64,
1718-
"repeat_penalty": 1,
1719-
"samplers": "edkypmxt",
1720-
"showThoughtInProgress": false,
1721-
"showTokensPerSecond": false,
1722-
"systemMessage": "Imagine you are an experienced Ethereum developer tasked with creating a smart contract for a blockchain messenger. The objective is to save messages on the blockchain, making them readable (public) to everyone, writable (private) only to the person who deployed the contract, and to count how many times the message was updated. Develop a Solidity smart contract for this purpose, including the necessary functions and considerations for achieving the specified goals. Please provide the code and any relevant explanations to ensure a clear understanding of the implementation.",
1723-
"temperature": 0.8,
1724-
"top_k": 40,
1725-
"top_p": 0.95,
1726-
"typical_p": 1,
1727-
"xtc_probability": 0,
1728-
"xtc_threshold": 0.1
1729-
}
17301730
}
17311731
]
17321732
}

examples/server/webui/src/components/Header.tsx

Lines changed: 87 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function Header() {
2020
const navigate = useNavigate();
2121
const [selectedTheme, setSelectedTheme] = useState(StorageUtils.getTheme());
2222
const { setShowSettings } = useAppContext();
23+
const [selectedConfig, setSelectedConfig] = useState<number>(-1);
2324

2425
const setTheme = (theme: string) => {
2526
StorageUtils.setTheme(theme);
@@ -31,9 +32,9 @@ export default function Header() {
3132
JSON.parse(JSON.stringify(config))
3233
);
3334

34-
const [promptSelectOptions, setPromptSelectOptions] = useState([
35-
{ key: -1, value: 'System prompt (none)' },
36-
]);
35+
const [promptSelectOptions, setPromptSelectOptions] = useState<
36+
{ key: number; value: string }[]
37+
>([]);
3738
const [promptSelectConfig, setPromptSelectConfig] = useState<
3839
typeof PROMPT_JSON | null
3940
>(null);
@@ -44,12 +45,13 @@ export default function Header() {
4445
// @ts-expect-error daisyuiThemes complains about index type, but it should work
4546
daisyuiThemes[selectedTheme]?.['color-scheme'] ?? 'auto'
4647
);
48+
}, [selectedTheme]);
49+
50+
useEffect(() => {
4751
fetch('/prompts.config.json')
4852
.then((response) => response.json())
4953
.then((data) => {
50-
const prt: { key: number; value: string }[] = [
51-
{ key: -1, value: 'Choose a system config' },
52-
];
54+
const prt: { key: number; value: string }[] = [];
5355
if (data && data.prompts) {
5456
setPromptSelectConfig(data.prompts);
5557
Object.keys(data.prompts).forEach(function (key) {
@@ -58,8 +60,23 @@ export default function Header() {
5860
});
5961
}
6062
setPromptSelectOptions(prt);
63+
})
64+
.catch((error) => {
65+
if (isDev) {
66+
console.log(error);
67+
}
6168
});
62-
}, [selectedTheme]);
69+
}, []);
70+
useEffect(() => {
71+
if (promptSelectConfig !== null && selectedConfig == -1) {
72+
setSelectedConfig(0);
73+
//selectPrompt(0);
74+
if (isDev) console.log('Saving config', promptSelectConfig[0].config);
75+
saveConfig(promptSelectConfig[0].config);
76+
resetSettings();
77+
}
78+
}, [promptSelectConfig, selectedConfig, saveConfig, resetSettings]);
79+
6380
const { isGenerating, viewingChat } = useAppContext();
6481
const isCurrConvGenerating = isGenerating(viewingChat?.conv.id ?? '');
6582

@@ -87,30 +104,20 @@ export default function Header() {
87104
URL.revokeObjectURL(url);
88105
};
89106

90-
const selectPrompt = (value: string) => {
91-
if (parseInt(value) == -1) {
92-
const newConfig: typeof CONFIG_DEFAULT = JSON.parse(
93-
JSON.stringify(localConfig)
94-
);
95-
if (isDev) console.log('Old config', newConfig);
96-
if (isDev) console.log('Saving config', newConfig);
97-
saveConfig(newConfig);
98-
return;
99-
}
107+
const selectPrompt = (value: number) => {
108+
setSelectedConfig(value);
100109
if (
101110
promptSelectConfig &&
102-
promptSelectConfig[parseInt(value)] &&
103-
promptSelectConfig[parseInt(value)].config
111+
promptSelectConfig[value] &&
112+
promptSelectConfig[value].config
104113
) {
105114
const newConfig: typeof CONFIG_DEFAULT = JSON.parse(
106115
JSON.stringify(localConfig)
107116
);
108117
// validate the config
109-
for (const key in promptSelectConfig[parseInt(value)].config) {
118+
for (const key in promptSelectConfig[value].config) {
110119
const val =
111-
promptSelectConfig[parseInt(value)].config[
112-
key as keyof typeof CONFIG_DEFAULT
113-
];
120+
promptSelectConfig[value].config[key as keyof typeof CONFIG_DEFAULT];
114121
const mustBeBoolean = isBoolean(
115122
CONFIG_DEFAULT[key as keyof typeof CONFIG_DEFAULT]
116123
);
@@ -173,20 +180,6 @@ export default function Header() {
173180
</label>
174181

175182
<div className="grow text-2xl font-bold ml-2">llama.cpp</div>
176-
{promptSelectOptions.length > 1 ? (
177-
<div className="grow text-2xl font-bold ml-2 pl-6 pr-6">
178-
<select
179-
className="select w-full max-w-xs"
180-
onChange={(e) => selectPrompt(e.target.value)}
181-
>
182-
{[...promptSelectOptions].map((opt) => (
183-
<option key={opt.key} value={opt.key}>
184-
{opt.value}
185-
</option>
186-
))}
187-
</select>
188-
</div>
189-
) : null}
190183
{/* action buttons (top right) */}
191184
<div className="flex items-center">
192185
{viewingChat && (
@@ -223,23 +216,64 @@ export default function Header() {
223216
</ul>
224217
</div>
225218
)}
219+
{promptSelectOptions.length > 0 ? (
220+
<div className="tooltip tooltip-bottom" data-tip="Settings">
221+
<div className="dropdown dropdown-end dropdown-bottom">
222+
<div tabIndex={0} role="button" className="btn m-1">
223+
{/* settings button */}
224+
<svg
225+
xmlns="http://www.w3.org/2000/svg"
226+
width="16"
227+
height="16"
228+
fill="currentColor"
229+
className="bi bi-gear"
230+
viewBox="0 0 16 16"
231+
>
232+
<path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492M5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0" />
233+
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115z" />
234+
</svg>
235+
</div>
236+
<ul
237+
tabIndex={0}
238+
className="dropdown-content bg-base-300 rounded-box z-[1] w-52 p-2 shadow-2xl h-80 overflow-y-auto"
239+
>
240+
{[...promptSelectOptions].map((opt) => (
241+
<li key={opt.key}>
242+
<input
243+
type="radio"
244+
name="settings"
245+
className="theme-controller btn btn-sm btn-block btn-ghost justify-start"
246+
aria-label={opt.value}
247+
value={opt.value}
248+
checked={selectedConfig === opt.key}
249+
onChange={(e) =>
250+
e.target.checked && selectPrompt(opt.key)
251+
}
252+
/>
253+
</li>
254+
))}
255+
</ul>
256+
</div>
257+
</div>
258+
) : (
259+
<div className="tooltip tooltip-bottom" data-tip="Settings">
260+
<button className="btn" onClick={() => setShowSettings(true)}>
261+
{/* settings button */}
262+
<svg
263+
xmlns="http://www.w3.org/2000/svg"
264+
width="16"
265+
height="16"
266+
fill="currentColor"
267+
className="bi bi-gear"
268+
viewBox="0 0 16 16"
269+
>
270+
<path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492M5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0" />
271+
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115z" />
272+
</svg>
273+
</button>
274+
</div>
275+
)}
226276

227-
<div className="tooltip tooltip-bottom" data-tip="Settings">
228-
<button className="btn" onClick={() => setShowSettings(true)}>
229-
{/* settings button */}
230-
<svg
231-
xmlns="http://www.w3.org/2000/svg"
232-
width="16"
233-
height="16"
234-
fill="currentColor"
235-
className="bi bi-gear"
236-
viewBox="0 0 16 16"
237-
>
238-
<path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492M5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0" />
239-
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115z" />
240-
</svg>
241-
</button>
242-
</div>
243277
{/* theme controller is copied from https://daisyui.com/components/theme-controller/ */}
244278
<div className="tooltip tooltip-bottom" data-tip="Themes">
245279
<div className="dropdown dropdown-end dropdown-bottom">

0 commit comments

Comments
 (0)