|
|
@ -49,7 +49,7 @@
|
|
|
|
"outputs": [],
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
"%%capture\n",
|
|
|
|
"%%capture\n",
|
|
|
|
"%env NEWS_API_KEY = YOUR_API_KEY\n"
|
|
|
|
"%env NEWS_API_KEY = YOUR_NEWS_API_KEY\n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -93,7 +93,7 @@
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"def embeddings(input: list[str]) -> list[list[str]]:\n",
|
|
|
|
"def embeddings(input: list[str]) -> list[list[str]]:\n",
|
|
|
|
" response = openai.Embedding.create(model=\"text-embedding-ada-002\", input=input)\n",
|
|
|
|
" response = openai.Embedding.create(model=\"text-embedding-ada-002\", input=input)\n",
|
|
|
|
" return [data.embedding for data in response.data]"
|
|
|
|
" return [data.embedding for data in response.data]\n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -113,7 +113,7 @@
|
|
|
|
"outputs": [],
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
"# User asks a question\n",
|
|
|
|
"# User asks a question\n",
|
|
|
|
"USER_QUESTION = \"Who won the NBA championship? And who was the MVP? Tell me a bit about the last game.\""
|
|
|
|
"USER_QUESTION = \"Who won the NBA championship? And who was the MVP? Tell me a bit about the last game.\"\n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -179,7 +179,7 @@
|
|
|
|
"# Let's include the original question as well for good measure\n",
|
|
|
|
"# Let's include the original question as well for good measure\n",
|
|
|
|
"queries.append(USER_QUESTION)\n",
|
|
|
|
"queries.append(USER_QUESTION)\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"queries"
|
|
|
|
"queries\n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -282,7 +282,7 @@
|
|
|
|
" print(\"Title:\", article[\"title\"])\n",
|
|
|
|
" print(\"Title:\", article[\"title\"])\n",
|
|
|
|
" print(\"Description:\", article[\"description\"])\n",
|
|
|
|
" print(\"Description:\", article[\"description\"])\n",
|
|
|
|
" print(\"Content:\", article[\"content\"][0:100] + \"...\")\n",
|
|
|
|
" print(\"Content:\", article[\"content\"][0:100] + \"...\")\n",
|
|
|
|
" print()\n"
|
|
|
|
" print()"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -326,7 +326,7 @@
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"hypothetical_answer = json_gpt(HA_INPUT)[\"hypotheticalAnswer\"]\n",
|
|
|
|
"hypothetical_answer = json_gpt(HA_INPUT)[\"hypotheticalAnswer\"]\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"hypothetical_answer\n"
|
|
|
|
"hypothetical_answer"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -376,7 +376,7 @@
|
|
|
|
"for article_embedding in article_embeddings:\n",
|
|
|
|
"for article_embedding in article_embeddings:\n",
|
|
|
|
" cosine_similarities.append(dot(hypothetical_answer_embedding, article_embedding))\n",
|
|
|
|
" cosine_similarities.append(dot(hypothetical_answer_embedding, article_embedding))\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"cosine_similarities[0:10]\n"
|
|
|
|
"cosine_similarities[0:10]"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -440,7 +440,7 @@
|
|
|
|
" print(\"Description:\", article[\"description\"])\n",
|
|
|
|
" print(\"Description:\", article[\"description\"])\n",
|
|
|
|
" print(\"Content:\", article[\"content\"][0:100] + \"...\")\n",
|
|
|
|
" print(\"Content:\", article[\"content\"][0:100] + \"...\")\n",
|
|
|
|
" print(\"Score:\", score)\n",
|
|
|
|
" print(\"Score:\", score)\n",
|
|
|
|
" print()\n"
|
|
|
|
" print()"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -500,7 +500,7 @@
|
|
|
|
"for chunk in completion:\n",
|
|
|
|
"for chunk in completion:\n",
|
|
|
|
" text += chunk.choices[0].delta.get(\"content\", \"\")\n",
|
|
|
|
" text += chunk.choices[0].delta.get(\"content\", \"\")\n",
|
|
|
|
" display.clear_output(wait=True)\n",
|
|
|
|
" display.clear_output(wait=True)\n",
|
|
|
|
" display.display(display.Markdown(text))"
|
|
|
|
" display.display(display.Markdown(text))\n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
|
|
|