-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ErrorHandling): retry query multiple times based on the max retr…
…ies (#592) * feat[Agent]: add agent conversation code * feat[Agent]: add test cases for the agent class * feat: add explain method * feat: Add Explain functionality in the agent * fix: refactor types * chore: fix typings * chore: improve prompt add conversation * refactor: remove memory from the agent class * refactor: import of Agent class in example * refactor: memory to return conversation according to size * refactor: remove leftover property * fix: prompt comment * fix: redundant try catch * chore: improve docstring and add example in documentation * fix: Comment in clarification prompts and add dtyps to the constructors * feat(RephraseQuery): rephrase user query to get more accurate responses * chore(agent): add max retries on queries * feat: improve the prompt to also add information about ambiguous parts * feat[retry_wrapper]: add basic wrapper for error handling and add prompt validators * refactor(validation): return False from the validator in case of failure * fix(RephraseQuery): remove conversation from the prompt if empty --------- Co-authored-by: Gabriele Venturi <[email protected]>
- Loading branch information
1 parent
09872ac
commit 722ca3e
Showing
6 changed files
with
236 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" Prompt to rephrase query to get more accurate responses | ||
You are provided with the following pandas DataFrames: | ||
{dataframes} | ||
{conversation} | ||
Return the rephrased sentence of "{query}” in order to obtain more accurate and | ||
comprehensive responses without any explanations. If something from the original | ||
query is ambiguous, please clarify it in the rephrased query, making assumptions, | ||
if necessary. | ||
""" | ||
from typing import List | ||
|
||
import pandas as pd | ||
from .base import Prompt | ||
|
||
|
||
class RephraseQueryPrompt(Prompt): | ||
"""Prompt to rephrase query to get more accurate responses""" | ||
|
||
text: str = """ | ||
You are provided with the following pandas DataFrames: | ||
{dataframes} | ||
{conversation} | ||
Return the rephrased sentence of "{query}” in order to obtain more accurate and | ||
comprehensive responses without any explanations. If something from the original | ||
query is ambiguous, please clarify it in the rephrased query, making assumptions, | ||
if necessary. | ||
""" | ||
|
||
conversation_text: str = """ | ||
And based on our conversation: | ||
<conversation> | ||
{conversation} | ||
</conversation> | ||
""" | ||
|
||
def __init__(self, query: str, dataframes: List[pd.DataFrame], conversation: str): | ||
conversation_content = ( | ||
self.conversation_text.format(conversation=conversation) | ||
if conversation | ||
else "" | ||
) | ||
self.set_var("conversation", conversation_content) | ||
self.set_var("query", query) | ||
self.set_var("dfs", dataframes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters