Skip to content

Commit e72aba6

Browse files
committed
Add prompt caching to OpenAI-compatible custom model info
1 parent edb53bf commit e72aba6

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.changeset/thin-fans-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Add prompt caching to OpenAI-compatible custom model info

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,29 @@ const ApiOptions = ({
847847
</div>
848848
</div>
849849

850+
<div>
851+
<div className="flex items-center gap-1">
852+
<Checkbox
853+
checked={apiConfiguration?.openAiCustomModelInfo?.supportsPromptCache ?? false}
854+
onChange={handleInputChange("openAiCustomModelInfo", (checked) => {
855+
return {
856+
...(apiConfiguration?.openAiCustomModelInfo || openAiModelInfoSaneDefaults),
857+
supportsPromptCache: checked,
858+
}
859+
})}>
860+
<span className="font-medium">Prompt Caching</span>
861+
</Checkbox>
862+
<i
863+
className="codicon codicon-info text-vscode-descriptionForeground"
864+
title="Enable if the model supports prompt caching. This can improve performance and reduce costs."
865+
style={{ fontSize: "12px" }}
866+
/>
867+
</div>
868+
<div className="text-sm text-vscode-descriptionForeground [pt">
869+
Is this model capable of caching prompts?
870+
</div>
871+
</div>
872+
850873
<div>
851874
<VSCodeTextField
852875
value={
@@ -933,6 +956,93 @@ const ApiOptions = ({
933956
</VSCodeTextField>
934957
</div>
935958

959+
{apiConfiguration?.openAiCustomModelInfo?.supportsPromptCache && (
960+
<>
961+
<div>
962+
<VSCodeTextField
963+
value={
964+
apiConfiguration?.openAiCustomModelInfo?.cacheReadsPrice?.toString() ?? "0"
965+
}
966+
type="text"
967+
style={{
968+
borderColor: (() => {
969+
const value = apiConfiguration?.openAiCustomModelInfo?.cacheReadsPrice
970+
971+
if (!value && value !== 0) {
972+
return "var(--vscode-input-border)"
973+
}
974+
975+
return value >= 0
976+
? "var(--vscode-charts-green)"
977+
: "var(--vscode-errorForeground)"
978+
})(),
979+
}}
980+
onChange={handleInputChange("openAiCustomModelInfo", (e) => {
981+
const value = (e.target as HTMLInputElement).value
982+
const parsed = parseFloat(value)
983+
984+
return {
985+
...(apiConfiguration?.openAiCustomModelInfo ??
986+
openAiModelInfoSaneDefaults),
987+
cacheReadsPrice: isNaN(parsed) ? 0 : parsed,
988+
}
989+
})}
990+
placeholder="e.g. 0.0001"
991+
className="w-full">
992+
<div className="flex items-center gap-1">
993+
<span className="font-medium">Cache Reads Price</span>
994+
<i
995+
className="codicon codicon-info text-vscode-descriptionForeground"
996+
title="Cost per million tokens for reading from the cache. This is the price charged when a cached response is retrieved."
997+
style={{ fontSize: "12px" }}
998+
/>
999+
</div>
1000+
</VSCodeTextField>
1001+
</div>
1002+
<div>
1003+
<VSCodeTextField
1004+
value={
1005+
apiConfiguration?.openAiCustomModelInfo?.cacheWritesPrice?.toString() ?? "0"
1006+
}
1007+
type="text"
1008+
style={{
1009+
borderColor: (() => {
1010+
const value = apiConfiguration?.openAiCustomModelInfo?.cacheWritesPrice
1011+
1012+
if (!value && value !== 0) {
1013+
return "var(--vscode-input-border)"
1014+
}
1015+
1016+
return value >= 0
1017+
? "var(--vscode-charts-green)"
1018+
: "var(--vscode-errorForeground)"
1019+
})(),
1020+
}}
1021+
onChange={handleInputChange("openAiCustomModelInfo", (e) => {
1022+
const value = (e.target as HTMLInputElement).value
1023+
const parsed = parseFloat(value)
1024+
1025+
return {
1026+
...(apiConfiguration?.openAiCustomModelInfo ??
1027+
openAiModelInfoSaneDefaults),
1028+
cacheWritesPrice: isNaN(parsed) ? 0 : parsed,
1029+
}
1030+
})}
1031+
placeholder="e.g. 0.00005"
1032+
className="w-full">
1033+
<div className="flex items-center gap-1">
1034+
<span className="font-medium">Cache Writes Price</span>
1035+
<i
1036+
className="codicon codicon-info text-vscode-descriptionForeground"
1037+
title="Cost per million tokens for writing to the cache. This is the price charged when a prompt is cached for the first time."
1038+
style={{ fontSize: "12px" }}
1039+
/>
1040+
</div>
1041+
</VSCodeTextField>
1042+
</div>
1043+
</>
1044+
)}
1045+
9361046
<Button
9371047
variant="secondary"
9381048
onClick={() =>

0 commit comments

Comments
 (0)