Asiya057 commited on
Commit
8ba99e8
·
verified ·
1 Parent(s): ba9f995

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -2
main.py CHANGED
@@ -4,7 +4,8 @@ import os
4
  import re
5
  import time
6
  import logging
7
-
 
8
  from langchain.chat_models import ChatOpenAI, ChatAnthropic
9
  from langchain.memory import ConversationTokenBufferMemory
10
  from convo_qa_chain import ConvoRetrievalChain
@@ -19,7 +20,7 @@ from toolkit.utils import (
19
  load_pickle,
20
  check_device,
21
  )
22
-
23
 
24
  # Load the config file
25
  configs = Config("configparser.ini")
@@ -137,6 +138,28 @@ qa = ConvoRetrievalChain.from_llm(
137
  )
138
 
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  if __name__ == "__main__":
141
  while True:
142
  user_input = input("Human: ")
@@ -148,3 +171,4 @@ if __name__ == "__main__":
148
  print(f"AI:{resp['answer']}")
149
  print(f"Time used: {time.time() - start_time}")
150
  print("-" * 60)
 
 
4
  import re
5
  import time
6
  import logging
7
+ from fastapi import FastAPI
8
+ from pydantic import BaseModel
9
  from langchain.chat_models import ChatOpenAI, ChatAnthropic
10
  from langchain.memory import ConversationTokenBufferMemory
11
  from convo_qa_chain import ConvoRetrievalChain
 
20
  load_pickle,
21
  check_device,
22
  )
23
+ app =FastAPI()
24
 
25
  # Load the config file
26
  configs = Config("configparser.ini")
 
138
  )
139
 
140
 
141
+
142
+
143
+ class Question(BaseModel):
144
+ question: str
145
+
146
+ @app.get("/chat/")
147
+ def chat_with(str1: str):
148
+ resp = qa({"question": str1})
149
+ answer = resp.get('answer', '')
150
+ return {'message': answer}
151
+
152
+ '''
153
+ @app.get("/")
154
+
155
+ def chat_with(str1):
156
+ resp = qa({"question": str1})
157
+ return {'message':resp}
158
+ '''
159
+
160
+
161
+
162
+ '''
163
  if __name__ == "__main__":
164
  while True:
165
  user_input = input("Human: ")
 
171
  print(f"AI:{resp['answer']}")
172
  print(f"Time used: {time.time() - start_time}")
173
  print("-" * 60)
174
+ '''