JamalAG commited on
Commit
8db58ed
·
verified ·
1 Parent(s): 43b260c

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +29 -0
utils.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_experimental.agents import create_pandas_dataframe_agent
2
+ import pandas as pd
3
+ from langchain.llms import HuggingFaceHub
4
+ from langchain.agents.agent_types import AgentType
5
+ from langchain_community.llms import HuggingFaceEndpoint
6
+ from langchain_community.chat_models.huggingface import ChatHuggingFace
7
+
8
+ def query_agent(data, query):
9
+ # Parse the CSV file and create a Pandas DataFrame from its contents.
10
+ df = pd.read_csv(data)
11
+
12
+ llm = HuggingFaceEndpoint(repo_id="teknium/OpenHermes-2.5-Mistral-7B",
13
+ temperature = 0.9,
14
+ stop_sequences = ["\nQuestion:"])
15
+
16
+ # Create a Pandas DataFrame agent with the loaded model and processor
17
+ agent = create_pandas_dataframe_agent(llm,
18
+ df,
19
+ verbose=True,
20
+ handle_parsing_errors=True,
21
+ )
22
+
23
+ # Modify the query to include details for your new model usage
24
+ modified_query = query + " using tool python_repl_ast or any other relevant tool if needed. First Command you find is most likely to be the most accurate one so use it."
25
+
26
+
27
+
28
+ # Run the agent with the modified model and processor instance
29
+ return agent.run(modified_query)