Sveltekit app inspired by Mayo Oshin's gpt4-pdf-chatbot-langchain
Welcome to the ChatGPT Svelte Playground, a single-page app for chatting with your favorite philosopher! This documentation provides an overview of the app structure, its components, and how it interacts with external services.
The app consists of two main parts: the Svelte page (/src/routes/$page.svelte
) and the form action (/src/routes/$page/[...action].ts
). Let's break down each part:
The Svelte template renders the chat interface, including user and bot messages, a form for user input, and loading indicators.
The form action (/src/routes/$page/[...action].ts
) handles form submissions and API interactions. It utilizes external services for language embeddings and vector stores.
npm install
npm run dev
ingest-data
ScriptThe ingest-data
script is responsible for loading and processing documents to be used in the language model. Follow the steps below to run the script:
Before running the script, ensure you have Node.js and npm installed on your machine.
Navigate to the Project Directory:
Open a terminal and navigate to the root directory of your Svelte project where the package.json
file is located.
cd /path/to/your/svelte-project
Install Dependencies:
Ensure you have all the necessary dependencies by running:
npm install
Set Up Configuration:
Open the ingest-data.ts
file located in the scripts
directory. Verify that the filePath
variable is correctly set to the directory containing your documents.
const filePath = 'docs'; // Change to your directory path
Run the Script:
Execute the script by running:
ts-node scripts/ingest-data.ts
This command will ingest and process the documents, splitting them into chunks and creating embeddings for each document.
Verify Successful Ingestion:
Ensure that the script runs without errors, and check the console for logs indicating the successful completion of ingestion.
ingestion complete
ingest-data
script uses the DirectoryLoader
to load documents from the specified directory, and the RecursiveCharacterTextSplitter
to split the text into chunks.Now, your language model is ready to use the ingested data for improved performance and accuracy.