-
Notifications
You must be signed in to change notification settings - Fork 0
/
LLMs.py
70 lines (49 loc) · 2.86 KB
/
LLMs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
60
61
62
63
64
65
66
from langchain_core.prompts import ChatPromptTemplate
from pydantic import BaseModel, Field
from langchain_fireworks import ChatFireworks
from dotenv import load_dotenv
import os
load_dotenv()
class Extractor_Output(BaseModel):
Response : str = Field(..., description="This is your Response in a form of a python dictionary")
class Gnerator_Output(BaseModel):
query : str = Field(..., description="This is the query to search for in the Store of Informations")
Done : str = Field(..., description="This is a boolean value indicating if all informations are found or not")
llm = ChatFireworks(api_key=os.getenv("FIREWORKS_API_KEY"),model="accounts/fireworks/models/mixtral-8x22b-instruct",temperature=0.7)
structured_llm_extractor = llm.with_structured_output(Extractor_Output)
structured_llm_generator = llm.with_structured_output(Gnerator_Output)
# Prompt
system_extractor = """You are an expert Youtubers scraper.\n
Given a banch of Informations(from the Web, Videos Transcriptions...), You have to extract main informations about a youtuber like (First and Last name, Main Topics, Email adresss, ...).\n
Steps To Perform Your Task :\n
1. Observe The Informations we already have.\n {Extracted_infos}.
2. Think in Outher keys we can add to what we have .\n
3. Use The provided Context to extract informations associeted to this keys.\n
**Important Note** \n
- Your Response must be in a form of a python dictionary with keys like (First_Name,Last_Name,Topics,bio,Github,Discord,Email,linkden,Twetter of the youtuber,...).\n
"""
system_generator = """You are an expert at Gnerating search queries.\n
Steps To Perform Your First Task :\n
1. Observe The extracted data by your Team memeber (Extractor) \n
2. Try to find what are the missing informations in this data.(like None or Not found)\n
3. Generate a query to search in the Informations's Store, In order to find these missing informations.\n
**Important Note : **
- If The Extractor response is None ,Your String Query should be like this : "Youtube Channel {Youtube_handle}".
Your second Task is :\n
- Respond with "Yes" if all fields of the Extractor response are filled with correct informations.Outherwise respond with "No".\n
- The Extractor response fields are (First_Name,Last_Name,Topics,bio,Github,Discord,Email,linkden,Twetter of the youtuber,...).\n
"""
prompt_extractor = ChatPromptTemplate.from_messages(
[
("system", system_extractor),
("human", """Extract all informations about the youtuber.\n A help data here :\n {Content} .\n"""),
]
)
prompt_generator = ChatPromptTemplate.from_messages(
[
("system", system_generator),
("human", """The data extracted by the Extractor is :\n {Informations} """),
]
)
Extractor = prompt_extractor | structured_llm_extractor
Generator = prompt_generator | structured_llm_generator