Manojkumarpandi commited on
Commit
cf4e603
·
verified ·
1 Parent(s): 4f6956d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -65
app.py CHANGED
@@ -2,8 +2,7 @@ import streamlit as st
2
  import os
3
  import json
4
  import requests
5
- from google import genai
6
- from google.genai import types
7
  from dotenv import load_dotenv
8
 
9
  load_dotenv()
@@ -17,7 +16,7 @@ st.set_page_config(
17
 
18
  # Initialize Gemini client
19
  api_key = st.secrets["GOOGLE_API_KEY"]
20
- client = genai.Client(api_key=api_key)
21
 
22
  # Indian Stock Market API base configuration
23
  INDIAN_API_KEY = st.secrets["FINANCE_KEY"]
@@ -31,50 +30,7 @@ API_ENDPOINTS = {
31
  "param_mapping": {"stock_name": "name"},
32
  "description": "Get details for a specific stock"
33
  },
34
- "get_trending_stocks": {
35
- "endpoint": "/trending",
36
- "required_params": [],
37
- "param_mapping": {},
38
- "description": "Get trending stocks in the market"
39
- },
40
- "get_market_news": {
41
- "endpoint": "/news",
42
- "required_params": [],
43
- "param_mapping": {},
44
- "description": "Get latest stock market news"
45
- },
46
- "get_mutual_funds": {
47
- "endpoint": "/mutual_funds",
48
- "required_params": [],
49
- "param_mapping": {},
50
- "description": "Get mutual funds data"
51
- },
52
- "get_ipo_data": {
53
- "endpoint": "/ipo",
54
- "required_params": [],
55
- "param_mapping": {},
56
- "description": "Get IPO data"
57
- },
58
- "get_bse_most_active": {
59
- "endpoint": "/BSE_most_active",
60
- "required_params": [],
61
- "param_mapping": {},
62
- "description": "Get BSE most active stocks"
63
- },
64
- "get_nse_most_active": {
65
- "endpoint": "/NSE_most_active",
66
- "required_params": [],
67
- "param_mapping": {},
68
- "description": "Get NSE most active stocks"
69
- },
70
- "get_historical_data": {
71
- "endpoint": "/historical_data",
72
- "required_params": ["stock_name"],
73
- "optional_params": ["period"],
74
- "default_values": {"period": "1m", "filter": "default"},
75
- "param_mapping": {},
76
- "description": "Get historical data for a stock"
77
- }
78
  }
79
 
80
  # Unified API call function
@@ -183,28 +139,16 @@ def orchestrator(query):
183
 
184
  # Create content for the orchestrator
185
  contents = [
186
- types.Content(
187
- role="user",
188
- parts=[
189
- types.Part.from_text(text=orchestrator_prompt)
190
- ],
191
- ),
192
  ]
193
 
194
- # Configure generation parameters
195
- generate_content_config = types.GenerateContentConfig(
196
- temperature=0.2,
197
- top_p=0.95,
198
- top_k=40,
199
- max_output_tokens=500,
200
- response_mime_type="text/plain",
201
- )
202
-
203
  # Generate content
204
- response = client.models.generate_content(
205
  model="gemini-1.5-flash",
206
  contents=contents,
207
- config=generate_content_config,
208
  )
209
 
210
  # Parse the response
@@ -223,7 +167,6 @@ def orchestrator(query):
223
  except Exception as e:
224
  print(f"Error parsing orchestrator response: {e}")
225
  return {"needs_api": False}
226
-
227
  # Language setting
228
 
229
  # Financial assistant system prompt
 
2
  import os
3
  import json
4
  import requests
5
+ import google.generativeai as genai # Correct import
 
6
  from dotenv import load_dotenv
7
 
8
  load_dotenv()
 
16
 
17
  # Initialize Gemini client
18
  api_key = st.secrets["GOOGLE_API_KEY"]
19
+ genai.configure(api_key=api_key) # Correct initialization
20
 
21
  # Indian Stock Market API base configuration
22
  INDIAN_API_KEY = st.secrets["FINANCE_KEY"]
 
30
  "param_mapping": {"stock_name": "name"},
31
  "description": "Get details for a specific stock"
32
  },
33
+ # ... (rest of your code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
  # Unified API call function
 
139
 
140
  # Create content for the orchestrator
141
  contents = [
142
+ {
143
+ "role": "user",
144
+ "parts": [orchestrator_prompt]
145
+ }
 
 
146
  ]
147
 
 
 
 
 
 
 
 
 
 
148
  # Generate content
149
+ response = genai.generate_content(
150
  model="gemini-1.5-flash",
151
  contents=contents,
 
152
  )
153
 
154
  # Parse the response
 
167
  except Exception as e:
168
  print(f"Error parsing orchestrator response: {e}")
169
  return {"needs_api": False}
 
170
  # Language setting
171
 
172
  # Financial assistant system prompt