Last active
September 4, 2024 16:18
-
-
Save FabienArcellier/05bc7c55773f36324259c12a90ff882a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ?') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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