Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Refactor get prompt service
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshaj000 committed Oct 6, 2023
1 parent 53a995f commit c315147
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions genai_stack/genai_server/services/prompt_engine_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,7 @@ def get_prompt(self, data: PromptEngineGetRequestModel) -> PromptEngineGetRespon
stack_session = session.get(StackSessionSchema, data.session_id)
if stack_session is None:
raise HTTPException(status_code=404, detail=f"Session {data.session_id} not found")
prompt_session = (
session.query(PromptSchema)
.filter_by(stack_session=data.session_id, type=data.type.value)
.first()
)
if prompt_session is not None:
template = prompt_session.template
prompt_type_map = {
PromptTypeEnum.SIMPLE_CHAT_PROMPT.value: "simple_chat_prompt_template",
PromptTypeEnum.CONTEXTUAL_CHAT_PROMPT.value: "contextual_chat_prompt_template",
PromptTypeEnum.CONTEXTUAL_QA_PROMPT.value: "contextual_qa_prompt_template",
}
input_variables = ["context", "history", "query"]
if data.type == PromptTypeEnum.SIMPLE_CHAT_PROMPT:
input_variables.remove("context")
elif data.type == PromptTypeEnum.CONTEXTUAL_QA_PROMPT:
input_variables.remove("history")
prompt = PromptTemplate(template=template, input_variables=input_variables)
stack = get_current_stack(
engine=session,
config=stack_config,
session=stack_session,
overide_config={
"prompt_engine": {
"should_validate": data.should_validate,
prompt_type_map[data.type.value]: prompt
}
}
)
else:
stack = get_current_stack(config=stack_config, engine=session, session=stack_session)
stack = get_current_stack(config=stack_config, engine=session, session=stack_session)
prompt = stack.prompt_engine.get_prompt_template(promptType=data.type, query=data.query)
return PromptEngineGetResponseModel(
template=prompt.template,
Expand Down

0 comments on commit c315147

Please sign in to comment.