Spaces:
Build error
Build error
File size: 3,306 Bytes
dfc4889 |
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 97 98 99 100 |
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain.tools import BaseTool, StructuredTool, tool
load_dotenv()
os.environ["TAVILY_API_KEY"] = os.getenv("TAVILY_API_KEY")
os.environ["GOOGLE_API_KEY"] = os.getenv("GEMINI_API_KEY")
def tavily_search(question: str) -> str:
"""
useful for when you need to search relevant informations such as: jobs, companies from Web sites.
"""
# setup prompt
# prompt = [{
# "role": "system",
# "content": f'You are an AI critical thinker research assistant. ' \
# f'Your sole purpose is to write well written, critically acclaimed,' \
# f'objective and structured reports on given text.'
# }, {
# "role": "user",
# "content": f'Information: """{content}"""\n\n' \
# f'Using the above information, answer the following' \
# f'query: "{query}" in a detailed report --' \
# f'Please use MLA format and markdown syntax.'
# }]
tool_search = TavilySearchResults(
max_results = 3,
include_raw_content = True
)
# prompt_search = f"""You are an expert at finding information about the job,
# the company, and the skills required for that job.
# Try to find out what is relevant to the company, the job, and the skills required for that job.
# If the questions are not relevant, answer them in your own words.
#
# Query: {question}
# """
# Search
# for information on Web sites: Indeed, LinkedIn, TopCV
# by
# using
# entity in user
# question(Job
# Titles, Company, Location, etc).
# Using
# search
# pattern: site:indeed
search_prompt = f"""
Response to user question by search job descriptions include: job titles, company, required skill, education, etc related to job recruitment posts in Vietnam.
Query: {question}
"""
result = tool_search.invoke({"query": search_prompt})
# llm_chat = ChatGoogleGenerativeAI(
# model = "gemini-1.5-flash-latest",
# temperature = 0
# )
# content = []
# for i in result:
# content.append(i['content'])
# prompt = f"""
#
# You are a career consultant, based on the information you have contents: {content},
# consider yourself an expert to summarize summary details not too short the content and
# highlight the content related to the company's job and the necessary skills and return must 1 URL
#
# You can add information you know about the question {question}
# """
# response_prompt = f"""
# Generate a concise and informative summary of the results in a polite and easy-to-understand manner based on question and Tavily search results.
# Returns URLs at the end of the summary for proof.
#
# Question: {question}
# Search Results: {str(result)}
#
# Answer:
# """
# response = llm_chat.invoke(response_prompt)
return result
if __name__ == "__main__":
question = "Recruitment information for the position of Software Engineer?"
result = tavily_search(question)
print(result) |