Skip to content
Merged

Wip #112

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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ venv/
ENV/
env.bak/
venv.bak/
myenv/

# IDE
.vscode/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- liquibase formatted sql

-- changeset Erangi Ariyasena:rag-script-v5-changeset1
CREATE TABLE public.prompt_configuration (
id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
prompt TEXT
);

4 changes: 3 additions & 1 deletion DSL/Liquibase/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ databaseChangeLog:
- include:
file: changelog/rag-search-script-v3-configuration.sql
- include:
file: changelog/rag-search-script-v4-authority-data.xml
file: changelog/rag-search-script-v4-authority-data.xml
- include:
file: changelog/rag-search-script-v5-prompt-config.sql
5 changes: 5 additions & 0 deletions DSL/Resql/rag-search/GET/get-prompt-configuration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
id,
prompt
FROM prompt_configuration
LIMIT 1
3 changes: 3 additions & 0 deletions DSL/Resql/rag-search/POST/insert-prompt-configuration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INSERT INTO prompt_configuration (prompt)
VALUES (:prompt)
RETURNING id, prompt
4 changes: 4 additions & 0 deletions DSL/Resql/rag-search/POST/update-prompt-configuration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
UPDATE prompt_configuration
SET prompt = :prompt
WHERE id = :id
RETURNING id, prompt
39 changes: 39 additions & 0 deletions DSL/Ruuter.private/rag-search/GET/prompt-configuration/get.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
declaration:
call: declare
version: 0.1
description: "Get prompt configuration"
method: get
accepts: json
returns: json
namespace: rag-search

get_prompt_configuration:
call: http.get
args:
url: "[#RAG_SEARCH_RESQL]/get-prompt-configuration"
result: prompt_result
next: check_prompt_exists

check_prompt_exists:
switch:
- condition: "${prompt_result.response.body.length > 0}"
next: transform_response
next: transform_empty_response

transform_response:
assign:
data: ${prompt_result.response.body}
next: return_success

transform_empty_response:
assign:
emptyData: []
next: return_empty

return_success:
return: ${data}
next: end

return_empty:
return: ${emptyData}
next: end
33 changes: 31 additions & 2 deletions DSL/Ruuter.private/rag-search/POST/llm-connections/edit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,38 @@ check_connection_exists:
validate_connection_exists:
switch:
- condition: "${existing_connection.response.body.length > 0}"
next: update_llm_connection
next: check_deployment_environment
next: return_not_found

check_deployment_environment:
switch:
- condition: ${environment == "production" && existing_connection.response.body[0].environment == "testing"}
next: get_existing_production_connection
next: update_llm_connection

get_existing_production_connection:
call: http.post
args:
url: "[#RAG_SEARCH_RESQL]/get-production-connection"
result: existing_production_result
next: update_existing_production_to_testing

update_existing_production_to_testing:
switch:
- condition: ${existing_production_result.response.body && existing_production_result.response.body.length > 0}
next: update_production_connection
next: update_llm_connection

update_production_connection:
call: http.post
args:
url: "[#RAG_SEARCH_RESQL]/update-llm-connection-environment"
body:
connection_id: ${existing_production_result.response.body[0].id}
environment: "testing"
result: update_result
next: update_llm_connection

update_llm_connection:
call: http.post
args:
Expand Down Expand Up @@ -169,4 +198,4 @@ return_invalid_environment:
return_unauthorized:
status: 401
return: "error: unauthorized"
next: end
next: end
58 changes: 58 additions & 0 deletions DSL/Ruuter.private/rag-search/POST/prompt-configuration/save.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
declaration:
call: declare
version: 0.1
description: "Update or insert prompt configuration"
method: post
accepts: json
returns: json
namespace: rag-search
allowlist:
body:
- field: prompt
type: string
description: "Prompt text to save"

extract_request_data:
assign:
prompt: ${incoming.body.prompt ?? ""}
next: get_existing_prompt

get_existing_prompt:
call: http.get
args:
url: "[#RAG_SEARCH_RESQL]/get-prompt-configuration"
result: existing_prompt
next: check_if_exists

check_if_exists:
switch:
- condition: "${existing_prompt.response.body.length > 0}"
next: update_prompt
next: insert_prompt

update_prompt:
call: http.post
args:
url: "[#RAG_SEARCH_RESQL]/update-prompt-configuration"
body:
id: ${existing_prompt.response.body[0].id}
prompt: ${prompt}
result: update_result
next: return_update_success

insert_prompt:
call: http.post
args:
url: "[#RAG_SEARCH_RESQL]/insert-prompt-configuration"
body:
prompt: ${prompt}
result: insert_result
next: return_insert_success

return_update_success:
return: ${update_result.response.body[0]}
next: end

return_insert_success:
return: ${insert_result.response.body[0]}
next: end
2 changes: 1 addition & 1 deletion DSL/Ruuter.private/rag-search/POST/vault/secret/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declaration:
method: post
accepts: json
returns: json
namespace: classifier
namespace: rag-search
allowlist:
body:
- field: connectionId
Expand Down
2 changes: 1 addition & 1 deletion DSL/Ruuter.private/rag-search/POST/vault/secret/delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declaration:
method: post
accepts: json
returns: json
namespace: classifier
namespace: rag-search
allowlist:
body:
- field: connectionId
Expand Down
2 changes: 2 additions & 0 deletions GUI/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ViewLLMConnection from 'pages/LLMConnections/ViewLLMConnection';
import UserManagement from 'pages/UserManagement';
import TestLLM from 'pages/TestModel';
import TestProductionLLM from 'pages/TestProductionLLM';
import PromptConfigurations from 'pages/PromptConfigurations';

