kookoobau commited on
Commit
8d768b7
1 Parent(s): 91a2093
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +6 -1
  3. myLLM.py +1 -0
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  .env
2
  _app.py
3
  models/ggml-gpt4all-l13b-snoozy.bin
 
 
1
  .env
2
  _app.py
3
  models/ggml-gpt4all-l13b-snoozy.bin
4
+ myLLM.py
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from langchain import PromptTemplate, LLMChain
2
  from langchain.llms import GPT4All
 
3
  from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
4
  import gradio as gr
5
  from huggingface_hub import hf_hub_download
@@ -16,16 +17,20 @@ template = """Question: {question}
16
  Answer: Let's think step by step."""
17
 
18
  prompt = PromptTemplate(template=template, input_variables=["question"])
 
 
 
19
  # Callbacks support token-wise streaming
20
  callbacks = [StreamingStdOutCallbackHandler()]
21
  # Verbose is required to pass to the callback manager
22
  llm = GPT4All(model=model, callbacks=callbacks, verbose=True)
23
 
24
- llm_chain = LLMChain(prompt=prompt, llm=llm)
25
 
26
  # Define the Gradio interface
27
  def chatbot_interface(input_text):
28
  response = llm_chain.run(input_text)
 
29
  return response
30
 
31
  # Define the Gradio app
 
1
  from langchain import PromptTemplate, LLMChain
2
  from langchain.llms import GPT4All
3
+ from langchain.memory import ConversationMemory
4
  from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
5
  import gradio as gr
6
  from huggingface_hub import hf_hub_download
 
17
  Answer: Let's think step by step."""
18
 
19
  prompt = PromptTemplate(template=template, input_variables=["question"])
20
+
21
+ # Create a memory module with a maximum capacity of 1000 items
22
+ memory = ConversationMemory(max_capacity=1000)
23
  # Callbacks support token-wise streaming
24
  callbacks = [StreamingStdOutCallbackHandler()]
25
  # Verbose is required to pass to the callback manager
26
  llm = GPT4All(model=model, callbacks=callbacks, verbose=True)
27
 
28
+ llm_chain = LLMChain(prompt=prompt, llm=llm, memory=memory)
29
 
30
  # Define the Gradio interface
31
  def chatbot_interface(input_text):
32
  response = llm_chain.run(input_text)
33
+ memory.store(llm_chain.last_input, llm_chain.last_output)
34
  return response
35
 
36
  # Define the Gradio app
myLLM.py CHANGED
@@ -16,3 +16,4 @@ class AutoModelLanguageModel(LanguageModel):
16
  output = self.model.generate(prompt, max_length=max_length, pad_token_id=self.tokenizer.pad_token_id)
17
  response = self.tokenizer.decode(output[0], skip_special_tokens=True)
18
  return response
 
 
16
  output = self.model.generate(prompt, max_length=max_length, pad_token_id=self.tokenizer.pad_token_id)
17
  response = self.tokenizer.decode(output[0], skip_special_tokens=True)
18
  return response
19
+