File size: 1,789 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
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from tavily import TavilyClient
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.
    """

    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}
    """

    tavily = TavilyClient(
        api_key = os.environ["TAVILY_API_KEY"],
    )

    response = tavily.search(
        query = question,
        include_raw_content = True,
        max_results = 5
    )

    search_results = ""
    for obj in response["results"]:
        search_results += f"""
- Page content: {obj["raw_content"]}
Source: {obj["url"]}
          
        """

    print(search_results)

    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: 
    {search_results}

    Answer:
    """

    # return context

def tavily_qna_search(question: str) -> str:
    tavily = TavilyClient(
        api_key=os.environ["TAVILY_API_KEY"],
    )

    response = tavily.qna_search(query=question)
    return response

if __name__ == "__main__":
    question = "Software Engineer job postings in Vietnam"

    result = tavily_search(question)
    print(result)