You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.9 KiB
81 lines
1.9 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Cook Search APIs\n",
|
|
"- This notebook is used to cook search APIs like Tavily and Serper."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import http.client\n",
|
|
"import json\n",
|
|
"import os\n",
|
|
"\n",
|
|
"from dotenv import load_dotenv\n",
|
|
"\n",
|
|
"load_dotenv(override=True)\n",
|
|
"\n",
|
|
"# https://docs.spaceserp.com/serp-api\n",
|
|
"conn = http.client.HTTPSConnection(\"google.serper.dev\")\n",
|
|
"payload = json.dumps({\"q\": \"apple inc\"})\n",
|
|
"headers = {\n",
|
|
" \"X-API-KEY\": os.getenv(\"SERPER_API_KEY\"),\n",
|
|
" \"Content-Type\": \"application/json\",\n",
|
|
"}\n",
|
|
"conn.request(\"POST\", \"/search\", payload, headers)\n",
|
|
"res = conn.getresponse()\n",
|
|
"data = res.read()\n",
|
|
"print(data.decode(\"utf-8\"))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"from dotenv import load_dotenv\n",
|
|
"from tavily import TavilyClient\n",
|
|
"\n",
|
|
"load_dotenv(override=True)\n",
|
|
"\n",
|
|
"tavily_client = TavilyClient(api_key=os.getenv(\"TAVILY_API_KEY\"))\n",
|
|
"# https://docs.tavily.com/documentation/api-reference/endpoint/search\n",
|
|
"response = tavily_client.search(\n",
|
|
" query=\"Who is Leo Messi?\",\n",
|
|
" search_depth=\"basic\",\n",
|
|
" topic=\"general\",\n",
|
|
" max_results=2,\n",
|
|
" include_answer=True,\n",
|
|
" include_raw_content=False,\n",
|
|
" include_images=False,\n",
|
|
")\n",
|
|
"\n",
|
|
"print(response)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "deepsearch-py311-2",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.11.11"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|