lugiiing commited on
Commit
1d951f3
โ€ข
1 Parent(s): 6e77103

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -25,21 +25,24 @@ st.markdown('###### ์งˆ๋ฌธ, ์š”์•ฝ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ถ€ํƒ์„ ํ•ด ๋ณด์„ธ์š”! ๊ต๊ณผ
25
 
26
 
27
  api_key = st.text_input(label='OpenAI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”', type='password')
28
- OpenAI.api_key = api_key
29
 
30
 
31
  if api_key:
32
  # OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ํ•จ์ˆ˜๋กœ ์ •์˜
33
- def initialize_openai_processing():
34
-
 
 
 
35
  loader = DirectoryLoader('./khistory_data', glob="*.txt", loader_cls=TextLoader)
36
  documents = loader.load()
37
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=100)
38
  texts = text_splitter.split_documents(documents)
39
 
40
  persist_directory = 'db'
41
- embedding = OpenAIEmbeddings()
42
- #embedding = OpenAIEmbeddings(api_key=api_key) # API ํ‚ค๋ฅผ ์ƒ์„ฑ์ž์— ์ „๋‹ฌ
43
  vectordb = Chroma.from_documents(
44
  documents=texts,
45
  embedding=embedding,
@@ -54,7 +57,8 @@ if api_key:
54
  retriever = vectordb.as_retriever(search_kwargs={"k": 3})
55
 
56
  qa_chain = RetrievalQA.from_chain_type(
57
- llm=OpenAI(),
 
58
  chain_type="stuff",
59
  retriever=retriever,
60
  return_source_documents=True)
@@ -62,7 +66,7 @@ if api_key:
62
  return embedding, vectordb, qa_chain
63
 
64
  # ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ์ดˆ๊ธฐํ™” ๊ณผ์ • ์ˆ˜ํ–‰
65
- embedding, vectordb, qa_chain = initialize_openai_processing()
66
 
67
 
68
  # ํ…์ŠคํŠธ ์ž…๋ ฅ
 
25
 
26
 
27
  api_key = st.text_input(label='OpenAI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”', type='password')
28
+
29
 
30
 
31
  if api_key:
32
  # OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ํ•จ์ˆ˜๋กœ ์ •์˜
33
+ def initialize_openai_processing(api_key):
34
+ #client = OpenAI()
35
+ #OpenAI.api_key = api_key
36
+
37
+
38
  loader = DirectoryLoader('./khistory_data', glob="*.txt", loader_cls=TextLoader)
39
  documents = loader.load()
40
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=100)
41
  texts = text_splitter.split_documents(documents)
42
 
43
  persist_directory = 'db'
44
+ #embedding = OpenAIEmbeddings()
45
+ embedding = OpenAIEmbeddings(api_key=api_key) # API ํ‚ค๋ฅผ ์ƒ์„ฑ์ž์— ์ „๋‹ฌ
46
  vectordb = Chroma.from_documents(
47
  documents=texts,
48
  embedding=embedding,
 
57
  retriever = vectordb.as_retriever(search_kwargs={"k": 3})
58
 
59
  qa_chain = RetrievalQA.from_chain_type(
60
+ #llm=OpenAI(),
61
+ llm=OpenAI(api_key=api_key),
62
  chain_type="stuff",
63
  retriever=retriever,
64
  return_source_documents=True)
 
66
  return embedding, vectordb, qa_chain
67
 
68
  # ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ์ดˆ๊ธฐํ™” ๊ณผ์ • ์ˆ˜ํ–‰
69
+ embedding, vectordb, qa_chain = initialize_openai_processing(api_key)
70
 
71
 
72
  # ํ…์ŠคํŠธ ์ž…๋ ฅ