Skip to content

Commit

Permalink
Merge pull request #100 from amilmshaji/fix/yaml-document-plugin-crash
Browse files Browse the repository at this point in the history
Fixed Application Crashes When Querying JSON from YAML
  • Loading branch information
ashmilhussain authored Oct 9, 2024
2 parents 47a5f40 + eec129f commit 42db98a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/chain/modules/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ def handle(self, request: dict) -> str:
return Formatter.format("Oops! Something went wrong. Try Again!",output['error'])

response["inference"] = parse_llm_response(output['content'])
if not response["inference"]:
return Formatter.format("Oops! Something went wrong. Try Again!","")

return super().handle(response)
2 changes: 1 addition & 1 deletion app/chain/modules/ouput_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def handle(self, request: Any) -> str:
if intent_key in self.datasource:
response = self.datasource[intent_key].format(request.get("query_response"), input_data)
elif "general_message" in input_data:
response["content"] = input_data.get('general_message')
response["content"] = str(input_data.get('general_message'))


if "data" in response and isinstance(response["data"], list) and len(response["data"]) == 0:
Expand Down
8 changes: 2 additions & 6 deletions app/plugins/document/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
Adhere to these rules while generating answers:
- Carefully read through the question and context word by word to appropriately answer the question.
- Only use information provided in the context to answer questions.
- Answer should not break the json format
- If the answer cannot be found in the context, state that you don't have enough information to answer.
"""
},
"user_prompt":{
Expand All @@ -46,10 +48,7 @@
Generate a JSON response in the following format without any formatting:
{
"explanation": "Explain how you determined the answer using the provided context",
"operation_kind": "none",
"general_message": "Answer to user question based on the context",
"confidence": "Confidence level from 0 to 100",
"main_entity": "document"
}
"""
},
Expand All @@ -59,10 +58,7 @@
Generate a JSON response in the following format without any formatting:
{
"explanation": "Explain how you determined the answer using the provided context",
"operation_kind": "answer_from_context",
"general_message": "Answer to user question based on the context",
"confidence": "Confidence level from 0 to 100",
"main_entity": "document"
}
"""
}
Expand Down
2 changes: 0 additions & 2 deletions app/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
def parse_llm_response(body):
text = body.replace("\\n","")
text = text.replace("\n","")
text = text.replace("\\","")
text = text.replace("\\_","_")
if '\\"' not in text:
text = text.replace("\\","")
text = text.removeprefix("```json")
text = text.removesuffix("```")
text = text.removesuffix("User:")

try:
out = json.loads(text)
except Exception as e:
Expand Down

0 comments on commit 42db98a

Please sign in to comment.