Google Serper 검색 도구(SerperDevTool)
Google Serper 검색 도구(SerperDevTool)
에이전트가 인터넷에서 최신 정보를 찾아야 할 때 가장 흔히 쓰는 도구가 웹 검색입니다. SerperDevTool은 serper.dev API를 기반으로 질의에 맞는 가장 관련성 높은 검색 결과를 가져다 주는 도구예요. 무료 티어가 있어서 시작하기도 쉽습니다.
출처: 공식문서
본문
설명
이 도구는 텍스트 콘텐츠에서 지정된 질의에 대해 인터넷 전역에서 의미 검색(semantic search)을 수행하도록 설계되었습니다. 사용자가 제공한 질의를 바탕으로 가장 관련성 높은 검색 결과를 가져와 보여 주기 위해 serper.dev API를 활용합니다.
설치
SerperDevTool을 효과적으로 쓰려면 다음 단계를 따르세요.
- 패키지 설치: Python 환경에
crewai[tools]패키지가 설치되어 있는지 확인합니다. - API 키 획득: https://serper.dev/에서
serper.devAPI 키를 얻습니다(무료 티어 사용 가능). - 환경 구성: 얻은 API 키를
SERPER_API_KEY라는 환경 변수에 저장해 도구가 사용할 수 있게 합니다.
프로젝트에 이 도구를 넣으려면 아래 설치 지침을 따르세요.
pip install 'crewai[tools]'
예제
from crewai_tools import SerperDevTool
# Initialize the tool for internet searching capabilities
tool = SerperDevTool()
파라미터
SerperDevTool에는 API로 전달되는 여러 파라미터가 있습니다.
- search_url: 검색 API의 URL 엔드포인트. (기본값
https://google.serper.dev/search) - country: 옵션. 검색 결과에 대한 국가를 지정합니다.
- location: 옵션. 검색 결과에 대한 위치를 지정합니다.
- locale: 옵션. 검색 결과에 대한 로케일을 지정합니다.
- n_results: 반환할 검색 결과 수. 기본값은
10.
country, location, locale, search_url 값은 Serper Playground에서 확인할 수 있습니다.
파라미터 사용 예제
from crewai_tools import SerperDevTool
tool = SerperDevTool(
search_url="https://google.serper.dev/scholar",
n_results=2,
)
print(tool.run(search_query="ChatGPT"))
# Using Tool: Search the internet
# Search results: Title: Role of chat gpt in public health
# Link: https://link.springer.com/article/10.1007/s10439-023-03172-7
# Snippet: … ChatGPT in public health. In this overview, we will examine the potential uses of ChatGPT in
# ---
# Title: Potential use of chat gpt in global warming
# Link: https://link.springer.com/article/10.1007/s10439-023-03171-8
# Snippet: … as ChatGPT, have the potential to play a critical role in advancing our understanding of climate
# ---
from crewai_tools import SerperDevTool
tool = SerperDevTool(
country="fr",
locale="fr",
location="Paris, Paris, Ile-de-France, France",
n_results=2,
)
print(tool.run(search_query="Jeux Olympiques"))
# Using Tool: Search the internet
# Search results: Title: Jeux Olympiques de Paris 2024 - Actualités, calendriers, résultats
# Link: https://olympics.com/fr/paris-2024
# Snippet: Quels sont les sports présents aux Jeux Olympiques de Paris 2024 ? · Athlétisme · Aviron · Badminton · Basketball · Basketball 3x3 · Boxe · Breaking · Canoë ...
# ---
# Title: Billetterie Officielle de Paris 2024 - Jeux Olympiques et Paralympiques
# Link: https://tickets.paris2024.org/
# Snippet: Achetez vos billets exclusivement sur le site officiel de la billetterie de Paris 2024 pour participer au plus grand événement sportif au monde.
# ---
결론
SerperDevTool을 Python 프로젝트에 통합하면 애플리케이션에서 직접 실시간으로 관련성 높은 웹 검색을 수행할 수 있습니다. 업데이트된 파라미터 덕분에 더 개인화되고 지역화된 검색 결과가 가능해요. 설정·사용 지침을 따르면 프로젝트에 간단하게 통합할 수 있습니다.