Skip to content

Commit 2ec779f

Browse files
author
wwanarif
committed
add button to import sample-workflows in studio-fe and fix UI_FEATURES disabling in app-fe
Signed-off-by: wwanarif <[email protected]>
1 parent 07971fe commit 2ec779f

File tree

11 files changed

+77
-51
lines changed

11 files changed

+77
-51
lines changed

app-frontend/react/.env.production

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
VITE_CHAT_SERVICE_URL=APP_BACKEND_SERVICE_URL
2-
VITE_DATA_PREP_SERVICE_URL=APP_DATA_PREP_SERVICE_URL
31
VITE_APP_UUID=APP_UUID

app-frontend/react/src/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
// console.log("Environment variables:", import.meta.env);
55

6-
export const DATA_PREP_URL = import.meta.env.VITE_DATA_PREP_SERVICE_URL;
7-
export const CHAT_QNA_URL = import.meta.env.VITE_CHAT_SERVICE_URL;
86
export const APP_UUID = import.meta.env.VITE_APP_UUID;
9-
10-
console.log("data prep", DATA_PREP_URL);
11-
console.log("chat qna", CHAT_QNA_URL);
7+
export const CHAT_QNA_URL = "VITE_APP_BACKEND_SERVICE_URL";
8+
export const DATA_PREP_URL = "VITE_APP_DATA_PREP_SERVICE_URL";
129

1310
type UiFeatures = {
1411
dataprep: boolean;
1512
chat: boolean;
1613
};
1714

1815
export const UI_FEATURES: UiFeatures = {
19-
dataprep: !!DATA_PREP_URL,
20-
chat: !!CHAT_QNA_URL
16+
chat: CHAT_QNA_URL.startsWith('VITE_') ? false : true,
17+
dataprep: DATA_PREP_URL.startsWith('VITE_') ? false : true
2118
};
19+
20+
console.log("chat qna", CHAT_QNA_URL, UI_FEATURES.chat);
21+
console.log("data prep", DATA_PREP_URL, UI_FEATURES.dataprep);

studio-backend/app/templates/app/app.compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ app-frontend:
2525
- no_proxy=${no_proxy}
2626
- https_proxy=${https_proxy}
2727
- http_proxy=${http_proxy}
28-
- APP_BACKEND_SERVICE_URL=/v1/app-backend
28+
- VITE_APP_BACKEND_SERVICE_URL=/v1/app-backend
2929
__UI_CONFIG_INFO_ENV_PLACEHOLDER__
3030
ipc: host
3131
restart: always

studio-backend/app/templates/app/app.manifest.aws.ecr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ spec:
118118
containers:
119119
- name: app-frontend
120120
env:
121-
- name: APP_BACKEND_SERVICE_URL
121+
- name: VITE_APP_BACKEND_SERVICE_URL
122122
value: /v1/app-backend
123123
__UI_CONFIG_INFO_ENV_PLACEHOLDER__
124124
securityContext: {}

studio-backend/app/templates/app/app.manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ spec:
107107
containers:
108108
- name: app-frontend
109109
env:
110-
- name: APP_BACKEND_SERVICE_URL
110+
- name: VITE_APP_BACKEND_SERVICE_URL
111111
value: /v1/app-backend
112112
__UI_CONFIG_INFO_ENV_PLACEHOLDER__
113113
securityContext: {}

studio-backend/app/utils/placeholders_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def replace_dynamic_manifest_placeholder(value_str, service_info, proj_info_json
7272
# For __UI_CONFIG_INFO_ENV_PLACEHOLDER__
7373
url_name = value['url_name']
7474
endpoint_path = value['endpoint_path']
75-
env_block = f"{indent_str}- name: {url_name}\n{indent_str} value: {endpoint_path}\n"
75+
env_block = f"{indent_str}- name: VITE_{url_name}\n{indent_str} value: {endpoint_path}\n"
7676
ui_env_config_info_str += env_block
7777

7878
# For __UI_CONFIG_INFO_ENV_PLACEHOLDER__
@@ -144,7 +144,7 @@ def replace_dynamic_compose_placeholder(value_str, service_info):
144144
for _, value in service_info['ui_config_info'].items():
145145
url_name = value['url_name']
146146
endpoint_path = value['endpoint_path']
147-
endpoint_block = f"{indent_str} - {url_name}={endpoint_path}\n"
147+
endpoint_block = f"{indent_str} - VITE_{url_name}={endpoint_path}\n"
148148
ui_env_config_info_str += endpoint_block
149149

150150
# Get app images from environment variables

studio-frontend/packages/server/src/controllers/chatflows/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ const getAllChatflowsbyUserId = async (req: Request, res: Response, next: NextFu
6767
}
6868
}
6969

