{ "cells": [ { "cell_type": "code", "execution_count": 13, "id": "5be86be3-be9d-4707-ba0f-d4d82518bc2b", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "from dotenv import load_dotenv, find_dotenv\n", "_ = load_dotenv(find_dotenv()) # read local .env file" ] }, { "cell_type": "code", "execution_count": 14, "id": "3653c1eb-db1c-4546-9357-b86c12ff7347", "metadata": {}, "outputs": [], "source": [ "from langchain.chains import RetrievalQA\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.document_loaders import CSVLoader\n", "from langchain.vectorstores import DocArrayInMemorySearch\n", "from IPython.display import display, Markdown" ] }, { "cell_type": "code", "execution_count": 15, "id": "cb4b06e3-f3ba-4210-86e0-69cf1fbab9ff", "metadata": {}, "outputs": [], "source": [ "file = 'Data.csv'\n", "loader = CSVLoader(file_path=file)" ] }, { "cell_type": "code", "execution_count": 16, "id": "09c5e552-32a3-4aad-9a16-d45eb42a8197", "metadata": {}, "outputs": [], "source": [ "from langchain.indexes import VectorstoreIndexCreator" ] }, { "cell_type": "code", "execution_count": 17, "id": "eaee53eb-59f2-4c95-b68f-30d35c2268f7", "metadata": {}, "outputs": [], "source": [ "index = VectorstoreIndexCreator(\n", " vectorstore_cls=DocArrayInMemorySearch\n", ").from_loaders([loader])" ] }, { "cell_type": "code", "execution_count": 18, "id": "28358e5c-9fb0-475c-914d-e752d3f03293", "metadata": {}, "outputs": [], "source": [ "query =\"Please list all your shirts with sun protection \\\n", "in a table in markdown and summarize each one.\"" ] }, { "cell_type": "code", "execution_count": 19, "id": "4e417607-fb44-4841-b6b7-da2f72e31742", "metadata": {}, "outputs": [], "source": [ "response = index.query(query)" ] }, { "cell_type": "code", "execution_count": 21, "id": "091b6e7e-bd97-4beb-a812-fc1d34f1a369", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "loader" ] }, { "cell_type": "code", "execution_count": null, "id": "fd3139bd-7fae-4747-adf9-9eb93515a19c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }