Bootcamp: Solisoma(week5 assesment)

This commit is contained in:
unknown
2025-10-24 09:13:17 +01:00
parent 7eeb1b5ba3
commit d59b552808

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 6,
"id": "3d526a96", "id": "3d526a96",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -25,7 +25,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"id": "3d14dedb", "id": "3d14dedb",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -58,7 +58,6 @@
" \n", " \n",
" current_path = Path.cwd()\n", " current_path = Path.cwd()\n",
" \n", " \n",
" # Walk up the directory tree\n",
" while current_path != current_path.parent:\n", " while current_path != current_path.parent:\n",
" for indicator in self.root_indicators:\n", " for indicator in self.root_indicators:\n",
" if (current_path / indicator).exists():\n", " if (current_path / indicator).exists():\n",
@@ -70,7 +69,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 8,
"id": "fa781fd3", "id": "fa781fd3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -123,7 +122,7 @@
" model_name=self.MODEL\n", " model_name=self.MODEL\n",
" )\n", " )\n",
" self.root_folder = ProjectRootDetector().find_root(root_path=root_path, use_file_path_as_root=use_file_path_as_root)\n", " self.root_folder = ProjectRootDetector().find_root(root_path=root_path, use_file_path_as_root=use_file_path_as_root)\n",
" self.agent = None # Initialize agent as None\n", " self.agent = None \n",
"\n", "\n",
" \n", " \n",
" def get_file(self, file_name: str):\n", " def get_file(self, file_name: str):\n",
@@ -131,8 +130,13 @@
" for root, dirs, files in os.walk(self.root_folder):\n", " for root, dirs, files in os.walk(self.root_folder):\n",
" print(files, flush=True)\n", " print(files, flush=True)\n",
" for f in files:\n", " for f in files:\n",
" if \".\" in file_name:\n",
" if f == file_name:\n", " if f == file_name:\n",
" matches.append(os.path.join(root, f))\n", " matches.append(os.path.join(root, f))\n",
" else:\n",
" base_file_name = file_name.split(\".\")[0]\n",
" if file_name == base_file_name:\n",
" matches.append(os.path.join(root, f))\n",
"\n", "\n",
" if not matches:\n", " if not matches:\n",
" return f\"No file named '{file_name}' found in the repository.\"\n", " return f\"No file named '{file_name}' found in the repository.\"\n",
@@ -223,7 +227,6 @@
" chain_type=\"stuff\"\n", " chain_type=\"stuff\"\n",
" )\n", " )\n",
"\n", "\n",
" # Wrap RAG chain as a Tool\n",
" rag_tool = Tool(\n", " rag_tool = Tool(\n",
" name=\"repo_context_search\",\n", " name=\"repo_context_search\",\n",
" func=lambda q: rag_chain.run(q),\n", " func=lambda q: rag_chain.run(q),\n",
@@ -240,12 +243,12 @@
" return self.get_file(x)\n", " return self.get_file(x)\n",
"\n", "\n",
" tools = [rag_tool, get_file]\n", " tools = [rag_tool, get_file]\n",
" # Alternative: Use system message in memory\n", " \n",
" memory = ConversationBufferMemory(\n", " memory = ConversationBufferMemory(\n",
" memory_key=\"chat_history\", \n", " memory_key=\"chat_history\", \n",
" input_key=\"input\", \n", " input_key=\"input\", \n",
" return_messages=True,\n", " return_messages=True,\n",
" system_message=self.system_prompt # Add system message here\n", " system_message=self.system_prompt \n",
" )\n", " )\n",
"\n", "\n",
" agent = initialize_agent(\n", " agent = initialize_agent(\n",
@@ -255,7 +258,6 @@
" handle_parsing_errors=True,\n", " handle_parsing_errors=True,\n",
" memory=memory,\n", " memory=memory,\n",
" verbose=True\n", " verbose=True\n",
" # Remove agent_kwargs since we're using memory system_message\n",
" )\n", " )\n",
"\n", "\n",
" return agent\n", " return agent\n",
@@ -278,7 +280,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 9,
"id": "075a4612", "id": "075a4612",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -291,492 +293,38 @@
"execution_count": null, "execution_count": null,
"id": "4f16318f", "id": "4f16318f",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7860\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_44004\\2054011777.py:131: LangChainDeprecationWarning: The class `OpenAIEmbeddings` was deprecated in LangChain 0.0.9 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-openai package and should be used instead. To use it run `pip install -U :class:`~langchain-openai` and import as `from :class:`~langchain_openai import OpenAIEmbeddings``.\n",
" embeddings = OpenAIEmbeddings()\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_44004\\2054011777.py:167: LangChainDeprecationWarning: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/\n",
" memory = ConversationBufferMemory(\n",
"C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_44004\\2054011777.py:174: LangChainDeprecationWarning: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the `LangGraph documentation <https://langchain-ai.github.io/langgraph/>`_ as well as guides for `Migrating from AgentExecutor <https://python.langchain.com/docs/how_to/migrate_agent/>`_ and LangGraph's `Pre-built ReAct agent <https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/>`_.\n",
" agent = initialize_agent(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI need to search the repository for the specific implementation of the `load_knowledge_base` function to explain its functionality line by line. \n",
"Action: repo_context_search \n",
"Action Input: \"load_knowledge_base\" \u001b[0m"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_44004\\2054011777.py:152: LangChainDeprecationWarning: The method `Chain.run` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use :meth:`~invoke` instead.\n",
" func=lambda q: rag_chain.run(q),\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that my initial search for the `load_knowledge_base` function did not return any results. I'll try to broaden my search to find any definitions or references to `load_knowledge_base` in the repository. \n",
"Action: repo_context_search \n",
"Action Input: \"def load_knowledge_base\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt appears that I'm unable to locate the `load_knowledge_base` function in the repository. It's possible that the function might be named differently or located in a different part of the codebase than I expected. I will try searching for just \"load\" in the hopes of finding related functions or any relevant implementations that could help identify the correct function. \n",
"Action: repo_context_search \n",
"Action Input: \"load\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know what you mean by \"load.\" Could you please provide more context or clarify your question?\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that I am unable to find the `load_knowledge_base` function or any related code in the repository using my previous attempts. This may suggest that the function is named differently or is not present in the repository. I should try to search for a broader context or related keywords that might help me identify the function or similar functionalities within the codebase.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"knowledge_base\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that my attempts to locate the `load_knowledge_base` function have not yielded any results. I may need to gather more context about the repository or the knowledge base functionality to understand how to proceed. If there are any specific files or components related to knowledge bases, that could lead me to the relevant implementation. \n",
"\n",
"I will now search for files that might be related to knowledge bases in general, looking for terms that could be associated with their implementation. \n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"knowledge\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that my repeated attempts to find the `load_knowledge_base` function or any relevant information in the repository have not been successful. I should consider that the function might not exist or that it is perhaps named in a way that does not match my search queries. \n",
"\n",
"To proceed, I will check the repository structure or any documentation that might provide insights into where knowledge base functions are typically defined or how they are implemented. \n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"functions\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mThe main functions of the Tourist Assistant include:\n",
"\n",
"1. **Text and Voice Input:** Users can type questions or use the microphone to ask questions about tourist destinations.\n",
" \n",
"2. **Location Setting:** Users can set their current location to get tailored information about nearby attractions.\n",
"\n",
"3. **Nearby Attractions:** The assistant can provide information about attractions near the user's current location when prompted.\n",
"\n",
"4. **Audio Responses:** The assistant responds with both text and spoken audio, enhancing the interaction experience.\n",
"\n",
"5. **Knowledge Base Refresh:** Users can refresh the knowledge base to reload the latest information from the PDFs in the directory.\n",
"\n",
"6. **Conversation Management:** Users can clear the conversation and start anew at any time.\n",
"\n",
"These features aim to provide a comprehensive and interactive experience for users seeking information about travel and tourism.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt appears I have not been able to locate the specific `load_knowledge_base` function or its implementation details. However, I've gathered some context about the functionality of a knowledge base refresh feature in the repository. This feature allows users to reload the latest information from PDFs in a directory, which may be related to the functionality of loading a knowledge base.\n",
"\n",
"Since I'm unable to find the exact function you're asking about, it's likely that `load_knowledge_base` is either not explicitly defined, named differently, or implied within a broader functionality related to the knowledge base refresh feature.\n",
"\n",
"If you have any specific files or sections of the codebase in mind where this function may be implemented, please provide that context, and I can conduct a more targeted search. Otherwise, based on the available information, I can summarize the knowledge base refresh functionality as a feature that allows the assistant to update its information dynamically from a set of PDF documents. \n",
"\n",
"Final Answer: I was unable to find the implementation of the `load_knowledge_base` function in the repository. However, I found information regarding a feature that allows the knowledge base to be refreshed, which reloads the latest information from PDFs in a directory. If you have more context or specific files in mind, please let me know for a more focused search.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mTo provide an explanation, I need to know what specific code or concept I previously explained. However, since I don't have that context, I will need to look for any recent explanations in the repository. I'll perform a search to identify any recent discussions or explanations that might relate to the current question.\n",
"\n",
"Action: repo_context_search\n",
"Action Input: \"explain\" # I will search for explanations in the repository\n",
"\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI'm sorry, but I don't know what you're referring to with \"I will search for explanations in the repository.\" Could you please provide more context or clarify your question?\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mI need to clarify the user's request to provide a meaningful explanation. Since the initial question does not specify which code or concept to explain, I should ask the user for more details about what they would like me to explain. \n",
"\n",
"Final Answer: Could you please specify which code or concept you would like me to explain?\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI need to acknowledge the user's name. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI need to acknowledge the user's name. However, I cannot perform any actions based on the provided statement since it's not a query about the codebase. \n",
"\n",
"Final Answer: Nice to meet you, Ed! How can I assist you today?\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Stopping agent prematurely due to triggering stop condition\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32;1m\u001b[1;3mI don't have any information about your name or identity. \n",
"Action: None\u001b[0m\n",
"Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n",
"Thought:\u001b[32;1m\u001b[1;3m\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mTo explain the `read_pdf` function and its implementation line by line, I first need to locate this specific function within the codebase. I will search for `read_pdf` in the repository to find its definition and details.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: read_pdf \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mThe `read_pdf` function is designed to read a PDF file and extract its text content. It uses the `PdfReader` from the `pypdf` library to iterate through each page of the PDF and concatenate the extracted text into a single string. If you have a specific PDF file you want to read, please provide the file path, and I can guide you further.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mI have identified the purpose of the `read_pdf` function and its use of the `PdfReader` from the `pypdf` library to extract text from a PDF file. However, to provide a line-by-line explanation, I need to retrieve the actual code for the `read_pdf` function from the repository.\n",
"\n",
"Action: get_file \n",
"Action Input: read_pdf (I will also search for any specific files that might contain this function if there are multiple files with similar names.) \u001b[0m['README.md', 'requirements.txt', 'style.css', 'tourist-assistant.py', 'travel.jpg']\n",
"\n",
"Observation: \u001b[33;1m\u001b[1;3mNo file named 'read_pdf (I will also search for any specific files that might contain this function if there are multiple files with similar names.)' found in the repository.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems I need to refine my search for the specific file that contains the `read_pdf` function. I will look for files that might contain this function by searching for relevant keywords or checking common file names used for PDF handling.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"def read_pdf\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mThe `read_pdf` function is designed to read a PDF file and extract its text content. Here is the function definition:\n",
"\n",
"```python\n",
"def read_pdf(file_path):\n",
" \"\"\"Read a PDF file and extract text content.\"\"\"\n",
" pdf_reader = PdfReader(file_path)\n",
" text = \"\"\n",
" for page in pdf_reader.pages:\n",
" text += page.extract_text() or \"\"\n",
" return text\n",
"```\n",
"\n",
"This function takes a file path as an argument, uses a PDF reader to open the file, and then iterates through each page to extract and concatenate the text content. The final result is a string containing all the text from the PDF.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mI now have the complete implementation of the `read_pdf` function and can explain its functionality line by line.\n",
"\n",
"Final Answer: Here is a line-by-line explanation of the `read_pdf` function:\n",
"\n",
"```python\n",
"def read_pdf(file_path):\n",
"```\n",
"- This line defines a function named `read_pdf` that accepts one parameter, `file_path`, which is expected to be the path to the PDF file that needs to be read.\n",
"\n",
"```python\n",
" \"\"\"Read a PDF file and extract text content.\"\"\"\n",
"```\n",
"- This is a docstring that describes the purpose of the function. It indicates that the function reads a PDF file and extracts its text content.\n",
"\n",
"```python\n",
" pdf_reader = PdfReader(file_path)\n",
"```\n",
"- Here, an instance of `PdfReader` is created by passing `file_path` to it. `PdfReader` is a class from the `pypdf` library that allows for reading PDF files. The `pdf_reader` object will be used to access the pages of the PDF.\n",
"\n",
"```python\n",
" text = \"\"\n",
"```\n",
"- This line initializes an empty string variable named `text`. This variable will be used to accumulate the text extracted from each page of the PDF.\n",
"\n",
"```python\n",
" for page in pdf_reader.pages:\n",
"```\n",
"- This line begins a `for` loop that iterates over each page in the `pdf_reader.pages` collection. `pdf_reader.pages` is a list of all the pages in the PDF document.\n",
"\n",
"```python\n",
" text += page.extract_text() or \"\"\n",
"```\n",
"- Within the loop, this line extracts text from the current `page` using the `extract_text()` method. If the extracted text is `None`, the `or \"\"` ensures that an empty string is concatenated instead. This prevents any `NoneType` errors and ensures that the `text` variable remains a string.\n",
"\n",
"```python\n",
" return text\n",
"```\n",
"- Finally, the function returns the accumulated `text` string, which contains all the text extracted from the PDF file.\n",
"\n",
"In summary, the `read_pdf` function reads a specified PDF file, extracts text from each page, and returns the combined text as a single string.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI need to search the repository for the `search_attractions` function to understand its implementation and then explain each line of the code. \n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"search_attractions\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems I couldn't locate the `search_attractions` function directly. I will try to search for it again with a more general query to see if I can find any relevant information about it. \n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"def search_attractions\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI'm sorry, but I don't know the answer to that.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt appears that I'm unable to find the `search_attractions` function through my current searches. To provide a detailed explanation, I will try to fetch specific files that may contain the function definition. \n",
"\n",
"Action: get_file \n",
"Action Input: \"search_attractions.py\" # Assuming this file may contain the function based on common naming conventions. \u001b[0m['README.md', 'requirements.txt', 'style.css', 'tourist-assistant.py', 'travel.jpg']\n",
"\n",
"Observation: \u001b[33;1m\u001b[1;3mNo file named 'search_attractions.py\" # Assuming this file may contain the function based on common naming conventions.' found in the repository.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that I wasn't able to locate the `search_attractions` function or any relevant file directly. I will broaden my search to look for any files related to attractions or search functionality that might contain the implementation of the `search_attractions` function.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"attractions\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI'm sorry, but I don't know the answer to your question about attractions.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that the searches have not yielded any useful results regarding the `search_attractions` function or related files. The repository may not contain explicit references or the function may be named differently. I will now attempt to perform a broader search for any functions or classes that may relate to attractions or searching functionalities, which could help in understanding the context of `search_attractions`.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"search\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems I'm unable to find the `search_attractions` function or any related information in the repository through various search attempts. This may indicate that the function is named differently or that my searches are not yielding the correct results. Given this situation, I will now check the repository's structure for any files that might have relevant information regarding attractions or search functionalities.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: \"list files\" \u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt appears that I have faced several unsuccessful attempts to locate the `search_attractions` function or relevant files within the repository. Since I can't identify the function through direct searches or by checking specific files, I may need to approach this differently. \n",
"\n",
"Since the repository structure and its contents are not accessible to me, I would typically rely on a list of files or a specific directory structure that might contain the function I am looking for. However, given that I am unable to retrieve such information, I am currently at an impasse.\n",
"\n",
"Thought: I will summarize my findings and acknowledge that I couldn't find the `search_attractions` function or related files in the repository.\n",
"Final Answer: I was unable to locate the `search_attractions` function or its implementation details in the repository. As a result, I can't provide an explanation of what it does or analyze each line of code.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new None chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI need to locate the `search_attractions` function within the `tourist-assistant` file to understand its implementation and explain each line of code. I'll start by searching for the specific function in the relevant file.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: search_attractions function in tourist-assistant \n",
"\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mI need to fetch the content of the `tourist-assistant` file to find the `search_attractions` function directly and understand its implementation. \n",
"\n",
"Action: get_file \n",
"Action Input: tourist-assistant \n",
"\u001b[0m['README.md', 'requirements.txt', 'style.css', 'tourist-assistant.py', 'travel.jpg']\n",
"\n",
"Observation: \u001b[33;1m\u001b[1;3mNo file named 'tourist-assistant \n",
"' found in the repository.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that there is no file named 'tourist-assistant' in the repository. I will search for any file that might contain the keyword 'search_attractions' to locate its implementation.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: search_attractions \n",
"\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt appears that I am unable to find any relevant information regarding the `search_attractions` function or the `tourist-assistant` file. This could be due to a variety of reasons, such as the file being named differently or the function not existing in the repository. \n",
"\n",
"To proceed, I will perform a broader search to see if there are any related files or functions that could provide context or lead me closer to the information about `search_attractions`.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: attractions \n",
"\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI don't know.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that my attempts to locate the `search_attractions` function and the `tourist-assistant` file have not yielded any results. This indicates that the function or file may not exist in the repository, or they may be named differently. \n",
"\n",
"To gain more context, I should consider searching for the general term \"tourist\" to find relevant files that could contain related functionality or similar terms.\n",
"\n",
"Action: repo_context_search \n",
"Action Input: tourist \n",
"\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mI'm here to help you with information about tourist destinations. What specific questions do you have about a city, landmark, or attraction?\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3mIt seems that I am unable to locate any information regarding the `search_attractions` function or the `tourist-assistant` file within the repository. The responses to my queries indicate that there may not be a direct match for those terms. \n",
"\n",
"I will now summarize my findings:\n",
"\n",
"1. I initially searched for the `search_attractions` function but could not find it.\n",
"2. I attempted to access the `tourist-assistant` file but was informed that it does not exist.\n",
"3. Subsequent searches for related terms like \"attractions\" and \"tourist\" also yielded no relevant results.\n",
"\n",
"Given this context, it is likely that the `search_attractions` function either does not exist in the repository or is located in a differently named file. \n",
"\n",
"Final Answer: I was unable to find the `search_attractions` function or any file named `tourist-assistant` in the repository. Therefore, I cannot provide an explanation of the function or its code.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\hp\\projects\\gen-ai\\llm_engineering\\.venv\\Lib\\site-packages\\langchain\\chains\\base.py:487: UserWarning: 'ConversationBufferMemory' got multiple output keys: dict_keys(['output', 'messages']). The default 'output' key is being used. If this is not desired, please manually set 'output_key'.\n",
" self.memory.save_context(inputs, outputs)\n"
]
}
],
"source": [ "source": [
"interface = gr.ChatInterface(G.run, type=\"messages\")\n", "interface = gr.ChatInterface(G.run, type=\"messages\")\n",
"interface.launch()" "interface.launch()"
] ]
},
{
"cell_type": "markdown",
"id": "c0cf22c8",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b81ef168",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'..\\\\day 4 no_langchain'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"os.path.res(\"../day 4 no_langchain\")"
]
} }
], ],
"metadata": { "metadata": {