shakeel143 commited on
Commit
1df4529
·
verified ·
1 Parent(s): 5b34c8d

Update model_service.py

Browse files
Files changed (1) hide show
  1. model_service.py +29 -1
model_service.py CHANGED
@@ -70,7 +70,35 @@ class ModelService:
70
  except Exception as e:
71
  logger.error(f"Error loading model: {str(e)}")
72
  raise HTTPException(status_code=500, detail=f"Failed to load model: {str(e)}")
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
  def configure_chain(self, temperature: float):
 
70
  except Exception as e:
71
  logger.error(f"Error loading model: {str(e)}")
72
  raise HTTPException(status_code=500, detail=f"Failed to load model: {str(e)}")
73
+
74
+ def chat_with_model(self, model_name: str, question: str):
75
+ """Chat with the specified model."""
76
+ try:
77
+ # Check if the model is loaded
78
+ if model_name not in self.loaded_models:
79
+ raise HTTPException(status_code=404, detail=f"Model '{model_name}' is not loaded.")
80
+
81
+ # Retrieve the model's vector store and QA chain
82
+ model_data = self.loaded_models[model_name]
83
+ vector_store = model_data["vector_store"]
84
+ chain = model_data["chain"]
85
+
86
+ # Perform a similarity search to find relevant documents
87
+ docs = vector_store.similarity_search(question)
88
+
89
+ # Generate a response using the QA chain
90
+ response = chain.run(input_documents=docs, question=question)
91
+
92
+ return {
93
+ "status": "success",
94
+ "response": response
95
+ }
96
+ except HTTPException:
97
+ raise
98
+ except Exception as e:
99
+ logger.error(f"Error chatting with model: {str(e)}")
100
+ raise HTTPException(status_code=500, detail=f"Failed to chat with model: {str(e)}")
101
+
102
 
103
 
104
  def configure_chain(self, temperature: float):