const App: FC = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -62,6 +63,7 @@ const App: FC = () => {
<Route path="/llm-connections" element={<LLMConnections />} />
<Route path="/create-llm-connection" element={<CreateLLMConnection />} />
<Route path="/view-llm-connection" element={<ViewLLMConnection />} />
<Route path="/prompt-configurations" element={<PromptConfigurations />} />
<Route path="/test-llm" element={<TestLLM />} />
<Route path="/test-production-llm" element={<TestProductionLLM />} />

Expand Down
10 changes: 6 additions & 4 deletions GUI/src/components/FormElements/FormSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ const FormSelect = forwardRef<HTMLSelectElement, FormSelectProps>(
itemToString,
selectedItem,
onSelectedItemChange: ({ selectedItem: newSelectedItem }) => {
setSelectedItem(newSelectedItem ?? null);
if (onSelectionChange) onSelectionChange(newSelectedItem ?? null);
if (!disabled) {
setSelectedItem(newSelectedItem ?? null);
if (onSelectionChange) onSelectionChange(newSelectedItem ?? null);
}
},
});

Expand All @@ -109,7 +111,7 @@ const FormSelect = forwardRef<HTMLSelectElement, FormSelectProps>(
className={`select__trigger ${
error ? `select__error` : `select__default`
}`}
{...getToggleButtonProps()}
{...getToggleButtonProps({ disabled })}
>
{selectedItem?.label ?? placeholderValue}
<Icon
Expand Down Expand Up @@ -145,4 +147,4 @@ const FormSelect = forwardRef<HTMLSelectElement, FormSelectProps>(
}
);

export default FormSelect;
export default FormSelect;
16 changes: 13 additions & 3 deletions GUI/src/components/MainNavigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ const MainNavigation: FC = () => {
},
{
id: 'llmConnections',
label: t('menu.llmConnections'),
path: '/llm-connections',
label: t('menu.llmConnections._self'),
path: '',
icon: <MdOutlineDataset />,
children: [
{
label: t('menu.llmConnections.overview'),
path: '/llm-connections',
},
{
label: t('menu.llmConnections.promptConfigurations'),
path: '/prompt-configurations',
}
],
},
{
id: 'testLLM',
Expand All @@ -37,7 +47,7 @@ const MainNavigation: FC = () => {
},
{
id: 'testProductionLLM',
label: 'Test Production LLM',
label: t('menu.testProductionLLM'),
path: '/test-production-llm',
icon: <MdSearch />
}
Expand Down
43 changes: 43 additions & 0 deletions GUI/src/components/molecules/LLMConnectionCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type LLMConnectionCardProps = {
isActive?: boolean;
deploymentEnv?: string;
budgetStatus?: string;
usedBudget?: number;
monthlyBudget?: number;
stopBudgetThreshold?: number;
disconnectOnBudgetExceed?: boolean;
onStatusChange?: (id: number | string, newStatus: boolean) => void;
};

Expand All @@ -32,6 +36,10 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
isActive,
deploymentEnv,
budgetStatus,
usedBudget,
monthlyBudget,
stopBudgetThreshold,
disconnectOnBudgetExceed,
onStatusChange,
}) => {
const { open, close } = useDialog();
Expand All @@ -40,6 +48,31 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
const toast = useToast();
const queryClient = useQueryClient();

// Format currency
const formatCurrency = (amount?: number): string => {
if (amount === undefined || amount === null) {
return '0,00 €';
}

return new Intl.NumberFormat('et-EE', {
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amount);
};


// Get the relevant budget threshold
const getRelevantBudget = (): number | undefined => {
// here if disconnect on budget exceed is enabled and stop threshold is set, calculate the actual amount from percentage
if (disconnectOnBudgetExceed && stopBudgetThreshold && stopBudgetThreshold > 0 && monthlyBudget) {
return (monthlyBudget * stopBudgetThreshold) / 100;
}
// Otherwise using monthly budget
return monthlyBudget;
};

const updateStatusMutation = useMutation({
mutationFn: ({ id, status }: { id: string | number; status: 'active' | 'inactive' }) =>
updateLLMConnectionStatus(id, status),
Expand Down Expand Up @@ -145,6 +178,16 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
</span>
<span className="label-value">{model ?? 'N/A'}</span>
</div>
{(usedBudget !== undefined || monthlyBudget !== undefined) && (
<div className="label-row">
<span className="label-title">
{t('dataModels.budgetUsage')}:
</span>
<span className="label-value">
{formatCurrency(usedBudget)} / {formatCurrency(getRelevantBudget())}
</span>
</div>
)}
<div className='label-row'>
{renderDeploymentEnv(deploymentEnv)}
{renderBudgetStatus(budgetStatus)}
Expand Down
Loading
Loading