Skip to content

Commit e534e85

Browse files
authored
Merge pull request #80 from code-kern-ai/privatemode-ai
privatemode ai for ac
2 parents ceefe3b + 48bf369 commit e534e85

File tree

9 files changed

+147
-31
lines changed

9 files changed

+147
-31
lines changed

src/components/projects/projectId/attributes/attributeId/AttributeCalculations.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { LLM_CODE_TEMPLATE_EXAMPLES, LLM_CODE_TEMPLATE_OPTIONS } from "./LLM/llm
4141
import KernButton from "@/submodules/react-components/components/kern-button/KernButton";
4242
import { MemoIconAlertTriangleFilled, MemoIconArrowLeft, MemoIconCircleCheckFilled } from "@/submodules/react-components/components/kern-icons/icons";
4343
import { LookupListWithOnClick } from "@/src/types/components/projects/projectId/lookup-lists";
44+
import { InfoButton } from "@/submodules/react-components/components/InfoButton";
4445

4546
const EDITOR_OPTIONS = { theme: 'vs-light', language: 'python', readOnly: false };
4647

@@ -386,10 +387,12 @@ export default function AttributeCalculation() {
386387
selectedOption={(option) => setAdditionalConfigTmp(p => ({ ...p, llmIdentifier: option }))}
387388
disabled={currentAttribute.state == AttributeState.USABLE}
388389
/>
389-
<label className="block text-sm font-medium text-gray-900 whitespace-nowrap">Api Key</label>
390+
<label className={"block text-sm font-medium text-gray-900 whitespace-nowrap" + (additionalConfigTmp?.llmIdentifier != 'Privatemode AI' ? "" : " line-through")}>Api Key</label>
390391

391-
<input type="text" disabled={currentAttribute.state == AttributeState.USABLE} value={additionalConfigTmp?.llmConfig.apiKey || ""} onInput={(e: any) => setAdditionalConfigTmp(p => ({ ...p, llmConfig: { ...additionalConfigTmp.llmConfig, apiKey: e.target.value } }))}
392-
className="h-8 text-sm border-gray-300 rounded-md placeholder-italic w-full border text-gray-700 pl-4 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100 disabled:opacity-50" />
392+
{additionalConfigTmp?.llmIdentifier != 'Privatemode AI' ?
393+
<input type="text" disabled={currentAttribute.state == AttributeState.USABLE} value={additionalConfigTmp?.llmConfig.apiKey || ""} onInput={(e: any) => setAdditionalConfigTmp(p => ({ ...p, llmConfig: { ...additionalConfigTmp.llmConfig, apiKey: e.target.value } }))}
394+
className="h-8 text-sm border-gray-300 rounded-md placeholder-italic w-full border text-gray-700 pl-4 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100 disabled:opacity-50" />
395+
: <InfoButton content="Set in backend" divPosition="right" infoButtonSize="sm" />}
393396
</div>}
394397
</div>
395398
<div className="text-sm leading-5 font-medium text-gray-700 inline-block">Attributes</div>

src/components/projects/projectId/attributes/attributeId/LLM/LLMConfig.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import OpenAI from "./models/OpenAI"
33
import Azure from "./models/Azure"
44
import { LLMConfigProps } from "./types";
55
import AzureFoundry from "./models/AzureFoundry";
6+
import PrivatemodeAi from "./models/PrivatemodeAi";
67

78
export function LLMConfig(props: LLMConfigProps) {
89
switch (props.llmIdentifier) {
@@ -12,6 +13,8 @@ export function LLMConfig(props: LLMConfigProps) {
1213
return <Azure disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} />
1314
case 'Azure Foundry':
1415
return <AzureFoundry disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} />
16+
case 'Privatemode AI':
17+
return <PrivatemodeAi disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} />
1518
default:
1619
return null
1720
}

