Divyanshh commited on
Commit
1139efa
1 Parent(s): 65037fc

version 3 working

Browse files
Files changed (5) hide show
  1. Code.txt +0 -0
  2. Code/app.py +1 -44
  3. __pycache__/util.cpython-310.pyc +0 -0
  4. app.py +1 -1
  5. util.py +2 -9
Code.txt ADDED
The diff for this file is too large to render. See raw diff
 
Code/app.py CHANGED
@@ -1,44 +1 @@
1
- import random
2
-
3
- # Sample dataset and transition matrix
4
- dataset = [
5
- "Once upon a time",
6
- "there was a cat",
7
- "The cat loved to",
8
- "explore the forest",
9
- "One day, it found",
10
- "a hidden treasure",
11
- "The treasure was",
12
- "guarded by a dragon",
13
- ]
14
-
15
- transition_matrix = {
16
- "Once upon a time": {"there was a cat": 1.0},
17
- "there was a cat": {"The cat loved to": 1.0},
18
- "The cat loved to": {"explore the forest": 1.0},
19
- "explore the forest": {"One day, it found": 1.0},
20
- "One day, it found": {"a hidden treasure": 1.0},
21
- "a hidden treasure": {"The treasure was": 1.0},
22
- "The treasure was": {"guarded by a dragon": 1.0},
23
- "guarded by a dragon": {"The end": 1.0},
24
- }
25
-
26
- # Generate a story
27
- def generate_story(transition_matrix, initial_state, length=5):
28
- current_state = initial_state
29
- story = [current_state]
30
-
31
- for _ in range(length):
32
- next_state_options = transition_matrix.get(current_state, {})
33
- if not next_state_options:
34
- break
35
- next_state = random.choices(list(next_state_options.keys()), list(next_state_options.values()))[0]
36
- story.append(next_state)
37
- current_state = next_state
38
-
39
- return " ".join(story)
40
-
41
- # Generate a story starting from a specific state
42
- initial_state = "Once upon a time"
43
- generated_story = generate_story(transition_matrix, initial_state)
44
- print(generated_story)
 
1
+ print("Hello world!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
__pycache__/util.cpython-310.pyc ADDED
Binary file (2.57 kB). View file
 
app.py CHANGED
@@ -37,7 +37,6 @@ if btn and not flag:
37
  # for word in response.split():
38
  # yield word + " "
39
  # time.sleep(0.05)
40
- from util import generate_assistant_response
41
 
42
  st.title("Nile")
43
 
@@ -52,6 +51,7 @@ for message in st.session_state.messages:
52
 
53
  # Accept user input
54
  if prompt := st.chat_input("What's your question ?"):
 
55
  # Add user message to chat history
56
  st.session_state.messages.append({"role": "user", "content": prompt})
57
  # Display user message in chat message container
 
37
  # for word in response.split():
38
  # yield word + " "
39
  # time.sleep(0.05)
 
40
 
41
  st.title("Nile")
42
 
 
51
 
52
  # Accept user input
53
  if prompt := st.chat_input("What's your question ?"):
54
+ from util import generate_assistant_response
55
  # Add user message to chat history
56
  st.session_state.messages.append({"role": "user", "content": prompt})
57
  # Display user message in chat message container
util.py CHANGED
@@ -65,12 +65,6 @@ with open("Code.txt", "w", encoding='utf-8') as output:
65
  code = file.read()
66
  output.write(f"Filepath: {filepath}:\n\n")
67
  output.write(code + "\n\n")
68
- elif filename.endswith((".txt")):
69
- filepath = os.path.join(directory_path, filename)
70
- with open(filepath, "r", encoding="utf-8") as file:
71
- code = file.read()
72
- output.write(f"Documentation list:\n\n")
73
- output.write(code + "\n\n")
74
 
75
  from langchain.text_splitter import RecursiveCharacterTextSplitter
76
  from langchain_community.document_loaders import TextLoader
@@ -83,9 +77,8 @@ pages = loader.load_and_split()
83
 
84
  # Split data into chunks
85
  text_splitter = RecursiveCharacterTextSplitter(
86
- chunk_size = 4000,
87
  chunk_overlap = 20,
88
- length_function = len,
89
  add_start_index = True,
90
  )
91
  chunks = text_splitter.split_documents(pages)
@@ -103,7 +96,7 @@ retriever = vectordb.as_retriever(search_kwargs = {"k": 3})
103
  # Function to generate assistant's response using ask function
104
  def generate_assistant_response(question):
105
  context = retriever.get_relevant_documents(question)
106
- qna_prompt_template= f"""### [INST] Instruction: You will be provided with questions and context. Your task is to find the answers to the questions using the given data. If the data doesn't contain the answer to the question, then you must return 'Not enough information.'
107
  Context: ```
108
  {context}
109
  ```
 
65
  code = file.read()
66
  output.write(f"Filepath: {filepath}:\n\n")
67
  output.write(code + "\n\n")
 
 
 
 
 
 
68
 
69
  from langchain.text_splitter import RecursiveCharacterTextSplitter
70
  from langchain_community.document_loaders import TextLoader
 
77
 
78
  # Split data into chunks
79
  text_splitter = RecursiveCharacterTextSplitter(
80
+ chunk_size = 2000,
81
  chunk_overlap = 20,
 
82
  add_start_index = True,
83
  )
84
  chunks = text_splitter.split_documents(pages)
 
96
  # Function to generate assistant's response using ask function
97
  def generate_assistant_response(question):
98
  context = retriever.get_relevant_documents(question)
99
+ qna_prompt_template= f"""### [INST] Instruction: You will be provided with questions and context. Your task is to find the answers to the questions using the given data.'
100
  Context: ```
101
  {context}
102
  ```