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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -42
app.py CHANGED
@@ -1,55 +1,42 @@
1
  import gradio as gr
2
  import os
3
- from groq import Groq
4
  from crewai import Agent, Task, Crew, Process
 
 
5
 
6
- # Initialize the GROQ client
7
- client = Groq(
8
- api_key=os.environ["GROQ_API_KEY"],
 
9
  )
10
 
11
- def generate_text(prompt, max_tokens=500):
12
- chat_completion = client.chat.completions.create(
13
- messages=[
14
- {
15
- "role": "user",
16
- "content": prompt,
17
- }
18
- ],
19
- model="mixtral-8x7b-32768",
20
- max_tokens=max_tokens,
21
  )
22
- return chat_completion.choices[0].message.content
23
-
24
- # Custom agent class using GROQ
25
- class GroqAgent(Agent):
26
- def execute_task(self, task):
27
- prompt = f"""
28
- You are a {self.role}.
29
- Your goal is: {self.goal}
30
- Your task is: {task.description}
31
 
32
- Please complete the task based on your role and goal.
33
- """
34
- return generate_text(prompt)
35
-
36
- # Create agents
37
- researcher = GroqAgent(
38
- role='Senior Researcher',
39
- goal='Conduct thorough research on given topics',
40
- backstory='You are an experienced researcher with a keen eye for detail and the ability to find relevant information quickly.'
41
  )
42
 
43
- writer = GroqAgent(
44
- role='Content Writer',
45
- goal='Create engaging and informative content based on research',
46
- backstory='You are a skilled writer capable of turning complex information into easily understandable and engaging content.'
47
  )
48
 
49
- editor = GroqAgent(
50
- role='Editor',
51
- goal='Refine and improve the written content',
52
- backstory='You are a meticulous editor with a strong command of language and an eye for clarity and coherence.'
53
  )
54
 
55
  def create_crew(query):
@@ -92,8 +79,8 @@ iface = gr.Interface(
92
  gr.Slider(minimum=100, maximum=1000, value=500, step=50, label="Max Tokens")
93
  ],
94
  outputs=gr.Textbox(lines=10, label="AI Agent Response"),
95
- title="CrewAI-powered Chatbot using GROQ",
96
- description="Enter a query and get a researched, written, and edited response using CrewAI and GROQ API."
97
  )
98
 
99
  iface.launch()
 
1
  import gradio as gr
2
  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):
15
+ return Agent(
16
+ role=role,
17
+ goal=goal,
18
+ backstory=backstory,
19
+ verbose=True,
20
+ allow_delegation=False,
21
+ llm=groq_llm
 
22
  )
 
 
 
 
 
 
 
 
 
23
 
24
+ researcher = create_agent(
25
+ 'Senior Researcher',
26
+ 'Conduct thorough research on given topics',
27
+ 'You are an experienced researcher with a keen eye for detail and the ability to find relevant information quickly.'
 
 
 
 
 
28
  )
29
 
30
+ writer = create_agent(
31
+ 'Content Writer',
32
+ 'Create engaging and informative content based on research',
33
+ 'You are a skilled writer capable of turning complex information into easily understandable and engaging content.'
34
  )
35
 
36
+ editor = create_agent(
37
+ 'Editor',
38
+ 'Refine and improve the written content',
39
+ 'You are a meticulous editor with a strong command of language and an eye for clarity and coherence.'
40
  )
41
 
42
  def create_crew(query):
 
79
  gr.Slider(minimum=100, maximum=1000, value=500, step=50, label="Max Tokens")
80
  ],
81
  outputs=gr.Textbox(lines=10, label="AI Agent Response"),
82
+ title="CrewAI-powered Chatbot using GROQ and LangChain",
83
+ description="Enter a query and get a researched, written, and edited response using CrewAI, GROQ API, and LangChain."
84
  )
85
 
86
  iface.launch()