Didn't change much

This commit is contained in:
henri123lemoine
2023-02-05 01:41:52 -05:00
parent 639c11ad1e
commit 0155a3cc52
+17 -2
View File
@@ -313,7 +313,7 @@
" result = openai.Embedding.create(model=EMBEDDING_MODEL, input=text)\n",
" return result[\"data\"][0][\"embedding\"]\n",
" \n",
" def get_top_k(self, query: str, k: int=5) -> List[Tuple[str, str, str]]:\n",
" def get_top_k(self, query: str, k: int=10) -> List[Tuple[str, str, str]]:\n",
" # Receives a query (str) and returns the top k articles (List[Tuple[str, str, str]]) that are most similar to the query.\n",
" # Each tuple contains the title of an article, its URL, and text.\n",
" query_embedding = self.get_embedding(query)\n",
@@ -337,7 +337,22 @@
" \"model\": COMPLETIONS_MODEL,\n",
" }\n",
" answer = openai.Completion.create(prompt=prompt, **COMPLETIONS_API_PARAMS)[\"choices\"][0][\"text\"].strip(\" \\n\")\n",
" return answer"
" return answer\n",
" \n",
" def search_and_answer(self, question: str, k: int=10) -> str:\n",
" # Receives a question (str) and returns an answer (str) to the question.\n",
" top_k = self.get_top_k(question, k)\n",
" answer = self.answer_question(question, top_k)\n",
" return answer\n",
" \n",
" def summarize(self, article: str) -> str:\n",
" COMPLETIONS_API_PARAMS = {\n",
" \"temperature\": 0.0,\n",
" \"max_tokens\": 300,\n",
" \"model\": COMPLETIONS_MODEL,\n",
" }\n",
" response = openai.Completion.create(prompt=article, **COMPLETIONS_API_PARAMS)\n",
" return response[\"choices\"][0][\"text\"].strip(\" \\n\")"
]
},
{