0504ankitsharma commited on
Commit
1939861
·
verified ·
1 Parent(s): 3144702

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +7 -7
app/main.py CHANGED
@@ -12,7 +12,7 @@ from fastapi.middleware.cors import CORSMiddleware
12
  from fastapi import FastAPI
13
  from pydantic import BaseModel
14
  from langchain_community.embeddings import HuggingFaceBgeEmbeddings
15
- import nltk # Importing NLTK
16
  import time
17
 
18
  # Set writable paths for cache and data
@@ -84,7 +84,7 @@ class Query(BaseModel):
84
 
85
  prompt = ChatPromptTemplate.from_template(
86
  """
87
- You are a helpful assistant designed specifically for the Thapar Institute of Engineering and Technology (TIET), a renowned technical college. Your task is to answer all queries related to TIET in concised manner. Every response you provide should be relevant to the context of TIET. If a question falls outside of this context, please decline by stating, 'Sorry, I cannot help with that.' If you do not know the answer to a question, do not attempt to fabricate a response; instead, politely decline.
88
  but avoid sounding boastful or exaggerating. Stay focused on the context provided.
89
  If the query is not related to TIET or falls outside the context of education, respond with:
90
  "Sorry, I cannot help with that. I'm specifically designed to answer questions about the Thapar Institute of Engineering and Technology.
@@ -133,7 +133,7 @@ def get_embeddings():
133
  model_norm = HuggingFaceBgeEmbeddings(model_name=model_name, encode_kwargs=encode_kwargs)
134
  return model_norm
135
 
136
- @app.post("/chat") # Changed from /anthropic to /chat
137
  def read_item(query: Query):
138
  try:
139
  embeddings = get_embeddings()
@@ -157,14 +157,14 @@ def read_item(query: Query):
157
  # For debugging, print the cleaned response
158
  print("Cleaned response:", repr(cleaned_response))
159
 
160
- return cleaned_response
161
  else:
162
- return "No Query Found"
163
 
164
  @app.get("/setup")
165
  def setup():
166
  return vector_embedding()
167
 
168
- if _name_ == "_main_":
169
  import uvicorn
170
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
12
  from fastapi import FastAPI
13
  from pydantic import BaseModel
14
  from langchain_community.embeddings import HuggingFaceBgeEmbeddings
15
+ import nltk
16
  import time
17
 
18
  # Set writable paths for cache and data
 
84
 
85
  prompt = ChatPromptTemplate.from_template(
86
  """
87
+ You are a helpful assistant designed specifically for the Thapar Institute of Engineering and Technology (TIET), a renowned technical college. Your task is to answer all queries related to TIET in a concise manner. Every response you provide should be relevant to the context of TIET. If a question falls outside of this context, please decline by stating, 'Sorry, I cannot help with that.' If you do not know the answer to a question, do not attempt to fabricate a response; instead, politely decline.
88
  but avoid sounding boastful or exaggerating. Stay focused on the context provided.
89
  If the query is not related to TIET or falls outside the context of education, respond with:
90
  "Sorry, I cannot help with that. I'm specifically designed to answer questions about the Thapar Institute of Engineering and Technology.
 
133
  model_norm = HuggingFaceBgeEmbeddings(model_name=model_name, encode_kwargs=encode_kwargs)
134
  return model_norm
135
 
136
+ @app.post("/chat")
137
  def read_item(query: Query):
138
  try:
139
  embeddings = get_embeddings()
 
157
  # For debugging, print the cleaned response
158
  print("Cleaned response:", repr(cleaned_response))
159
 
160
+ return {"response": cleaned_response}
161
  else:
162
+ return {"response": "No Query Found"}
163
 
164
  @app.get("/setup")
165
  def setup():
166
  return vector_embedding()
167
 
168
+ if __name__ == "__main__":
169
  import uvicorn
170
+ uvicorn.run(app, host="0.0.0.0", port=8000)