728x90
이번엔 GPT를 활용하여!!
최신 검색결과를 알아볼까요!
pip install google-search-results
시작 전 필요한 패키지를 설치합니다!
오늘의 코드는 간단하기에! 금방 진행됩니다!!
from langchain.llms.openai import OpenAI
from langchain.agents import load_tools, initialize_agent
search_query = "일등박사"
# Initialize the OpenAI module, load the SerpApi tool, and run the search query using an agent
llm=OpenAI(temperature=0, openai_api_key='{나의 openai key}', verbose=True)
tools = load_tools(["serpapi"], llm, serpapi_api_key="{나의 serpapi key}")
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
result = agent.run(search_query)
result
탐색 주제는!! search_query에 입력한 일등박사!!
결과가 어떘을까요~!
langchain 패키지는 serpapi를 통하여 구글검색을 진행하고!!
그 결과!! 아래와 같이 멋지게 일등박사의 검색결과를 소개해주었습니다!
'일등박사 is a term that refers to a top-ranked scientist or engineer in South Korea, known for their expertise in data analysis and blockchain technology. They have worked at Samsung Electronics and have also pursued a PhD in AI before transitioning to focus on blockchain. They have published books and given public performances, and also have an online presence through their blog and social media.' |
ㅁ 참고 : https://github.com/alphasecio/langchain-examples/blob/main/search/langchain_search.ipynb
728x90
'데이터&AI > langchain' 카테고리의 다른 글
[langchain공부] SimpleJsonOutputParser (json으로 결과도출!!) (0) | 2024.02.02 |
---|---|
[langchain공부] langchain 기초 - 5 (뉴스결과 요약해!!) (2) | 2024.02.02 |
[langchain공부] langchain 기초 - 4 (사이트 요약해!!) (0) | 2024.02.01 |
[langchain공부] langchain 기초 - 2 (feat. function call. 함수호출하기) (1) | 2024.01.26 |
[langchain공부] langchain 기초 - 1 (feat. GPT api와의 비교) (1) | 2024.01.25 |
댓글