src/components/projects/projectId/attributes/attributeId/LLM/LLMPlaygroundModal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { jsonCopy } from "@/submodules/javascript-functions/general";
1919
import { TEMPLATE_EXAMPLES, TEMPLATE_OPTIONS } from "./llmTemplates";
2020
import { LLM_PROVIDER_OPTIONS, postProcessLLMPlaygroundRecordData } from "@/src/util/components/projects/projectId/settings/attribute-calculation-helper";
2121
import { MemoIconHandClick, MemoIconPlayCardStar, MemoIconPlayerPlay, MemoIconRefresh, MemoIconTerminal } from "@/submodules/react-components/components/kern-icons/icons";
22+
import { InfoButton } from "@/submodules/react-components/components/InfoButton";
2223

2324
const ACCEPT_BUTTON = { buttonCaption: "Use current values for attribute", useButton: true };
2425
const DISPLAY_STATES = [AttributeState.AUTOMATICALLY_CREATED, AttributeState.UPLOADED, AttributeState.USABLE]
@@ -176,10 +177,12 @@ export default function LLMPlaygroundModal() {
176177
options={LLM_PROVIDER_OPTIONS}
177178
dropdownWidth="w-64"
178179
selectedOption={(option) => setFullLlmConfig(p => ({ ...p, llmIdentifier: option }))}
179-
/><label className="block text-sm font-medium text-gray-900 whitespace-nowrap">Api Key</label>
180+
/><label className={"block text-sm font-medium text-gray-900 whitespace-nowrap" + (fullLlmConfig?.llmIdentifier != 'Privatemode AI' ? "" : " line-through")}>Api Key</label>
180181

181-
<input type="text" value={fullLlmConfig?.llmConfig.apiKey || ""} onInput={(e: any) => setFullLlmConfig(p => ({ ...p, llmConfig: { ...fullLlmConfig.llmConfig, apiKey: e.target.value } }))}
182-
className="h-8 text-sm border-gray-300 rounded-md placeholder-italic w-full border text-gray-700 pl-4 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100" />
182+
{fullLlmConfig?.llmIdentifier != 'Privatemode AI' ?
183+
<input type="text" value={fullLlmConfig?.llmConfig.apiKey || ""} onInput={(e: any) => setFullLlmConfig(p => ({ ...p, llmConfig: { ...fullLlmConfig.llmConfig, apiKey: e.target.value } }))}
184+
className="h-8 text-sm border-gray-300 rounded-md placeholder-italic w-full border text-gray-700 pl-4 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100" />
185+
: <InfoButton content="Set in backend" divPosition="right" infoButtonSize="sm" />}
183186

184187
</div>}
185188
<LLMResponseConfig attributeId={modal.attributeId} fullLlmConfig={fullLlmConfig} setFullLlmConfig={setFullLlmConfig} noPlayground keepConfigOpen />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { useEffect } from "react";
2+
import KernDropdown from "@/submodules/react-components/components/KernDropdown";
3+
import { InfoButton } from "@/submodules/react-components/components/InfoButton";
4+
import { InputWithSlider } from "@/submodules/react-components/components/InputWithSlider";
5+
import { LLmPropsPrivatemodeAI } from "../types";
6+
7+
8+
export const MODEL_MAP_FULL_NAME = {
9+
'Meta-Llama-3.3-70B': "ibnzterrell/Meta-Llama-3.3-70B-Instruct-AWQ-INT4",
10+
'gemma-3-27b': "leon-se/gemma-3-27b-it-fp8-dynamic",
11+
}
12+
const REVERSE_MAP_FULL_NAME = Object.fromEntries(Object.entries(MODEL_MAP_FULL_NAME).map(([key, value]) => [value, key]));
13+
export const MODEL_OPTIONS = Object.keys(MODEL_MAP_FULL_NAME);
14+
const MODEL_MAP_FULL_NAME_OPTIONS = Object.keys(REVERSE_MAP_FULL_NAME);
15+
export default function PrivatemodeAi(props: LLmPropsPrivatemodeAI) {
16+
useEffect(() => {
17+
if (props.llmConfig.model && !MODEL_MAP_FULL_NAME_OPTIONS.includes(props.llmConfig.model)) {
18+
props.setLlmConfig({ ...props.llmConfig, model: MODEL_MAP_FULL_NAME[MODEL_OPTIONS[0]] })
19+
}
20+
}, []);
21+
return (
22+
<div className='flex flex-col'>
23+
{props.onlyEssential ?
24+
null : <div className="mb-2 flex items-center">
25+
<span className="text-sm font-medium text-gray-900 line-through">API Key </span>
26+
<InfoButton content="Set in backend" divPosition="right" infoButtonSize="sm" />
27+
</div>}
28+
<div>
29+
<label className="block mb-2 text-sm font-medium text-gray-900">Model</label>
30+
<KernDropdown
31+
buttonName={props.llmConfig.model ? REVERSE_MAP_FULL_NAME[props.llmConfig.model] : 'Select model'}
32+
options={MODEL_OPTIONS}
33+
selectedOption={(option) => props.setLlmConfig({ ...props.llmConfig, model: MODEL_MAP_FULL_NAME[option] })}
34+
disabled={props.disabled}
35+
/>
36+
</div>
37+
{props.onlyEssential ? null : <>
38+
<InputWithSlider
39+
label="Temperature"
40+
value={props.llmConfig.temperature}
41+
min={0}
42+
max={2}
43+
step={0.01}
44+
onChange={(value) => props.setLlmConfig({ ...props.llmConfig, temperature: value })}
45+
disabled={props.disabled}
46+
/>
47+
48+
<InputWithSlider
49+
label="Top P"
50+
value={props.llmConfig.topP}
51+
min={0}
52+
max={1}
53+
step={0.01}
54+
onChange={(value) => props.setLlmConfig({ ...props.llmConfig, topP: value })}
55+
disabled={props.disabled}
56+
/>
57+
<InputWithSlider
58+
label='Frequency penalty'
59+
value={props.llmConfig.frequencyPenalty}
60+
min={-2}
61+
max={2}
62+
step={0.01}
63+
onChange={(value) => props.setLlmConfig({ ...props.llmConfig, frequencyPenalty: value })}
64+
disabled={props.disabled}
65+
/>
66+
<InputWithSlider
67+
label='Presence penalty'
68+
value={props.llmConfig.presencePenalty}
69+
min={-2}
70+
max={2}
71+
step={0.01}
72+
onChange={(value) => props.setLlmConfig({ ...props.llmConfig, presencePenalty: value })}
73+
disabled={props.disabled}
74+
/>
75+
</>}
76+
77+
</div>
78+
)
79+
}

