arvindershinh commited on
Commit
5a39c8a
·
verified ·
1 Parent(s): f35cb88

edit secret key

Browse files
Files changed (1) hide show
  1. 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
- llm = HuggingFaceEndpoint(
18
- repo_id="HuggingFaceH4/zephyr-7b-beta",
19
- huggingfacehub_api_token=hf_api_key,
20
- task="text-generation"
21
- )
22
-
23
- graphicDesigner = Agent(
24
- role="Graphic Designer",
25
- goal="Provide the list of relevant questions that can be ask to user based on his/her requirement: {requirement}",
26
- backstory="You're working as expert graphic designer "
27
- "A user has shared with you the requirement: {requirement}."
28
- "Use information present in requirement"
29
- "and provide the list of questions that can be asked to user"
30
- "to gather more specific information based on requirement",
31
- llm=llm,
32
- allow_delegation=False,
33
- verbose=False
34
- )
35
-
36
- class Questions(BaseModel):
37
- QuestionsList: List[str]
38
-
39
- Ask_questions = Task(
40
- description=(
41
- "Provide the list of relevant questions that can be ask to user to gather more specific information based on requirement: {requirement}"
42
- ),
43
- expected_output="List of relevant questions based on user requirement. output only questions",
44
- # output_json=Questions,
45
- agent=graphicDesigner,
46
- )
47
-
48
- crew = Crew(
49
- agents=[graphicDesigner],
50
- tasks=[Ask_questions],
51
- verbose=False
52
- )
53
-
54
- def questions(requirement, userDefinedQuestions=None):
55
- # "I want a logo for my new business."
56
-
57
- if not userDefinedQuestions:
58
- result = crew.kickoff(inputs={"requirement": requirement})
59
- result = result.split('\n')
60
- # json_dict = json.loads(result)
61
- questions = [i.split('. ')[1] for i in result]
62
- return questions
63
- else:
 
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