added together ai agent
Browse files
gemini_langchain_agent.py
CHANGED
@@ -39,13 +39,14 @@ def create_agent(llm, data, tools):
|
|
39 |
return_intermediate_steps=True
|
40 |
)
|
41 |
|
42 |
-
def _prompt_generator(question: str, chart_required: bool):
|
43 |
chat_prompt = f"""You are a senior data analyst working with CSV data. Adhere strictly to the following guidelines:
|
44 |
|
45 |
1. **Data Verification:** Always inspect the data with `.sample(5).to_dict()` before performing any analysis.
|
46 |
2. **Data Integrity:** Ensure proper handling of null values to maintain accuracy and reliability.
|
47 |
3. **Communication:** Provide concise, professional, and well-structured responses.
|
48 |
4. Avoid including any internal processing details or references to the methods used to generate your response (ex: based on the tool call, using the function -> These types of phrases.)
|
|
|
49 |
|
50 |
**Query:** {question}
|
51 |
"""
|
@@ -80,6 +81,7 @@ def _prompt_generator(question: str, chart_required: bool):
|
|
80 |
- Use THE SAME unique_id throughout entire process
|
81 |
- NEVER generate new UUIDs after initial creation
|
82 |
- Return EXACT filepath string of the final saved chart
|
|
|
83 |
"""
|
84 |
|
85 |
if chart_required:
|
@@ -112,7 +114,7 @@ def langchain_gemini_csv_handler(csv_url: str, question: str, chart_required: bo
|
|
112 |
)
|
113 |
|
114 |
agent = create_agent(llm, data, [tool])
|
115 |
-
prompt = _prompt_generator(question, chart_required)
|
116 |
result = agent.invoke({"input": prompt})
|
117 |
output = result.get("output")
|
118 |
|
|
|
39 |
return_intermediate_steps=True
|
40 |
)
|
41 |
|
42 |
+
def _prompt_generator(question: str, chart_required: bool, csv_url: str):
|
43 |
chat_prompt = f"""You are a senior data analyst working with CSV data. Adhere strictly to the following guidelines:
|
44 |
|
45 |
1. **Data Verification:** Always inspect the data with `.sample(5).to_dict()` before performing any analysis.
|
46 |
2. **Data Integrity:** Ensure proper handling of null values to maintain accuracy and reliability.
|
47 |
3. **Communication:** Provide concise, professional, and well-structured responses.
|
48 |
4. Avoid including any internal processing details or references to the methods used to generate your response (ex: based on the tool call, using the function -> These types of phrases.)
|
49 |
+
5. Always use pd.read_csv({csv_url}) to read the CSV file.
|
50 |
|
51 |
**Query:** {question}
|
52 |
"""
|
|
|
81 |
- Use THE SAME unique_id throughout entire process
|
82 |
- NEVER generate new UUIDs after initial creation
|
83 |
- Return EXACT filepath string of the final saved chart
|
84 |
+
- Always use pd.read_csv({csv_url}) to read the CSV file
|
85 |
"""
|
86 |
|
87 |
if chart_required:
|
|
|
114 |
)
|
115 |
|
116 |
agent = create_agent(llm, data, [tool])
|
117 |
+
prompt = _prompt_generator(question, chart_required, csv_url)
|
118 |
result = agent.invoke({"input": prompt})
|
119 |
output = result.get("output")
|
120 |
|