{user_name} commited on
Commit
442895c
โ€ข
1 Parent(s): b16918e
Files changed (2) hide show
  1. app.py +13 -11
  2. Module/rag.py โ†’ rag.py +8 -12
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
@@ -26,18 +28,18 @@ def respond(
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = ""
 
 
 
 
 
 
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ import rag
5
+
6
  """
7
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
8
  """
 
28
  messages.append({"role": "user", "content": message})
29
 
30
  response = ""
31
+ return rag.Response(message)
32
+ # for message in client.chat_completion(
33
+ # messages,
34
+ # max_tokens=max_tokens,
35
+ # stream=True,
36
+ # temperature=temperature,
37
+ # top_p=top_p,
38
+ # ):
39
+ # token = message.choices[0].delta.content
40
 
41
+ # response += token
42
+ # yield response
 
 
 
 
 
 
 
 
 
43
 
44
  """
45
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
Module/rag.py โ†’ rag.py RENAMED
@@ -34,16 +34,9 @@ model_huggingface = HuggingFaceEmbeddings(model_name = 'jhgan/ko-sroberta-multit
34
  db = Chroma.from_documents(sourceDocs, model_huggingface)
35
 
36
  ## ์งˆ์˜ํ•˜๊ธฐ
37
- question = '์‚ผ์„ฑ์ „์ž์˜ ์ฃผ์š” ์‚ฌ์—…์˜์—ญ์€?'
38
- docs3 = db.similarity_search_with_relevance_scores(question, k = 1) # 2๊ฐœ ํ•˜๋‹ˆ ๋„ˆ๋ฌด ๋Š๋ฆฐ๊ฑด๊ฐ€? ๋‹ต๋ณ€์ด ์•ˆ๋‚˜์˜ค๋Š”๋ฐ..?
39
-
40
- # ํŒŒ์ผ๋กœ ์ €์žฅํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
41
- # db_toFiles = Chroma.from_documents(docs, model_huggingface, persist_directory = './samsumg.db')
42
- # db_fromfile = Chroma(persist_directory = './samsumg.db',embedding_function=model_huggingface)
43
- # docs3 = db_fromfile.similarity_search_with_relevance_scores(question,k=3)
44
-
45
- joinDoc = ' '.join([doc[0].page_content for doc in docs3])
46
- print(joinDoc)
47
 
48
  ################
49
  # ์ฐพ์€ ๋ฌธ์„œ๋ฅผ ํ”„๋กฌํ”„ํŠธ์— ์ „๋‹ฌํ•˜์—ฌ LLM์œผ๋กœ ๋‹ต๋ณ€ ์ƒ์„ฑ
@@ -62,6 +55,9 @@ prompt = ChatPromptTemplate.from_messages([
62
  ("user", "{question}"),
63
  ])
64
 
65
- print('-'*50)
66
  chain = prompt | llm
67
- print(chain.invoke({"question": question, "document": joinDoc}))
 
 
 
 
34
  db = Chroma.from_documents(sourceDocs, model_huggingface)
35
 
36
  ## ์งˆ์˜ํ•˜๊ธฐ
37
+ def searchDocs(question, k=1):
38
+ results = db.similarity_search_with_relevance_scores(question, k = k)
39
+ return results
 
 
 
 
 
 
 
40
 
41
  ################
42
  # ์ฐพ์€ ๋ฌธ์„œ๋ฅผ ํ”„๋กฌํ”„ํŠธ์— ์ „๋‹ฌํ•˜์—ฌ LLM์œผ๋กœ ๋‹ต๋ณ€ ์ƒ์„ฑ
 
55
  ("user", "{question}"),
56
  ])
57
 
58
+ # print('-'*50)
59
  chain = prompt | llm
60
+ def Response(question):
61
+ searchedDocs = searchDocs(question)
62
+ mergedDoc = ' '.join(searchedDocs[0][0])
63
+ return chain.invoke({"question": question, "document": mergedDoc})