OnurKerimoglu commited on
Commit
4305c1f
·
1 Parent(s): bc99a02

src.rag: fixed the interface for using HF-inference models; default llm model: zephyr-7b-beta

Browse files
Files changed (1) hide show
  1. src/rag.py +22 -19
src/rag.py CHANGED
@@ -23,8 +23,8 @@ class RAG():
23
 
24
  # Constants
25
  # self.use_model = 'gpt-4o-mini'
26
- # self.use_model = 'zephyr-7b-alpha'
27
- self.use_model = 'Mistral-Nemo-Base-2407'
28
 
29
  # self.use_vectordb = 'chroma'
30
  self.use_vectordb = 'faiss'
@@ -108,10 +108,10 @@ class RAG():
108
  """
109
  Instantiates a language model based on the specified model type.
110
 
111
- This function supports two models:
112
  - 'gpt-4o-mini' through the ChatOpenAI interface
113
- - 'Mistral-Nemo-Base-2407' through the HuggingFaceEndpoint, with provider: novita
114
- ('zephyr-7b-alpha' through the HuggingFaceEndpoint is being tested, but not working at the moment)
115
  The model is determined by the `self.use_model` attribute.
116
  Returns an instance of the selected language model.
117
 
@@ -124,19 +124,21 @@ class RAG():
124
  llm = ChatOpenAI(
125
  model_name="gpt-4o-mini",
126
  temperature=0)
127
- # elif self.use_model == 'zephyr-7b-alpha':
128
- # print(f'As llm, using HF-Endpint: {self.use_model}')
129
- # llm = HuggingFaceEndpoint(
130
- # repo_id=f"HuggingFaceH4/{self.use_model}",
131
- # temperature=0.1,
132
- # max_new_tokens=512,
133
- # do_sample=False
134
- # )
 
 
135
  elif self.use_model == 'Mistral-Nemo-Base-2407':
136
  provider = "novita"
137
  print(f'As llm, using HF-Endpint: {self.use_model} through provider: {provider}')
138
  llm = HuggingFaceEndpoint(
139
- repo_id="mistralai/Mistral-Nemo-Base-2407",
140
  provider=provider,
141
  temperature=0.1,
142
  max_new_tokens=512,
@@ -229,13 +231,14 @@ class RAG():
229
 
230
  if __name__ == "__main__":
231
  rag = RAG(
232
- urls = [
233
- "https://en.wikipedia.org/wiki/Artificial_intelligence",
234
- "https://en.wikipedia.org/wiki/Machine_learning"
235
- ]
236
  # pdfs = ["/home/onur/WORK/DS/repos/chat_with_docs/docs/the-big-book-of-mlops-v10-072023 - Databricks.pdf"]
 
237
  )
238
- response = rag.ask_QAbot("What is Machine Learning?")
239
  print(f"Question: {response['question']}")
240
  print(f"Answer: {response['answer']}")
241
  print("Sources:")
 
23
 
24
  # Constants
25
  # self.use_model = 'gpt-4o-mini'
26
+ self.use_model = 'zephyr-7b-beta'
27
+ # self.use_model = 'Mistral-Nemo-Base-2407'
28
 
29
  # self.use_vectordb = 'chroma'
30
  self.use_vectordb = 'faiss'
 
108
  """
109
  Instantiates a language model based on the specified model type.
110
 
111
+ This function supports the following models:
112
  - 'gpt-4o-mini' through the ChatOpenAI interface
113
+ - 'zephyr-7b-beta' through the HuggingFaceEndpoint with provider: hf-inference
114
+ - 'Mistral-Nemo-Base-2407' through the HuggingFaceEndpoint, with provider: novita (at testing stage)
115
  The model is determined by the `self.use_model` attribute.
116
  Returns an instance of the selected language model.
117
 
 
124
  llm = ChatOpenAI(
125
  model_name="gpt-4o-mini",
126
  temperature=0)
127
+ elif self.use_model == 'zephyr-7b-beta':
128
+ provider = "hf-inference"
129
+ print(f'As llm, using HF-Endpint: {self.use_model} through provider: {provider}')
130
+ llm = HuggingFaceEndpoint(
131
+ repo_id=f"HuggingFaceH4/{self.use_model}",
132
+ provider=provider,
133
+ temperature=0.1,
134
+ max_new_tokens=512,
135
+ do_sample=False
136
+ )
137
  elif self.use_model == 'Mistral-Nemo-Base-2407':
138
  provider = "novita"
139
  print(f'As llm, using HF-Endpint: {self.use_model} through provider: {provider}')
140
  llm = HuggingFaceEndpoint(
141
+ repo_id=f"mistralai/{self.use_model}",
142
  provider=provider,
143
  temperature=0.1,
144
  max_new_tokens=512,
 
231
 
232
  if __name__ == "__main__":
233
  rag = RAG(
234
+ # urls = [
235
+ # "https://en.wikipedia.org/wiki/Artificial_intelligence",
236
+ # "https://en.wikipedia.org/wiki/Machine_learning"
237
+ #]
238
  # pdfs = ["/home/onur/WORK/DS/repos/chat_with_docs/docs/the-big-book-of-mlops-v10-072023 - Databricks.pdf"]
239
+ pdfs =['/home/onur/Desktop/job_app/Resume_Onur_Kerimoglu.pdf']
240
  )
241
+ response = rag.ask_QAbot("What technical skills does Onur Kerimoglu possess?")
242
  print(f"Question: {response['question']}")
243
  print(f"Answer: {response['answer']}")
244
  print("Sources:")