File size: 931 Bytes
6a20884
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import sys

import openai
from langchain_community.chains import ConversationalRetrievalChain, RetrievalQA
from langchain_community.chat_models import ChatOpenAI
from langchain_community.document_loaders import DirectoryLoader, TextLoader
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_community.indexes import VectorstoreIndexCreator
from langchain_community.indexes.vectorstore import VectorStoreIndexWrapper
from langchain_community.llms import OpenAI
from langchain_community.vectorstores import Chroma



os.environ["OPENAI_API_KEY"] = "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"

if len(sys.argv) > 1:
  query = sys.argv[1]

#loader = TextLoader("data/data.txt") # Use this line if you only need data.txt
loader = DirectoryLoader(".",glob="*.txt")
index = VectorstoreIndexCreator().from_loaders([loader])

llm=ChatOpenAI(model="gpt-3.5-turbo-16k")
print(index.query(query,llm))