import re from typing import Any, List from pydantic import Field from llama_index.core import Document, Settings, VectorStoreIndex from llama_index.core.embeddings import BaseEmbedding from llama_index.core.llms import ( CompletionResponse, CompletionResponseGen, CustomLLM, LLMMetadata, ) from llama_index.core.llms.callbacks import llm_completion_callback from llama_index.core.node_parser import SentenceSplitter faq_documents = [ Document( text=( "Question: How do I reset my password?\n" "Answer: Use the account recovery page to send a reset link to the " "verified email address on the account." ), metadata={"faq_id": "password-reset"}, ), Document( text=( "Question: What is the refund window?\n" "Answer: Customers can request a refund within 30 days of cancellation " "from the billing portal." ), metadata={"faq_id": "refund-window"}, ), Document( text=( "Question: How do I change my billing email?\n" "Answer: Open Billing, choose Payment details, and update the billing " "contact email before the next invoice." ), metadata={"faq_id": "billing-email"}, ), ]