70+
const importSampleChatflowsbyUserId = async (req: Request, res: Response, next: NextFunction) => {
71+
try {
72+
const apiResponse = await chatflowsService.importSampleChatflowsbyUserId(req.query.userid as string, req.query.type as ChatflowType)
73+
return res.json(apiResponse)
74+
} catch (error) {
75+
next(error)
76+
}
77+
}
78+
7079
// Get specific chatflow via api key
7180
const getChatflowByApiKey = async (req: Request, res: Response, next: NextFunction) => {
7281
try {
@@ -268,6 +277,7 @@ export default {
268277
deleteChatflow,
269278
getAllChatflows,
270279
getAllChatflowsbyUserId,
280+
importSampleChatflowsbyUserId,
271281
getChatflowByApiKey,
272282
getChatflowById,
273283
saveChatflow,

studio-frontend/packages/server/src/routes/chatflows/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const router = express.Router()
44

55
// CREATE
66
router.post('/', chatflowsController.saveChatflow)
7+
router.post('/importsamples', chatflowsController.importSampleChatflowsbyUserId)
78
router.post('/importchatflows', chatflowsController.importChatflows)
89

910
// READ

studio-frontend/packages/server/src/services/chatflows/index.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,11 @@ const getAllChatflowsbyUserId = async (userid: string, type?: ChatflowType): Pro
139139
const appServer = getRunningExpressApp()
140140

141141
// Use find with a where condition to filter by userid
142-
let dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find({
142+
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find({
143143
where: {
144144
userid: userid, // Filter by the specific userid
145145
},
146146
})
147-
148-
// If no chatflows are found for the user, create a new one based from sample workflow
149-
if (dbResponse.length === 0) {
150-
// URL to fetch the sample workflow
151-
const url = 'https://raw.githubusercontent.com/opea-project/GenAIStudio/refs/heads/main/sample-workflows/sample_workflow_chatqna.json';
152-
153-
try {
154-
// Fetch and parse the JSON data from the URL
155-
const response = await axios.get(url);
156-
const parsedFlowData = response.data;
157-
158-
// Create a new chatflow with the flowData from the URL
159-
const newChatflow: Partial<ChatFlow> = {
160-
userid: userid,
161-
name: 'sample-chatqna',
162-
flowData: JSON.stringify(parsedFlowData),
163-
type: 'OPEA',
164-
deployed: false,
165-
isPublic: false
166-
};
167-
168-
// Call the importChatflows function to insert the new chatflow
169-
await importChatflows([newChatflow]);
170-
} catch (error) {
171-
throw new Error('Failed to import sample chatflow');
172-
}
173-
174-
// Rerun the find query to fetch the latest state of chatflows after insertion
175-
dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find({
176-
where: {
177-
userid: userid,
178-
},
179-
});
180-
}
181147

182148
// Filter further by type if needed
183149
if (type) {
@@ -193,6 +159,39 @@ const getAllChatflowsbyUserId = async (userid: string, type?: ChatflowType): Pro
193159
}
194160
}
195161

162+
const importSampleChatflowsbyUserId = async (userid: string, type?: ChatflowType): Promise<ChatFlow[]> => {
163+
try {
164+
const response = await axios.get('https://api.github.com/repos/opea-project/GenAIStudio/contents/sample-workflows');
165+
const files = response.data.filter((item: any) => item.type === 'file');
166+
console.log(`Number of files: ${files.length}`);
167+
168+
const chatflows: Partial<ChatFlow>[] = [];
169+
170+
for (const file of files) {
171+
console.log(`Download URL: ${file.download_url}`);
172+
const fileResponse = await axios.get(file.download_url);
173+
const parsedFlowData = fileResponse.data;
174+
175+
const newChatflow: Partial<ChatFlow> = {
176+
userid: userid,
177+
name: file.name.replace('.json', ''),
178+
flowData: JSON.stringify(parsedFlowData),
179+
type: 'OPEA',
180+
deployed: false,
181+
isPublic: false
182+
};
183+
184+
chatflows.push(newChatflow);
185+
}
186+
const insertResponse = await importChatflows(chatflows);
187+
return insertResponse;
188+
} catch (error) {
189+
throw new InternalFlowiseError(
190+
StatusCodes.INTERNAL_SERVER_ERROR,
191+
`Error: chatflowsService.importSampleChatflowsbyUserId - ${getErrorMessage(error)}`
192+
);
193+
}
194+
}
196195

197196
const getChatflowByApiKey = async (apiKeyId: string, keyonly?: unknown): Promise<any> => {
198197
try {
@@ -516,6 +515,7 @@ export default {
516515
deleteChatflow,
517516
getAllChatflows,
518517
getAllChatflowsbyUserId,
518+
importSampleChatflowsbyUserId,
519519
getChatflowByApiKey,
520520
getChatflowById,
521521
saveChatflow,

studio-frontend/packages/ui/src/api/chatflows.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const stopSandbox = (id) => client.post(`/chatflows-sandbox/stop/${id}`)
3131

3232
const buildDeploymentPackage = (id, body) => client.post(`chatflows-sandbox/build-deployment-package/${id}`, body, {responseType: "arraybuffer"})
3333

34+
const importSampleChatflowsbyUserId = (userid) => client.post(`/chatflows/importsamples?userid=${userid}&type=OPEA`)
35+
3436
export default {
3537
getAllChatflows,
3638
getAllAgentflows,
@@ -39,6 +41,7 @@ export default {
3941
getSpecificChatflow,
4042
getSpecificChatflowFromPublicEndpoint,
4143
createNewChatflow,
44+
importSampleChatflowsbyUserId,
4245
importChatflows,
4346
updateChatflow,
4447
deleteChatflow,

0 commit comments

Comments
 (0)