Update app.py
Browse files
app.py
CHANGED
@@ -10,21 +10,26 @@ client = InferenceClient(model)
|
|
10 |
# Embedded system prompt
|
11 |
system_prompt_text = "You are a smart and helpful co-worker of Thailand based multi-national company PTT, and PTTEP. You help with any kind of request and provide a detailed answer to the question. But if you are asked about something unethical or dangerous, you must refuse and provide a safe and respectful way to handle that."
|
12 |
|
13 |
-
# Read the content of the info.md
|
14 |
with open("info.md", "r") as file:
|
15 |
info_md_content = file.read()
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
chunk_size = 2500 # Adjust this size as needed
|
19 |
info_md_chunks = textwrap.wrap(info_md_content, chunk_size)
|
|
|
20 |
|
21 |
def get_all_chunks(chunks):
|
22 |
return "\n\n".join(chunks)
|
23 |
|
24 |
-
def format_prompt_mixtral(message, history, info_md_chunks):
|
25 |
prompt = "<s>"
|
26 |
-
|
27 |
-
|
|
|
28 |
prompt += f"{system_prompt_text}\n\n" # Add the system prompt
|
29 |
|
30 |
if history:
|
@@ -44,7 +49,7 @@ def chat_inf(prompt, history, seed, temp, tokens, top_p, rep_p):
|
|
44 |
seed=seed,
|
45 |
)
|
46 |
|
47 |
-
formatted_prompt = format_prompt_mixtral(prompt, history, info_md_chunks)
|
48 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
49 |
output = ""
|
50 |
for response in stream:
|
@@ -96,9 +101,3 @@ with gr.Blocks() as app: # Add auth here
|
|
96 |
clear_btn.click(clear_fn, None, [inp, chat])
|
97 |
|
98 |
app.queue(default_concurrency_limit=10).launch(share=True, auth=("admin", "0112358"))
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
I have 2000 lines in info.md file, and the model throws error due to character limit.
|
103 |
-
Even though I divide chunks, I added all together which is a bad choice.
|
104 |
-
what can I do?
|
|
|
10 |
# Embedded system prompt
|
11 |
system_prompt_text = "You are a smart and helpful co-worker of Thailand based multi-national company PTT, and PTTEP. You help with any kind of request and provide a detailed answer to the question. But if you are asked about something unethical or dangerous, you must refuse and provide a safe and respectful way to handle that."
|
12 |
|
13 |
+
# Read the content of the info.md and info2.md files
|
14 |
with open("info.md", "r") as file:
|
15 |
info_md_content = file.read()
|
16 |
|
17 |
+
with open("info2.md", "r") as file:
|
18 |
+
info2_md_content = file.read()
|
19 |
+
|
20 |
+
# Chunk the info.md and info2.md content into smaller sections
|
21 |
chunk_size = 2500 # Adjust this size as needed
|
22 |
info_md_chunks = textwrap.wrap(info_md_content, chunk_size)
|
23 |
+
info2_md_chunks = textwrap.wrap(info2_md_content, chunk_size)
|
24 |
|
25 |
def get_all_chunks(chunks):
|
26 |
return "\n\n".join(chunks)
|
27 |
|
28 |
+
def format_prompt_mixtral(message, history, info_md_chunks, info2_md_chunks):
|
29 |
prompt = "<s>"
|
30 |
+
# Sequentially add chunks from both files
|
31 |
+
all_chunks = get_all_chunks(info_md_chunks + info2_md_chunks)
|
32 |
+
prompt += f"{all_chunks}\n\n" # Add all chunks at the beginning
|
33 |
prompt += f"{system_prompt_text}\n\n" # Add the system prompt
|
34 |
|
35 |
if history:
|
|
|
49 |
seed=seed,
|
50 |
)
|
51 |
|
52 |
+
formatted_prompt = format_prompt_mixtral(prompt, history, info_md_chunks, info2_md_chunks)
|
53 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
54 |
output = ""
|
55 |
for response in stream:
|
|
|
101 |
clear_btn.click(clear_fn, None, [inp, chat])
|
102 |
|
103 |
app.queue(default_concurrency_limit=10).launch(share=True, auth=("admin", "0112358"))
|
|
|
|
|
|
|
|
|
|
|
|