src/components/projects/projectId/attributes/attributeId/LLM/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export type LLmPropsOpenAI = {
3030
disabled?: boolean;
3131
}
3232

33+
export type LLmPropsPrivatemodeAI = {
34+
llmConfig: any;
35+
setLlmConfig: (llmConfig: any) => void;
36+
onlyEssential?: boolean;
37+
projectId?: string;
38+
disabled?: boolean;
39+
}
40+
3341

3442
export type LLmPropsAzure = {
3543
llmConfig: any;

src/components/projects/projectId/settings/embeddings/AddNewEmbeddingModal.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function AddNewEmbeddingModal() {
5656

5757
useEffect(() => {
5858
prepareSuggestions();
59-
checkIfPlatformHasToken();
59+
// checkIfPlatformHasToken();
6060
}, []);
6161

6262
useEffect(() => {
@@ -84,7 +84,7 @@ export default function AddNewEmbeddingModal() {
8484
const suggestionListFiltered = suggestionList.map((suggestion: any) => {
8585
const suggestionCopy = { ...suggestion };
8686
const applicability = JSON.parse(suggestionCopy.applicability);
87-
if ((granularity.value == EmbeddingType.ON_ATTRIBUTE && applicability.attribute) || (granularity.value == EmbeddingType.ON_TOKEN && applicability.token)) {
87+
if ((granularity.value == EmbeddingType.ON_ATTRIBUTE && applicability.attribute) /*|| (granularity.value == EmbeddingType.ON_TOKEN && applicability.token)*/) {
8888
suggestionCopy.forceHidden = false;
8989
} else {
9090
suggestionCopy.forceHidden = true;
@@ -99,11 +99,13 @@ export default function AddNewEmbeddingModal() {
9999

100100
function checkIfAttributeHasToken() {
101101
const attribute = useableEmbedableAttributes.find((a) => a.id == targetAttribute.id);
102-
if (attribute?.dataType == DataTypeEnum.EMBEDDING_LIST) {
103-
setGranularityArray(GRANULARITY_TYPES_ARRAY.filter((g) => g.value != EmbeddingType.ON_TOKEN));
104-
} else {
105-
checkIfPlatformHasToken();
106-
}
102+
setGranularityArray(GRANULARITY_TYPES_ARRAY);
103+
104+
// if (attribute?.dataType == DataTypeEnum.EMBEDDING_LIST) {
105+
// setGranularityArray(GRANULARITY_TYPES_ARRAY.filter((g) => g.value != EmbeddingType.ON_TOKEN));
106+
// } else {
107+
// checkIfPlatformHasToken();
108+
// }
107109
}
108110

109111
function changePlatformOrGranularity() {
@@ -131,18 +133,20 @@ export default function AddNewEmbeddingModal() {
131133
acceptButtonCopy.disabled = checkIfCreateEmbeddingIsDisabled({ platform, model, apiToken, termsAccepted, embeddings, targetAttribute, granularity, engine, url, version, embeddingPlatforms });
132134
setAcceptButton(acceptButtonCopy);
133135
setTermsAccepted(false);
134-
setModel(null);
136+
if (savePlatform == PlatformType.PRIVATEMODE_AI) {
137+
setModel("intfloat/multilingual-e5-large-instruct");
138+
} else setModel(null);
135139
setApiToken('');
136140
}
137141

138-
function checkIfPlatformHasToken() {
139-
if (!platform) return;
140-
if (platform.name == platformNamesDict[PlatformType.OPEN_AI] || platform.name == platformNamesDict[PlatformType.AZURE]) {
141-
setGranularityArray(GRANULARITY_TYPES_ARRAY.filter((g) => g.value != EmbeddingType.ON_TOKEN));
142-
} else {
143-
setGranularityArray(GRANULARITY_TYPES_ARRAY);
144-
}
145-
}
142+
// function checkIfPlatformHasToken() {
143+
// if (!platform) return;
144+
// if (platform.name == platformNamesDict[PlatformType.OPEN_AI] || platform.name == platformNamesDict[PlatformType.AZURE]) {
145+
// setGranularityArray(GRANULARITY_TYPES_ARRAY.filter((g) => g.value != EmbeddingType.ON_TOKEN));
146+
// } else {
147+
// setGranularityArray(GRANULARITY_TYPES_ARRAY);
148+
// }
149+
// }
146150

147151
const prepareAzureData = useCallback(() => {
148152
const getAzureUrl = localStorage.getItem('azureUrls');
@@ -175,7 +179,8 @@ export default function AddNewEmbeddingModal() {
175179
platform: platform.platform,
176180
termsText: gdprText.current != null ? gdprText.current.innerText : null,
177181
termsAccepted: termsAccepted,
178-
embeddingType: granularity.value == EmbeddingType.ON_TOKEN ? EmbeddingType.ON_TOKEN : EmbeddingType.ON_ATTRIBUTE,
182+
// embeddingType: granularity.value == EmbeddingType.ON_TOKEN ? EmbeddingType.ON_TOKEN : EmbeddingType.ON_ATTRIBUTE,
183+
embeddingType: EmbeddingType.ON_ATTRIBUTE,
179184
filterAttributes: filteredAttributes
180185
}
181186

@@ -191,6 +196,8 @@ export default function AddNewEmbeddingModal() {
191196
config.type = DEFAULT_AZURE_TYPE;
192197
config.version = version;
193198
prepareAzureData();
199+
} else if (platform.name == platformNamesDict[PlatformType.PRIVATEMODE_AI]) {
200+
config.model = model;
194201
}
195202
createEmbeddingPost(projectId, targetAttribute.id, JSON.stringify(config), (res) => { });
196203

@@ -290,13 +297,20 @@ export default function AddNewEmbeddingModal() {
290297
<SuggestionsAzure options={azureVersions} selectedOption={(option: string) => setVersion(option)} name="Version" tooltip="The latest version of the Azure OpenAI service can also be found here." />
291298
</>}
292299
</>}
300+
{platform && platform.name == platformNamesDict[PlatformType.PRIVATEMODE_AI] && <>
301+
<Tooltip content={TOOLTIPS_DICT.PROJECT_SETTINGS.EMBEDDINGS.MODEL} placement="right" color="invert">
302+
<span className="card-title mb-0 label-text flex"><span className="cursor-help underline filtersUnderline">Model</span></span>
303+
</Tooltip>
304+
<input defaultValue="intfloat/multilingual-e5-large-instruct" disabled className="h-9 w-full text-sm border-gray-300 rounded-md placeholder-italic border text-gray-900 pl-4 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100 disabled:opacity-50" />
305+
</>}
293306
</div>
294-
{platform && (platform.name == platformNamesDict[PlatformType.OPEN_AI] || platform.name == platformNamesDict[PlatformType.AZURE]) && <div className="text-center mt-3">
307+
{platform && (platform.name == platformNamesDict[PlatformType.OPEN_AI] || platform.name == platformNamesDict[PlatformType.AZURE] || platform.name == platformNamesDict[PlatformType.PRIVATEMODE_AI]) && <div className="text-center mt-3">
295308
<div className="border border-gray-300 text-xs text-gray-500 p-2.5 rounded-lg text-justify">
296309
<label ref={gdprText} className="text-gray-700">
297310
{selectedPlatform.splitTerms[0]}
298311
{platform.name == platformNamesDict[PlatformType.OPEN_AI] && <a href={selectedPlatform.link} target="_blank" className="underline">openai terms of service.</a>}
299312
{platform.name == platformNamesDict[PlatformType.AZURE] && <a href={selectedPlatform.link} target="_blank" className="underline">azure terms of service.</a>}
313+
{platform.name == platformNamesDict[PlatformType.PRIVATEMODE_AI] && <a href={selectedPlatform.link} target="_blank" className="underline">private mode ai terms of service.</a>}
300314
<div>{selectedPlatform.splitTerms[1]}</div>
301315
</label>
302316
</div>

src/types/components/projects/projectId/settings/embeddings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type EmbeddingWithOnClick = Embedding & {
3131

3232
export enum EmbeddingType {
3333
ON_ATTRIBUTE = "ON_ATTRIBUTE",
34-
ON_TOKEN = "ON_TOKEN"
34+
// ON_TOKEN = "ON_TOKEN" //currently removed since it doesn't seem to be used but kept code wise for easy reenabling
3535
};
3636

3737
export type EmbeddingPlatform = {
@@ -46,7 +46,8 @@ export type EmbeddingPlatform = {
4646
export enum PlatformType {
4747
HUGGING_FACE = "huggingface",
4848
OPEN_AI = "openai",
49-
AZURE = "azure"
49+
AZURE = "azure",
50+
PRIVATEMODE_AI = "privatemode-ai"
5051
}
5152

5253
export type RecommendedEncoder = {

src/util/components/projects/projectId/settings/attribute-calculation-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export function postProcessRecordByRecordId(record: Record): Record {
4747
export const LLM_PROVIDER_OPTIONS = [
4848
'Open AI',
4949
'Azure',
50-
'Azure Foundry'
50+
'Azure Foundry',
51+
'Privatemode AI'
5152
];
5253

5354
export function postProcessLLMPlaygroundRecordData(recordList: any[]): any[] {

0 commit comments

Comments
 (0)