mb-rag 1.1.21__tar.gz → 1.1.23__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mb-rag might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mb_rag
3
- Version: 1.1.21
3
+ Version: 1.1.23
4
4
  Summary: RAG function file
5
5
  Author: ['Malav Bateriwala']
6
6
  Requires-Python: >=3.8
@@ -204,12 +204,13 @@ class ModelFactory:
204
204
 
205
205
  @classmethod
206
206
  def create_hugging_face(cls, model_name: str = "Qwen/Qwen2.5-VL-7B-Instruct",model_function: str = "image-text-to-text",
207
- **kwargs) -> Any:
207
+ device='cpu',**kwargs) -> Any:
208
208
  """
209
209
  Create and load hugging face model.
210
210
  Args:
211
211
  model_name (str): Name of the model
212
- model_function (str): model function
212
+ model_function (str): model function. Default is image-text-to-text.
213
+ device (str): Device to use. Default is cpu
213
214
  **kwargs: Additional arguments
214
215
  Returns:
215
216
  ChatHuggingFace: Chatbot model
@@ -222,30 +223,38 @@ class ModelFactory:
222
223
  raise ImportError("Torch package not found. Please install it using: pip install torch")
223
224
 
224
225
  from langchain_huggingface import HuggingFacePipeline
225
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
226
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, AutoModelForImageTextToText
226
227
  import torch
227
228
 
228
- device = "cuda" if torch.cuda.is_available() else "cpu"
229
+ device = torch.device(device) if torch.cuda.is_available() else torch.device("cpu")
229
230
 
230
231
  temperature = kwargs.pop("temperature", 0.7)
231
232
  max_length = kwargs.pop("max_length", 1024)
232
233
 
233
- tokenizer = AutoTokenizer.from_pretrained(model_name)
234
- model = AutoModelForCausalLM.from_pretrained(
235
- model_name,
236
- torch_dtype=torch.float16 if device == "cuda" else torch.float32,
237
- device_map=device,
238
- **kwargs
239
- )
234
+ tokenizer = AutoTokenizer.from_pretrained(model_name,trust_remote_code=True)
235
+ if model_function == "image-text-to-text":
236
+ model = AutoModelForImageTextToText.from_pretrained(
237
+ model_name,
238
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
239
+ device_map=device,
240
+ trust_remote_code=True,
241
+ **kwargs
242
+ )
243
+ else:
244
+ model = AutoModelForCausalLM.from_pretrained(
245
+ model_name,
246
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
247
+ device_map=device,
248
+ trust_remote_code=True,
249
+ **kwargs)
240
250
 
241
251
  # Create pipeline
242
252
  pipe = pipeline(
243
- "text-generation",
253
+ model_function,
244
254
  model=model,
245
255
  tokenizer=tokenizer,
246
256
  max_length=max_length,
247
- temperature=temperature,
248
- device=device
257
+ temperature=temperature
249
258
  )
250
259
 
251
260
  # Create and return LangChain HuggingFacePipeline
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 1
3
- PATCH_VERSION = 21
3
+ PATCH_VERSION = 23
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mb_rag
3
- Version: 1.1.21
3
+ Version: 1.1.23
4
4
  Summary: RAG function file
5
5
  Author: ['Malav Bateriwala']
6
6
  Requires-Python: >=3.8
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes