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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -33
app.py CHANGED
@@ -2,17 +2,12 @@ import gradio as gr
2
  import os
3
  from groq import Groq
4
  from crewai import Agent, Task, Crew, Process
5
- from langchain_community.tools import DuckDuckGoSearchRun
6
 
7
  # Initialize the GROQ client
8
  client = Groq(
9
  api_key=os.environ["GROQ_API_KEY"],
10
  )
11
 
12
- # Initialize the search tool
13
- search_tool = DuckDuckGoSearchRun()
14
-
15
- # Create a function to generate text using GROQ
16
  def generate_text(prompt, max_tokens=500):
17
  chat_completion = client.chat.completions.create(
18
  messages=[
@@ -26,38 +21,35 @@ def generate_text(prompt, max_tokens=500):
26
  )
27
  return chat_completion.choices[0].message.content
28
 
29
- # Create agents using the GROQ text generation function
30
- def create_agent(role, goal, backstory):
31
- return Agent(
32
- role=role,
33
- goal=goal,
34
- backstory=backstory,
35
- verbose=True,
36
- allow_delegation=False,
37
- llm_config={
38
- "function": generate_text,
39
- "config": {
40
- "max_tokens": 500
41
- }
42
- }
43
- )
44
 
45
- researcher = create_agent(
46
- 'Senior Researcher',
47
- 'Conduct thorough research on given topics',
48
- 'You are an experienced researcher with a keen eye for detail and the ability to find relevant information quickly.'
 
49
  )
50
 
51
- writer = create_agent(
52
- 'Content Writer',
53
- 'Create engaging and informative content based on research',
54
- 'You are a skilled writer capable of turning complex information into easily understandable and engaging content.'
55
  )
56
 
57
- editor = create_agent(
58
- 'Editor',
59
- 'Refine and improve the written content',
60
- 'You are a meticulous editor with a strong command of language and an eye for clarity and coherence.'
61
  )
62
 
63
  def create_crew(query):
@@ -100,7 +92,7 @@ iface = gr.Interface(
100
  gr.Slider(minimum=100, maximum=1000, value=500, step=50, label="Max Tokens")
101
  ],
102
  outputs=gr.Textbox(lines=10, label="AI Agent Response"),
103
- title="CrewAI-powered Chatbot",
104
  description="Enter a query and get a researched, written, and edited response using CrewAI and GROQ API."
105
  )
106
 
 
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=[
 
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
  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