Spaces:
Sleeping
Sleeping
typesdigital
commited on
Commit
•
135b01f
1
Parent(s):
e7028c7
Update app.py
Browse files
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 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
"max_tokens": 500
|
41 |
-
}
|
42 |
-
}
|
43 |
-
)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
'
|
48 |
-
'
|
|
|
49 |
)
|
50 |
|
51 |
-
writer =
|
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 =
|
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 |
|