Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/vNext-Dev' into dayland/7881-upd…
Browse files Browse the repository at this point in the history
…ate-cosmosdb-conn-to-aad-auth
  • Loading branch information
dayland committed Aug 8, 2024
2 parents ee08e09 + 2b76a6d commit 6bb1ef2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ async def posttd(csv: UploadFile = File(...)):
global dffinal
# Read the file into a pandas DataFrame
content = await csv.read()
df = pd.read_csv(StringIO(content.decode('latin-1')))
df = pd.read_csv(StringIO(content.decode('utf-8-sig')))

dffinal = df
# Process the DataFrame...
Expand All @@ -715,11 +715,12 @@ async def posttd(csv: UploadFile = File(...)):
#return {"filename": csv.filename}
@app.get("/process_td_agent_response")
async def process_td_agent_response(retries=3, delay=1000, question: Optional[str] = None):
save_df(dffinal)
if question is None:
raise HTTPException(status_code=400, detail="Question is required")
for i in range(retries):
try:
results = td_agent_response(question)
results = td_agent_response(question,dffinal)
return results
except AttributeError as ex:
log.exception(f"Exception in /process_tabular_data_agent_response:{str(ex)}")
Expand Down
17 changes: 12 additions & 5 deletions app/backend/approaches/tabulardataassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ def get_image_data(image_path):

def save_chart(query):
temp_dir = tempfile.gettempdir()
q_s = f'''You are a assistant to help analyze CSV file data and are a dataframe ally. You analyze every row, addressing all queries with unwavering precision.
You DO NOT answer based on subset of dataframe or top 5 or based on head() output. You need to look at all rows and then answer questions. Data is case insensitive.
If any charts or graphs or plots were created save them in the {temp_dir} directory. Remember, you can handle both singular and plural forms of queries.
q_s = f'''You are a assistant to help analyze CSV data that is placed in a dataframe and are a dataframe ally. You analyze every row, addressing all queries with unwavering precision.
You DO NOT answer based on subset of the dataframe or top 5 or based on head() output. Do not create an example dataframe. Use the dataframe provided to you. You need to look at all rows and then answer questions based on the entire dataframe and ensure the input to any tool is valid. Data is case insensitive.
Normalize column names by converting them to lowercase and replacing spaces with underscores to handle discrepancies in column naming conventions.
If any charts or graphs or plots were created save them in the {temp_dir} directory. Make sure the output of the result includes the final result and not just the chart or graph. Put the charts in the {temp_dir} directory and not the final output.
Remember, you can handle both singular and plural forms of queries.
For example:
- If you ask \'How many thinkpads do we have?\' or \'How many thinkpad do we have?\', you will address both forms in the same manner.
Expand Down Expand Up @@ -108,10 +110,15 @@ def process_agent_scratch_pad(question, df):
raise ValueError()

#Function to stream final output
def process_agent_response(question):
def process_agent_response(question, df):
question = save_chart(question)

pdagent = create_pandas_dataframe_agent(model, dffinal, verbose=True,agent_type=AgentType.OPENAI_FUNCTIONS, allow_dangerous_code=True, agent_executor_kwargs={"handle_parsing_errors": True})
pdagent = create_pandas_dataframe_agent(model,
df,
verbose=True,
agent_type=AgentType.OPENAI_FUNCTIONS,
allow_dangerous_code=True,
agent_executor_kwargs={"handle_parsing_errors": True})
for chunk in pdagent.stream({"input": question}):
if "output" in chunk:
output = f'Final Output: ```{chunk["output"]}```'
Expand Down
3 changes: 1 addition & 2 deletions app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ wikipedia==1.4.0
langchain-openai == 0.1.14
pytest==8.2.1
python-dotenv==1.0.1
langchain-community==0.2.9

langchain-community==0.2.9

0 comments on commit 6bb1ef2

Please sign in to comment.