Skip to content

Commit 4fb516f

Browse files
authored
Merge pull request #71 from code-kern-ai/o-series-ac
Adds o-series support flag
2 parents cbc1a5d + 3ad2591 commit 4fb516f

File tree

9 files changed

+76
-27
lines changed

9 files changed

+76
-27
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ export default function AttributeCalculation() {
156156
useEffect(() => {
157157
if (!currentAttributeRef.current || !currentAttributeRef.current.additionalConfig || simpleDictCompare(currentAttributeRef.current?.additionalConfig, debouncedConfig)) return;
158158
const attributeNew = { ...currentAttribute };
159-
attributeNew.additionalConfig = { ...debouncedConfig };
159+
const finalConfig = { ...debouncedConfig };
160+
if (finalConfig.llmConfig && finalConfig.llmIdentifier == 'Azure Foundry') {
161+
delete finalConfig.llmConfig.openAioSeries;
162+
}
163+
attributeNew.additionalConfig = { ...finalConfig };
160164
updateAttribute(projectId, currentAttribute.id, (res) => {
161165
setCurrentAttribute(postProcessCurrentAttribute(attributeNew));
162166
dispatch(updateAttributeById(attributeNew));
163167
setEnableButton(true);
164-
}, null, null, null, null, null, debouncedConfig);
168+
}, null, null, null, null, null, finalConfig);
165169

166170
}, [debouncedConfig])
167171

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import AzureFoundry from "./models/AzureFoundry";
77
export function LLMConfig(props: LLMConfigProps) {
88
switch (props.llmIdentifier) {
99
case 'Open AI':
10-
return <OpenAI disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} isVision={props.isVision} />
10+
return <OpenAI disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} />
1111
case 'Azure':
1212
return <Azure disabled={props.disabled} llmConfig={props.llmConfig} setLlmConfig={props.setLlmConfig} onlyEssential={props.onlyEssential} projectId={props.projectId} />
1313
case 'Azure Foundry':

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ export default function LLMPlaygroundModal() {
7474
if (!recordDataRef.current || recordDataRef.current?.length == 0) return;
7575
setPlaygroundTestRunning(true);
7676
const recordIds = recordDataRef.current.map((record) => record.id);
77-
runAttributeLlmPlayground(projectId, modalRef.current.attributeId, recordIds, fullLlmConfigRef.current, (res) => {
77+
78+
const finalConfig = { ...fullLlmConfigRef.current };
79+
if (finalConfig.llmConfig && finalConfig.llmIdentifier == 'Azure Foundry') {
80+
delete finalConfig.llmConfig.openAioSeries;
81+
}
82+
runAttributeLlmPlayground(projectId, modalRef.current.attributeId, recordIds, finalConfig, (res) => {
7883
let answer = ""
7984
for (const id of recordIds) answer += "Answer: " + (res[id] || "No answer found") + "\n";
8085
if (res["logs"]) answer += "\n---\nlogs:\n" + res["logs"].join("\n");

src/components/projects/projectId/attributes/attributeId/LLM/models/Azure.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect } from "react";
22
import { LocalStorageDropdown } from "@/submodules/react-components/components/LocalStorageDropdown";
33
import { InputWithSlider } from "@/submodules/react-components/components/InputWithSlider";
44
import { LLmPropsAzure } from "../types";
5+
import OpenAIoSeriesSwitch from "./OpenAIoSeriesSwitch";
56

67

78
export default function Azure(props: LLmPropsAzure) {
@@ -25,10 +26,14 @@ export default function Azure(props: LLmPropsAzure) {
2526
<label className="block mb-2 text-sm font-medium text-gray-900">Azure URL</label>
2627
<LocalStorageDropdown disabled={props.disabled} buttonName={props.llmConfig.apiBase ?? 'Select URL'} searchDefaultValue={props.llmConfig.apiBase} storageKey='AzureApiBase' onOptionSelected={(o) => props.setLlmConfig({ ...props.llmConfig, apiBase: o })} />
2728
</div>
28-
<div>
29+
<div className="-mb-5">
2930
<label className="block mb-2 text-sm font-medium text-gray-900">API Version</label>
3031
<LocalStorageDropdown disabled={props.disabled} buttonName={props.llmConfig.apiVersion ?? 'Select Version'} searchDefaultValue={props.llmConfig.apiVersion} storageKey='AzureVersion' onOptionSelected={(o) => props.setLlmConfig({ ...props.llmConfig, apiVersion: o })} />
3132
</div>
33+
<OpenAIoSeriesSwitch
34+
llmConfig={props.llmConfig}
35+
setLlmConfig={props.setLlmConfig}
36+
/>
3237
{props.onlyEssential ? null : <>
3338

3439
<div className="grid grid-cols-2 xl:grid-cols-3 gap-2">

src/components/projects/projectId/attributes/attributeId/LLM/models/OpenAI.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import { useEffect } from "react";
22
import KernDropdown from "@/submodules/react-components/components/KernDropdown";
33
import { InputWithSlider } from "@/submodules/react-components/components/InputWithSlider";
44
import { LLmPropsOpenAI } from "../types";
5+
import OpenAIoSeriesSwitch from "./OpenAIoSeriesSwitch";
56

67

78

89
// https://platform.openai.com/docs/models
9-
const MODEL_OPTIONS = ['gpt-4o-mini', 'gpt-4o', 'gpt-4', 'gpt-4-turbo-preview', 'gpt-4-1106-preview', 'gpt-4-0125-preview', 'gpt-4-turbo', 'gpt-3.5-turbo']
10-
const VISION_MODEL_OPTIONS = ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini']
1110
const MAX_LENGTH = {
11+
'gpt-4o-mini': 16384,
1212
'gpt-3.5-turbo': 16385,
1313
'gpt-4': 8192,
14-
'gpt-4-turbo': 128000,
15-
'gpt-4-turbo-preview': 128000,
16-
'gpt-4-1106-preview': 128000,
17-
'gpt-4-0125-preview': 128000,
18-
'gpt-4o': 128000,
19-
'gpt-4o-mini': 128000,
14+
'gpt-4-turbo': 4096,
15+
'gpt-4o': 16384,
16+
'o1': 100000,
17+
'o1-mini': 65536,
18+
'o3-mini': 100000,
2019
}
20+
const MODEL_OPTIONS = Object.keys(MAX_LENGTH);
2121

2222
export default function OpenAI(props: LLmPropsOpenAI) {
2323

@@ -29,27 +29,24 @@ export default function OpenAI(props: LLmPropsOpenAI) {
2929
}, [props.llmConfig.model])
3030

3131
useEffect(() => {
32-
if (props.isVision) {
33-
if (props.llmConfig.model && !VISION_MODEL_OPTIONS.includes(props.llmConfig.model)) {
34-
props.setLlmConfig({ ...props.llmConfig, model: VISION_MODEL_OPTIONS[0] })
35-
}
36-
} else {
37-
if (props.llmConfig.model && !MODEL_OPTIONS.includes(props.llmConfig.model)) {
38-
props.setLlmConfig({ ...props.llmConfig, model: MODEL_OPTIONS[0] })
39-
}
32+
if (props.llmConfig.model && !MODEL_OPTIONS.includes(props.llmConfig.model)) {
33+
props.setLlmConfig({ ...props.llmConfig, model: MODEL_OPTIONS[0] })
4034
}
4135
}, [])
42-
4336
return (
4437
<div className='flex flex-col gap-y-6'>
4538
<div>
4639
<label className="block mb-2 text-sm font-medium text-gray-900">Model</label>
4740
<KernDropdown
4841
buttonName={props.llmConfig.model ? props.llmConfig.model : 'Select model'}
49-
options={props.isVision ? VISION_MODEL_OPTIONS : MODEL_OPTIONS}
42+
options={MODEL_OPTIONS}
5043
selectedOption={(option) => props.setLlmConfig({ ...props.llmConfig, model: option })}
5144
disabled={props.disabled}
5245
/>
46+
<OpenAIoSeriesSwitch
47+
llmConfig={props.llmConfig}
48+
setLlmConfig={props.setLlmConfig}
49+
/>
5350
</div>
5451
{props.onlyEssential ? null : <>
5552

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { combineClassNames } from "@/submodules/javascript-functions/general"
2+
import { InfoButton } from "@/submodules/react-components/components/InfoButton"
3+
import { Switch } from "@headlessui/react"
4+
import { OpenAIoSeriesSwitchProps } from "../types"
5+
6+
7+
export default function OpenAIoSeriesSwitch(props: OpenAIoSeriesSwitchProps) {
8+
return <div className="flex flex-row gap-x-2 items-center">
9+
<Switch.Group as="div" className="flex items-center justify-between">
10+
<span className="flex flex-row gap-x-1 items-center">
11+
<Switch.Description as="span" className="text-sm font-medium text-gray-700 mr-2">
12+
o model series
13+
</Switch.Description>
14+
15+
</span>
16+
<Switch
17+
checked={props.llmConfig.openAioSeries || false}
18+
onChange={(value) => props.setLlmConfig({ ...props.llmConfig, openAioSeries: value })}
19+
className={combineClassNames(
20+
props.llmConfig.openAioSeries ? 'bg-blue-600' : 'bg-gray-200',
21+
'relative inline-flex h-4 w-7 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-bg-blue-600 focus:ring-offset-2')}
22+
>
23+
<span
24+
aria-hidden="true"
25+
className={combineClassNames(
26+
props.llmConfig.openAioSeries ? 'translate-x-3' : 'translate-x-0',
27+
'pointer-events-none inline-block h-3 w-3 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out'
28+
)}
29+
/>
30+
</Switch>
31+
</Switch.Group>
32+
<InfoButton content="Open AI models of the o series (e.g. o1 & o3) use e.g. max_completion_token instead of max_token and no temperature" divPosition="right" infoButtonSize="sm" />
33+
</div>
34+
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export type LLMConfigProps = {
1818
setLlmConfig: (llmConfig: any) => void,
1919
onlyEssential?: boolean,
2020
projectId?: string,
21-
isVision?: boolean,
2221
disabled?: boolean,
2322
}
2423

@@ -28,7 +27,6 @@ export type LLmPropsOpenAI = {
2827
setLlmConfig: (llmConfig: any) => void;
2928
onlyEssential?: boolean;
3029
projectId?: string;
31-
isVision?: boolean;
3230
disabled?: boolean;
3331
}
3432

@@ -40,4 +38,9 @@ export type LLmPropsAzure = {
4038
projectId?: string;
4139
disabled?: boolean;
4240
}
43-
export type LLmPropsAzureFoundry = LLmPropsAzure;
41+
export type LLmPropsAzureFoundry = LLmPropsAzure;
42+
43+
export type OpenAIoSeriesSwitchProps = {
44+
llmConfig: any;
45+
setLlmConfig: (llmConfig: any) => void;
46+
}

src/types/components/projects/projectId/settings/data-schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type LLMConfig = {
1818
apiKey: string;
1919
apiVersion?: string, //only for azure
2020
endpoint?: string, //only for azure
21+
openAioSeries?: boolean; //only for openai models
2122
}
2223
}
2324

0 commit comments

Comments
 (0)