typesdigital commited on
Commit
e65bfec
1 Parent(s): 4b2acb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -3,12 +3,25 @@ import os
3
  from crewai import Agent, Task, Crew, Process
4
  from langchain_groq import ChatGroq
5
  from langchain.schema import HumanMessage
 
6
 
7
  # Initialize the GROQ language model
8
- groq_llm = ChatGroq(
9
- groq_api_key=os.environ["GROQ_API_KEY"],
10
- model_name="mixtral-8x7b-32768"
11
- )
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Create agents
14
  def create_agent(role, goal, backstory):
@@ -67,9 +80,16 @@ def create_crew(query):
67
  return crew
68
 
69
  def process_query(query, max_tokens=500):
70
- crew = create_crew(query)
71
- result = crew.kickoff()
72
- return result
 
 
 
 
 
 
 
73
 
74
  # Create the Gradio interface
75
  iface = gr.Interface(
 
3
  from crewai import Agent, Task, Crew, Process
4
  from langchain_groq import ChatGroq
5
  from langchain.schema import HumanMessage
6
+ import time
7
 
8
  # Initialize the GROQ language model
9
+ try:
10
+ groq_llm = ChatGroq(
11
+ groq_api_key=os.environ["GROQ_API_KEY"],
12
+ model_name="mixtral-8x7b-32768"
13
+ )
14
+ except Exception as e:
15
+ print(f"Error initializing GROQ LLM: {e}")
16
+ groq_llm = None
17
+
18
+ def simple_groq_query(query):
19
+ try:
20
+ response = groq_llm([HumanMessage(content=query)])
21
+ return response.content
22
+ except Exception as e:
23
+ print(f"Error in simple GROQ query: {e}")
24
+ return f"I apologize, but I'm having trouble processing your request at the moment. Here's what I can say: {query} is an interesting topic. Could you please try again in a moment?"
25
 
26
  # Create agents
27
  def create_agent(role, goal, backstory):
 
80
  return crew
81
 
82
  def process_query(query, max_tokens=500):
83
+ try:
84
+ if not groq_llm:
85
+ raise Exception("GROQ LLM not initialized")
86
+
87
+ crew = create_crew(query)
88
+ result = crew.kickoff()
89
+ return result
90
+ except Exception as e:
91
+ print(f"Error in process_query: {e}")
92
+ return simple_groq_query(query)
93
 
94
  # Create the Gradio interface
95
  iface = gr.Interface(