-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample1.py
96 lines (80 loc) · 4.02 KB
/
example1.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
from dotenv import load_dotenv
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langchain_utils.cretae_embaddings import create_new_embadding
from langchain_utils.langgraph_react_agent import get_react_agent
from langchain import hub
from agental_utils.get_application import get_form_files
from agental_utils.fill_form import fill_the_form
from langchain_core.output_parsers import JsonOutputParser
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY')
os.environ["LANGCHAIN_TRACING_V2"] = os.getenv('LANGCHAIN_TRACING_V2')
os.environ["LANGCHAIN_PROJECT"] = os.getenv('LANGCHAIN_PROJECT')
os.environ['LANGCHAIN_API_KEY'] = os.getenv('LANGCHAIN_API_KEY')
new_enadding = create_new_embadding(file_path="./Mohammed_Ashraf_v5.pdf",
embadding_collection_name="my-resume",
retriever_tool_name="my_resume",
retriever_tool_description="my resume have the the information me as a machine learning engineer.")
retriever_tool =new_enadding.create_retriever_tools()
@tool
def get_anwers_about_me(query: str):
"""Useful for when you need to answer questions about me.use my resume to anwers the qustion"""
llm = ChatOpenAI(temperature=0, model="gpt-4-0125-preview", streaming=False)
prompt = hub.pull("hwchase17/openai-tools-agent")
prompt.messages[0].prompt.template = "you are help asssistent for Mohammed Ashraf.\
you need to anwers the questions asked in the job application form using the tools you have.\
incuding my contact details if needed."
agent = create_openai_tools_agent(llm, [retriever_tool], prompt)
agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool])
response = agent_executor.invoke({"input":query})
return response
@tool
def write_a_cover_letter(job_role:str,job_desc:str):
"""Useful for when you need to write a cover letter.use my resume to write a highly costomize cover letter"""
llm = ChatOpenAI(temperature=0, model="gpt-4-0125-preview", streaming=False)
prompt = hub.pull("hwchase17/openai-tools-agent")
prompt.messages[0].prompt.template = "you are help asssistent for Mohammed Ashraf.\
you need to anwers the questions asked in the job application form using the tools you have.\
i want you to write cover latter for based on the job role and the job descption.make it as custumize as posible."
agent = create_openai_tools_agent(llm, [retriever_tool], prompt)
agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool])
response = agent_executor.invoke({"input":f'{{"job_role":"{job_role}",\
"job_desc":"{job_desc}"}}'})
return response
tools = [get_anwers_about_me,write_a_cover_letter]
prompt="you are help asssistent for Mohammed Ashraf.\
you need to anwers the questions asked in the job application form using the tools you have.\
the questions will be in form stype with `qustion` and `expected anwers type`. \
find the anwers to questions and the respose.\
return JSON a object with the aswer"
grapgh_agent = get_react_agent(tools=tools,prompt=prompt)
QUERY = """
{
details[]
{
job_role
descption
all_qustions[]
{
question
type
options
}
}
}
"""
input_forms = get_form_files(url="https://forms.gle/CPSGDEiwWK7pfoxu5", query = QUERY)
filtered_data = [
{**item, 'all_qustions': [q for q in item['all_qustions'] if 'upload your resume' not in q['question'] and q.get('input_filed_type') != 'file']}
for item in input_forms
]
print(filtered_data)
inputs = {"messages": [("user", str(filtered_data))]}
result = grapgh_agent.invoke(inputs)
parser = JsonOutputParser()
json_data = parser.parse(result["messages"][-1].content)
print(json_data)
fill_the_form(url="https://forms.gle/CPSGDEiwWK7pfoxu5",form_data=json_data, resume_location_path="E:\\new_projects\\web_automation\\agent_ql\\app\\Mohammed_Ashraf_v5.pdf")