GenAICoder commited on
Commit
2aaf3ce
·
verified ·
1 Parent(s): 479fdf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -15,14 +15,27 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
15
  #from transformers import pipeline
16
  # Load model directly
17
  #from transformers import AutoModelForCausalLM
18
- from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
19
-
 
 
20
 
21
 
22
 
23
  #access_token = os.getenv("HUGGINGFACE_API_KEY")
24
 
25
-
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  #st.set_page_config(page_title="Document Genie", layout="wide")
28
 
@@ -97,10 +110,10 @@ def get_conversational_chain(retriever):
97
  #llm = AutoModelForCausalLM.from_pretrained("google/gemma-1.1-2b-it")
98
  #llm = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-128k-instruct", trust_remote_code=True, token=access_token)
99
  #llm = pipeline("text-generation", model="google/gemma-1.1-2b-it")
100
- llm = HuggingFacePipeline.from_model_id(
101
- model_id="gpt2",
102
- task="text-generation",
103
- pipeline_kwargs={"max_new_tokens": 10})
104
 
105
  pt = ChatPromptTemplate.from_template(prompt_template)
106
  # Retrieve and generate using the relevant snippets of the blog.
 
15
  #from transformers import pipeline
16
  # Load model directly
17
  #from transformers import AutoModelForCausalLM
18
+ #from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
19
+ from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate
20
+ from llama_index.llms.huggingface import HuggingFaceInferenceAPI
21
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
22
 
23
 
24
 
25
  #access_token = os.getenv("HUGGINGFACE_API_KEY")
26
 
27
+ # Configure the Llama index settings
28
+ Settings.llm = HuggingFaceInferenceAPI(
29
+ model_name="meta-llama/Meta-Llama-3-8B-Instruct",
30
+ tokenizer_name="meta-llama/Meta-Llama-3-8B-Instruct",
31
+ context_window=3900,
32
+ token=os.getenv("HUGGINGFACE_API_KEY"),
33
+ # max_new_tokens=1000,
34
+ generate_kwargs={"temperature": 0.1},
35
+ )
36
+ Settings.embed_model = HuggingFaceEmbedding(
37
+ model_name="BAAI/bge-small-en-v1.5"
38
+ )
39
 
40
  #st.set_page_config(page_title="Document Genie", layout="wide")
41
 
 
110
  #llm = AutoModelForCausalLM.from_pretrained("google/gemma-1.1-2b-it")
111
  #llm = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-128k-instruct", trust_remote_code=True, token=access_token)
112
  #llm = pipeline("text-generation", model="google/gemma-1.1-2b-it")
113
+ #llm = HuggingFacePipeline.from_model_id(
114
+ #model_id="gpt2",
115
+ #task="text-generation",
116
+ #pipeline_kwargs={"max_new_tokens": 10})
117
 
118
  pt = ChatPromptTemplate.from_template(prompt_template)
119
  # Retrieve and generate using the relevant snippets of the blog.