-
Notifications
You must be signed in to change notification settings - Fork 4
Prompt config module #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt config module #218
Changes from all commits
f635768
b674b5e
9fec475
9caa51d
49a78eb
e8af3fa
dd3fa8b
023d53a
6e7e45f
620af8c
509d0f0
c6351eb
30f05bb
8b54764
7b1c830
4fe08d1
9af1a1e
6e5234c
6830670
a416995
0352184
925af1c
b584e44
ce0916d
6f95769
5cc3963
f6ea894
08ce120
c854c94
9f8074e
fb08609
355ca1c
c2bfedb
f4d83d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| SELECT | ||
| id, | ||
| prompt | ||
| FROM prompt_configuration | ||
| LIMIT 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| INSERT INTO prompt_configuration (prompt) | ||
| VALUES (:prompt) | ||
| RETURNING id, prompt |
| 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 |
| 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 |
| 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 ?? ""} | ||
|
Comment on lines
+15
to
+17
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| .prompt-configurations { | ||
| padding: 2rem; | ||
|
|
||
| .container { | ||
| max-width: 1200px; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .title-container { | ||
| margin-bottom: 2rem; | ||
|
|
||
| .title { | ||
| font-size: 2rem; | ||
| font-weight: 600; | ||
| margin-bottom: 0.5rem; | ||
| color: #1a1a1a; | ||
| } | ||
|
|
||
| .subtitle { | ||
| font-size: 1rem; | ||
| color: #666; | ||
| margin: 0; | ||
| } | ||
| } | ||
|
|
||
| .prompt-form { | ||
| background: #fff; | ||
| border-radius: 8px; | ||
| padding: 2rem; | ||
| box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); | ||
|
|
||
| .form-actions { | ||
| margin-top: 1.5rem; | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| gap: 1rem; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,100 @@ | ||||||||||||||
| import { FC, useState, useEffect } from 'react'; | ||||||||||||||
| import { useTranslation } from 'react-i18next'; | ||||||||||||||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||||||||||||||
| import { Button, FormTextarea } from 'components'; | ||||||||||||||
| import { ButtonAppearanceTypes, ToastTypes } from 'enums/commonEnums'; | ||||||||||||||
| import CircularSpinner from 'components/molecules/CircularSpinner/CircularSpinner'; | ||||||||||||||
| import { getPromptConfiguration, savePromptConfiguration } from 'services/promptConfiguration'; | ||||||||||||||
| import { promptConfigurationQueryKeys } from 'utils/queryKeys'; | ||||||||||||||
| import { useToast } from 'hooks/useToast'; | ||||||||||||||
| import './PromptConfigurations.scss'; | ||||||||||||||
|
|
||||||||||||||
| const PromptConfigurations: FC = () => { | ||||||||||||||
| const { t } = useTranslation(); | ||||||||||||||
| const toast = useToast(); | ||||||||||||||
| const queryClient = useQueryClient(); | ||||||||||||||
| const [promptText, setPromptText] = useState(''); | ||||||||||||||
| const [isUpdating, setIsUpdating] = useState(false); | ||||||||||||||
|
|
||||||||||||||
| // Fetch prompt configuration | ||||||||||||||
| const { data: promptConfig, isLoading } = useQuery({ | ||||||||||||||
| queryKey: promptConfigurationQueryKeys.current(), | ||||||||||||||
| queryFn: getPromptConfiguration, | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| // Update promptText when data is loaded | ||||||||||||||
| useEffect(() => { | ||||||||||||||
| if (promptConfig && promptConfig.length > 0) { | ||||||||||||||
| setPromptText(promptConfig[0].prompt || ''); | ||||||||||||||
| setIsUpdating(true); | ||||||||||||||
| } | ||||||||||||||
| }, [promptConfig]); | ||||||||||||||
|
|
||||||||||||||
| // Save prompt mutation | ||||||||||||||
| const saveMutation = useMutation({ | ||||||||||||||
| mutationFn: savePromptConfiguration, | ||||||||||||||
| onSuccess: () => { | ||||||||||||||
| queryClient.invalidateQueries({ queryKey: promptConfigurationQueryKeys.current() }); | ||||||||||||||
| toast.open({ | ||||||||||||||
| type: ToastTypes.SUCCESS, | ||||||||||||||
| title: t('toast.success.title'), | ||||||||||||||
| message: t('promptConfigurations.submitSuccess'), | ||||||||||||||
| }); | ||||||||||||||
| }, | ||||||||||||||
| onError: (error: any) => { | ||||||||||||||
| console.error('Error saving prompt:', error); | ||||||||||||||
| toast.open({ | ||||||||||||||
| type: ToastTypes.ERROR, | ||||||||||||||
| title: t('toast.error.title'), | ||||||||||||||
| message: t('promptConfigurations.submitError'), | ||||||||||||||
| }); | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const handleSubmit = () => { | ||||||||||||||
| if (!promptText.trim()) { | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
| saveMutation.mutate(promptText); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| if (isLoading) { | ||||||||||||||
| return <CircularSpinner />; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <div className="prompt-configurations"> | ||||||||||||||
| <div className="container"> | ||||||||||||||
| <div className="title_container"> | ||||||||||||||
|
||||||||||||||
| <div className="title_container"> | |
| <div className="title-container"> |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecated property isLoading is being used for both useQuery and useMutation. In newer versions of @tanstack/react-query (v4+), this property has been renamed to isPending for mutations. Consider updating to use isPending for the mutation or ensure the code is compatible with the version being used.
| disabled={saveMutation.isLoading || !promptText.trim()} | |
| > | |
| {saveMutation.isLoading | |
| disabled={saveMutation.isPending || !promptText.trim()} | |
| > | |
| {saveMutation.isPending |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import apiDev from './api-dev'; | ||
| import { promptConfigurationEndpoints } from 'utils/endpoints'; | ||
|
|
||
| export interface PromptConfiguration { | ||
| id: number | null; | ||
| prompt: string; | ||
| } | ||
|
|
||
| export interface PromptConfigurationResponse { | ||
| response: PromptConfiguration[]; | ||
| } | ||
|
|
||
| export const getPromptConfiguration = async (): Promise<PromptConfiguration[]> => { | ||
| const { data } = await apiDev.get(promptConfigurationEndpoints.GET_PROMPT_CONFIGURATION()); | ||
| return data?.response || []; | ||
| }; | ||
|
|
||
| export const savePromptConfiguration = async (prompt: string): Promise<PromptConfiguration[]> => { | ||
| const { data } = await apiDev.post(promptConfigurationEndpoints.SAVE_PROMPT_CONFIGURATION(), { | ||
| prompt, | ||
| }); | ||
| return data?.response; | ||
|
Comment on lines
+18
to
+22
|
||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The database migration is missing a PRIMARY KEY constraint on the
idcolumn. While the column is defined as an IDENTITY column, it should explicitly be marked as PRIMARY KEY to ensure proper indexing and prevent duplicate IDs.