Spaces:
Sleeping
Sleeping
Ben Burtenshaw
commited on
Commit
•
7335632
1
Parent(s):
f67c271
improve self instruct prompt
Browse files
utils.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import os
|
2 |
from textwrap import dedent
|
3 |
|
4 |
import streamlit as st
|
@@ -32,9 +31,12 @@ def project_sidebar():
|
|
32 |
st.session_state["project_name"] = project_name
|
33 |
st.session_state["hub_username"] = hub_username
|
34 |
st.session_state["hub_token"] = st.sidebar.text_input(
|
35 |
-
"Hub Token", type="password", value=
|
36 |
)
|
37 |
-
if
|
|
|
|
|
|
|
38 |
os.environ["HF_TOKEN"] = st.session_state["hub_token"]
|
39 |
st.sidebar.link_button(
|
40 |
"🤗 Get your Hub Token", "https://huggingface.co/settings/tokens"
|
@@ -67,19 +69,21 @@ def create_seed_terms(topics: list[str], perspectives: list[str]) -> list[str]:
|
|
67 |
]
|
68 |
|
69 |
|
70 |
-
def create_application_instruction(
|
|
|
|
|
71 |
"""Create the instruction for Self-Instruct task."""
|
72 |
-
system_prompt =
|
73 |
-
|
74 |
-
Your should not expect basic but profound questions from your users.
|
75 |
-
The queries should reflect a diversxamity of vision and economic positions and political positions.
|
76 |
-
The queries may know about different methods of {domain}.
|
77 |
-
The queries can be positioned politically, economically, socially, or practically.
|
78 |
-
Also take into account the impact of diverse causes on diverse domains."""
|
79 |
-
)
|
80 |
for example in examples:
|
81 |
question = example["question"]
|
82 |
answer = example["answer"]
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
return system_prompt
|
|
|
|
|
1 |
from textwrap import dedent
|
2 |
|
3 |
import streamlit as st
|
|
|
31 |
st.session_state["project_name"] = project_name
|
32 |
st.session_state["hub_username"] = hub_username
|
33 |
st.session_state["hub_token"] = st.sidebar.text_input(
|
34 |
+
"Hub Token", type="password", value=None
|
35 |
)
|
36 |
+
if (
|
37 |
+
st.sidebar.checkbox("Save Hub Token")
|
38 |
+
and st.session_state["hub_token"] is not None
|
39 |
+
):
|
40 |
os.environ["HF_TOKEN"] = st.session_state["hub_token"]
|
41 |
st.sidebar.link_button(
|
42 |
"🤗 Get your Hub Token", "https://huggingface.co/settings/tokens"
|
|
|
69 |
]
|
70 |
|
71 |
|
72 |
+
def create_application_instruction(
|
73 |
+
domain: str, system_prompt: str, examples: list[dict[str, str]]
|
74 |
+
) -> str:
|
75 |
"""Create the instruction for Self-Instruct task."""
|
76 |
+
system_prompt = f"""AI assistant in the domain of {domain}. {system_prompt}"""
|
77 |
+
examples_str = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
for example in examples:
|
79 |
question = example["question"]
|
80 |
answer = example["answer"]
|
81 |
+
if len(answer) and len(question):
|
82 |
+
examples_str += f"""\n- Question: {question}\n- Answer: {answer}\n"""
|
83 |
+
examples_str += f"""\n- Question: {question}\n- Answer: {answer}\n"""
|
84 |
+
if len(examples_str):
|
85 |
+
system_prompt += """Below are some examples of questions and answers \
|
86 |
+
that the AI assistant would generate:"""
|
87 |
+
system_prompt += "\nExamples:"
|
88 |
+
system_prompt += f"\n{examples_str}"
|
89 |
return system_prompt
|