Spaces:
Sleeping
Sleeping
edit secret key
Browse files- Promptless_LLM_Agent.py +64 -63
Promptless_LLM_Agent.py
CHANGED
|
@@ -1,64 +1,65 @@
|
|
| 1 |
-
# Warning control
|
| 2 |
-
import warnings
|
| 3 |
-
warnings.filterwarnings('ignore')
|
| 4 |
-
|
| 5 |
-
from typing import List
|
| 6 |
-
import json
|
| 7 |
-
from pydantic import BaseModel
|
| 8 |
-
# from langchain_community.llms import HuggingFaceHub
|
| 9 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
| 10 |
-
from crewai import Agent, Task, Crew
|
| 11 |
-
|
| 12 |
-
import os
|
| 13 |
-
from dotenv import load_dotenv, find_dotenv
|
| 14 |
-
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 15 |
-
hf_api_key = os.environ['HF_API_KEY']
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
"
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
result =
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
return userDefinedQuestions
|
|
|
|
| 1 |
+
# Warning control
|
| 2 |
+
import warnings
|
| 3 |
+
warnings.filterwarnings('ignore')
|
| 4 |
+
|
| 5 |
+
from typing import List
|
| 6 |
+
import json
|
| 7 |
+
from pydantic import BaseModel
|
| 8 |
+
# from langchain_community.llms import HuggingFaceHub
|
| 9 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 10 |
+
from crewai import Agent, Task, Crew
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
from dotenv import load_dotenv, find_dotenv
|
| 14 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 15 |
+
# hf_api_key = os.environ['HF_API_KEY']
|
| 16 |
+
hf_api_key = os.getenv('HF_API_KEY')
|
| 17 |
+
|
| 18 |
+
llm = HuggingFaceEndpoint(
|
| 19 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta",
|
| 20 |
+
huggingfacehub_api_token=hf_api_key,
|
| 21 |
+
task="text-generation"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
graphicDesigner = Agent(
|
| 25 |
+
role="Graphic Designer",
|
| 26 |
+
goal="Provide the list of relevant questions that can be ask to user based on his/her requirement: {requirement}",
|
| 27 |
+
backstory="You're working as expert graphic designer "
|
| 28 |
+
"A user has shared with you the requirement: {requirement}."
|
| 29 |
+
"Use information present in requirement"
|
| 30 |
+
"and provide the list of questions that can be asked to user"
|
| 31 |
+
"to gather more specific information based on requirement",
|
| 32 |
+
llm=llm,
|
| 33 |
+
allow_delegation=False,
|
| 34 |
+
verbose=False
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
class Questions(BaseModel):
|
| 38 |
+
QuestionsList: List[str]
|
| 39 |
+
|
| 40 |
+
Ask_questions = Task(
|
| 41 |
+
description=(
|
| 42 |
+
"Provide the list of relevant questions that can be ask to user to gather more specific information based on requirement: {requirement}"
|
| 43 |
+
),
|
| 44 |
+
expected_output="List of relevant questions based on user requirement. output only questions",
|
| 45 |
+
# output_json=Questions,
|
| 46 |
+
agent=graphicDesigner,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
crew = Crew(
|
| 50 |
+
agents=[graphicDesigner],
|
| 51 |
+
tasks=[Ask_questions],
|
| 52 |
+
verbose=False
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
def questions(requirement, userDefinedQuestions=None):
|
| 56 |
+
# "I want a logo for my new business."
|
| 57 |
+
|
| 58 |
+
if not userDefinedQuestions:
|
| 59 |
+
result = crew.kickoff(inputs={"requirement": requirement})
|
| 60 |
+
result = result.split('\n')
|
| 61 |
+
# json_dict = json.loads(result)
|
| 62 |
+
questions = [i.split('. ')[1] for i in result]
|
| 63 |
+
return questions
|
| 64 |
+
else:
|
| 65 |
return userDefinedQuestions
|