Skip to content

Instantly share code, notes, and snippets.

@FabienArcellier
Last active September 4, 2024 16:18
Show Gist options
  • Save FabienArcellier/05bc7c55773f36324259c12a90ff882a to your computer and use it in GitHub Desktop.
Save FabienArcellier/05bc7c55773f36324259c12a90ff882a to your computer and use it in GitHub Desktop.
from kb import index_knowledge_base, ask_knowledge_base
kb.index_knowledge_base('./datasets') # dossier avec des pdfs ou d'autres documents
kb.ask_knowledge_base('Quels sont les 3 techniques qui fonctionnent pour éliminer les moustiques d un marécage ?')
from typing import Optional
import os
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
os.environ["OPENAI_API_KEY"] = 'sk-xxxxxxxxx'
vector_store: Optional[VectorStoreIndex] = None
def index_knowledge_base(path: str):
global vector_store
documents = SimpleDirectoryReader(path).load_data()
vector_store = VectorStoreIndex.from_documents(documents)
def ask_knowledge_base(question: str) -> str:
query_str = question
query_engine = vector_store.as_query_engine()
response = query_engine.query(query_str)
return response.response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment