Skip to content

Commit

Permalink
chore: restructures response object from chatbots routes
Browse files Browse the repository at this point in the history
  • Loading branch information
yg-lim committed Aug 7, 2024
1 parent e1e26b9 commit 6669ef3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions pipeline/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ def ui_to_pipeline(ui_json):

log.debug('config_util.py ui_to_pipeline: pipeline_obj', pipeline_obj)
return pipeline_obj


def pipeline_to_ui(pipeline_obj):
ui_obj = {
"id": pipeline_obj['id'],
"name": pipeline_obj['name'],
"knowledge_bases": pipeline_obj['knowledgebases'],
"generative_model": pipeline_obj['generative_model'],
"similarity": {
"on": pipeline_obj['postprocessing']['similarity']['on'],
"cutoff": pipeline_obj['postprocessing']['similarity'].get('similarity_cutoff', 0.7)
},
"colbert_rerank": {
"on": pipeline_obj['postprocessing']['colbertRerank']['on'],
"top_n": pipeline_obj['postprocessing']['colbertRerank'].get('top_n', DEFAULT_TOP_N)
},
"long_context_reorder": {
"on": pipeline_obj['postprocessing']['longContextReorder']['on']
},
"prompt": pipeline_obj['prompt']['template_str']
}

log.debug('config_util.py pipeline_to_ui: ui_obj', ui_obj)
return ui_obj

4 changes: 2 additions & 2 deletions routers/chatbots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def get_chatbots():
log.info('/api/chatbots loaded')
results = mutil.get_all(CONFIG_DB, CONFIG_PIPELINE_COL, {}, { '_id': 0 })
log.info('/api/chatbots results:', results)
return results
return [cutil.pipeline_to_ui(result) for result in results]

@router.get('/{id}')
async def get_chatbots_id(id: str):
Expand All @@ -38,7 +38,7 @@ async def get_chatbots_id(id: str):
if not results:
return {"message": "no chatbot configuration found"}

return results
return [cutil.pipeline_to_ui(result) for result in results]

@router.post('/')
async def post_chatbots(request: Request):
Expand Down
2 changes: 1 addition & 1 deletion ui/src/services/knowledge-base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function fetchKnowledgeBases() {
}

async function fetchKnowledgeBaseById(id: string) {
const response = await axios.get(`${baseUrl}/api/knowledge-base/${id}`);
const response = await axios.get(`${baseUrl}/api/knowledge-bases/${id}`);
console.log(response.data);
return response.data;
}
Expand Down

0 comments on commit 6669ef3

Please sign in to comment.