Aniket2006 commited on
Commit
d633941
·
1 Parent(s): ba6427c

Fix: Simplify Gemini integration and update dependencies

Browse files
Files changed (2) hide show
  1. app.py +18 -16
  2. requirements.txt +3 -2
app.py CHANGED
@@ -114,12 +114,6 @@ def generate_response(user_message: str, history: List[Dict], context: Optional[
114
  """Generate AI response using Gemini."""
115
  context_used = []
116
 
117
- # Build conversation history for context
118
- conversation = []
119
- for msg in history[-10:]: # Last 10 messages for context
120
- role = "user" if msg.get("role") == "user" else "model"
121
- conversation.append({"role": role, "parts": [msg.get("content", "")]})
122
-
123
  # Build context prompt if pipeline data available
124
  context_prompt = ""
125
  if context:
@@ -136,17 +130,25 @@ def generate_response(user_message: str, history: List[Dict], context: Optional[
136
  return f"I received your question: '{user_message}'. Please configure GEMINI_API_KEY for real responses.", []
137
 
138
  try:
139
- # Create chat with system instruction
140
- chat = model.start_chat(history=conversation)
 
 
 
141
 
142
- # Generate response
143
- response = chat.send_message(
144
- f"[System: {full_system}]\n\nUser: {user_message}",
145
- generation_config=genai.types.GenerationConfig(
146
- temperature=0.7,
147
- max_output_tokens=1024,
148
- )
149
- )
 
 
 
 
 
150
 
151
  return response.text, context_used
152
 
 
114
  """Generate AI response using Gemini."""
115
  context_used = []
116
 
 
 
 
 
 
 
117
  # Build context prompt if pipeline data available
118
  context_prompt = ""
119
  if context:
 
130
  return f"I received your question: '{user_message}'. Please configure GEMINI_API_KEY for real responses.", []
131
 
132
  try:
133
+ # Build conversation context
134
+ history_text = ""
135
+ for msg in history[-6:]: # Last 6 messages
136
+ role = "User" if msg.get("role") == "user" else "Assistant"
137
+ history_text += f"{role}: {msg.get('content', '')}\n"
138
 
139
+ # Create full prompt
140
+ full_prompt = f"""{full_system}
141
+
142
+ ## Previous Conversation:
143
+ {history_text}
144
+
145
+ ## Current Question:
146
+ User: {user_message}
147
+
148
+ ## Your Response (as AGROW AI agricultural advisor):"""
149
+
150
+ # Generate response using simple generate_content
151
+ response = model.generate_content(full_prompt)
152
 
153
  return response.text, context_used
154
 
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  fastapi==0.104.1
2
  uvicorn==0.24.0
3
  pydantic==2.5.2
4
- google-generativeai==0.3.2
5
- supabase==2.3.0
6
  python-dotenv==1.0.0
 
 
1
  fastapi==0.104.1
2
  uvicorn==0.24.0
3
  pydantic==2.5.2
4
+ google-generativeai>=0.8.0
5
+ supabase>=2.0.0
6
  python-dotenv==1.0.0
7
+ httpx>=0.24.0