Refreshed notebooks, particularly with new Week 1

This commit is contained in:
Edward Donner
2024-11-13 15:46:22 +00:00
parent 6ba1875cd3
commit 21c7a8155c
34 changed files with 2331 additions and 410 deletions

View File

@@ -313,7 +313,7 @@
"# the retriever is an abstraction over the VectorStore that will be used during RAG\n",
"retriever = vectorstore.as_retriever()\n",
"\n",
"# putting it together: set up the conversation chain with the GPT 3.5 LLM, the vector store and memory\n",
"# putting it together: set up the conversation chain with the GPT 4o-mini LLM, the vector store and memory\n",
"conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory)"
]
},
@@ -329,6 +329,20 @@
"print(result[\"answer\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6eb99fb-33ec-4025-ab92-b634ede03647",
"metadata": {},
"outputs": [],
"source": [
"# set up a new conversation memory for the chat\n",
"memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)\n",
"\n",
"# putting it together: set up the conversation chain with the GPT 4o-mini LLM, the vector store and memory\n",
"conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory)"
]
},
{
"cell_type": "markdown",
"id": "bbbcb659-13ce-47ab-8a5e-01b930494964",
@@ -346,7 +360,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Wrapping that in a function\n",
"# Wrapping in a function - note that history isn't used, as the memory is in the conversation_chain\n",
"\n",
"def chat(message, history):\n",
" result = conversation_chain.invoke({\"question\": message})\n",
@@ -362,7 +376,7 @@
"source": [
"# And in Gradio:\n",
"\n",
"view = gr.ChatInterface(chat).launch()"
"view = gr.ChatInterface(chat, type=\"messages\").launch(inbrowser=True)"
]
},
{