Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 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 |
-
|
| 33 |
-
|
| 34 |
-
|
| 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 =
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
)
|
| 48 |
|
| 49 |
-
editor =
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 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
|
| 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()
|