Darayut commited on
Commit
637e09e
·
verified ·
1 Parent(s): 2f923a7

Update src/simple_rag.py

Browse files
Files changed (1) hide show
  1. src/simple_rag.py +6 -4
src/simple_rag.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import os
2
  import logging
3
  import torch
@@ -7,7 +9,6 @@ from langchain.schema import Document
7
  from langchain.vectorstores.chroma import Chroma
8
  from langchain.embeddings import HuggingFaceEmbeddings
9
  from langchain.document_loaders import PyPDFDirectoryLoader
10
- from transformers import BitsAndBytesConfig
11
 
12
  logging.basicConfig(level=logging.INFO)
13
 
@@ -34,8 +35,8 @@ if use_gpu:
34
  else:
35
  model = AutoModelForCausalLM.from_pretrained(
36
  model_id,
37
- load_in_8bit=True,
38
- device_map={"": "cpu"}, # Force CPU
39
  )
40
 
41
 
@@ -53,7 +54,8 @@ embedding_model = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-bas
53
  PROMPT_TEMPLATE = """
54
  You are a helpful assistant.
55
  Answer the question based ONLY on the context below.
56
-
 
57
  Use clear, concise sentences, no more than 50 words. Do not mention the existence of context.
58
 
59
  Context:
 
1
+ # Modified RAG Pipeline for General Document Q&A (Khmer & English)
2
+
3
  import os
4
  import logging
5
  import torch
 
9
  from langchain.vectorstores.chroma import Chroma
10
  from langchain.embeddings import HuggingFaceEmbeddings
11
  from langchain.document_loaders import PyPDFDirectoryLoader
 
12
 
13
  logging.basicConfig(level=logging.INFO)
14
 
 
35
  else:
36
  model = AutoModelForCausalLM.from_pretrained(
37
  model_id,
38
+ device_map="cpu", # Force CPU
39
+ torch_dtype=torch.float32,
40
  )
41
 
42
 
 
54
  PROMPT_TEMPLATE = """
55
  You are a helpful assistant.
56
  Answer the question based ONLY on the context below.
57
+ If the user asks in Khmer, respond in Khmer.
58
+ If the user asks in English, respond in English.
59
  Use clear, concise sentences, no more than 50 words. Do not mention the existence of context.
60
 
61
  Context: