aguyader commited on
Commit
6a4a996
·
verified ·
1 Parent(s): ca31854

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +13 -16
app2.py CHANGED
@@ -1,18 +1,15 @@
1
 
2
  import openai
3
  import gradio as gr
 
4
 
 
5
 
 
 
 
6
 
7
- #import docx # For reading Word documents
8
-
9
- #openai.api_key = "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"
10
-
11
- #messages = [
12
- # {"role": "system", "content": "You are a chatbot that is very happy and kind. You will search the website https://www.patch-and-sparks.com/en/"},
13
- #]
14
 
15
- """
16
  def read_word_document(file_path):
17
  #Read and return all paragraphs from the Word document.
18
  doc = docx.Document(file_path)
@@ -41,16 +38,16 @@ def chatbot(input):
41
  doc_content = read_word_document("./Info_1.docx") # Specify the path to your Word document
42
  doc_reply = search_in_doc(doc_content, input)
43
 
44
- ## Get the chatbot response from OpenAI
45
- #chat = openai.ChatCompletion.create(
46
- # model="gpt-4", messages=messages
47
- #)
48
- #ai_reply = chat.choices[0].message.content
49
- #messages.append({"role": "assistant", "content": ai_reply})
50
 
51
  # Combine the response from OpenAI and the document search
52
- #combined_reply = f"{ai_reply}\n\n{doc_reply}"
53
- combined_reply = f"{doc_reply}"
54
  return combined_reply
55
 
56
 
 
1
 
2
  import openai
3
  import gradio as gr
4
+ import docx # For reading Word documents
5
 
6
+ openai.api_key = "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"
7
 
8
+ messages = [
9
+ {"role": "system", "content": "You are a chatbot that is very happy and kind. You will search the website https://www.patch-and-sparks.com/en/"},
10
+ ]
11
 
 
 
 
 
 
 
 
12
 
 
13
  def read_word_document(file_path):
14
  #Read and return all paragraphs from the Word document.
15
  doc = docx.Document(file_path)
 
38
  doc_content = read_word_document("./Info_1.docx") # Specify the path to your Word document
39
  doc_reply = search_in_doc(doc_content, input)
40
 
41
+ # Get the chatbot response from OpenAI
42
+ chat = openai.ChatCompletion.create(
43
+ model="gpt-3.5-turbo", messages=messages
44
+ )
45
+ ai_reply = chat.choices[0].message.content
46
+ messages.append({"role": "assistant", "content": ai_reply})
47
 
48
  # Combine the response from OpenAI and the document search
49
+ combined_reply = f"{ai_reply}\n\n{doc_reply}"
50
+ #combined_reply = f"{doc_reply}"
51
  return combined_reply
52
 
53