본문 바로가기
데이터&AI/langchain

[langchain공부] langchain 기초 - 3 (feat. 검색결과!!)

by 일등박사 2024. 2. 1.

이번엔 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

댓글