mjolnir1122 commited on
Commit
81a65c3
·
verified ·
1 Parent(s): ec68136

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -142,15 +142,15 @@ def calculate_cost(method, water_cost, water_purification_cost, energy_source, e
142
 
143
  def call_groq_api(user_inputs, production_data, cost_data):
144
  """Call Groq API with Llama 3 to analyze production parameters and provide recommendations"""
145
-
146
  # Initialize Groq client
147
  try:
148
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
149
  except Exception as e:
150
  return {"error": f"Failed to initialize Groq client: {str(e)}"}
151
 
152
- # Format inputs for the API
153
- prompt = f"""
154
  As a hydrogen production expert, analyze the following electrolysis parameters and provide recommendations for optimization:
155
 
156
  Input Parameters:
@@ -183,6 +183,10 @@ def call_groq_api(user_inputs, production_data, cost_data):
183
  4. An ideal parameter configuration based on the provided inputs
184
 
185
  Format your response as a structured JSON with these fields:
 
 
 
 
186
  {
187
  "efficiency_assessment": "text analysis",
188
  "efficiency_recommendations": ["recommendation1", "recommendation2", "recommendation3"],
@@ -201,6 +205,9 @@ def call_groq_api(user_inputs, production_data, cost_data):
201
  }
202
  """
203
 
 
 
 
204
  try:
205
  # Call Groq API using the client
206
  chat_completion = client.chat.completions.create(
 
142
 
143
  def call_groq_api(user_inputs, production_data, cost_data):
144
  """Call Groq API with Llama 3 to analyze production parameters and provide recommendations"""
145
+
146
  # Initialize Groq client
147
  try:
148
+ client = Groq(api_key=os.environ.get("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"))
149
  except Exception as e:
150
  return {"error": f"Failed to initialize Groq client: {str(e)}"}
151
 
152
+ # Prepare the prompt without f-string for the JSON schema part
153
+ prompt_part1 = f"""
154
  As a hydrogen production expert, analyze the following electrolysis parameters and provide recommendations for optimization:
155
 
156
  Input Parameters:
 
183
  4. An ideal parameter configuration based on the provided inputs
184
 
185
  Format your response as a structured JSON with these fields:
186
+ """
187
+
188
+ # The JSON schema part without using f-string
189
+ prompt_part2 = """
190
  {
191
  "efficiency_assessment": "text analysis",
192
  "efficiency_recommendations": ["recommendation1", "recommendation2", "recommendation3"],
 
205
  }
206
  """
207
 
208
+ # Combine the parts
209
+ prompt = prompt_part1 + prompt_part2
210
+
211
  try:
212
  # Call Groq API using the client
213
  chat_completion = client.chat.completions.create(