Adding UI enhancements
Browse files- .idea/abalone_chat_application.iml +9 -0
- .idea/copilot.data.migration.agent.xml +6 -0
- .idea/copilot.data.migration.ask.xml +6 -0
- .idea/copilot.data.migration.ask2agent.xml +6 -0
- .idea/copilot.data.migration.edit.xml +6 -0
- .idea/misc.xml +9 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +48 -28
.idea/abalone_chat_application.iml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="JAVA_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
| 4 |
+
<exclude-output />
|
| 5 |
+
<content url="file://$MODULE_DIR$" />
|
| 6 |
+
<orderEntry type="inheritedJdk" />
|
| 7 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 8 |
+
</component>
|
| 9 |
+
</module>
|
.idea/copilot.data.migration.agent.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="AgentMigrationStateService">
|
| 4 |
+
<option name="migrationStatus" value="COMPLETED" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
.idea/copilot.data.migration.ask.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="AskMigrationStateService">
|
| 4 |
+
<option name="migrationStatus" value="COMPLETED" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
.idea/copilot.data.migration.ask2agent.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Ask2AgentMigrationStateService">
|
| 4 |
+
<option name="migrationStatus" value="COMPLETED" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
.idea/copilot.data.migration.edit.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="EditMigrationStateService">
|
| 4 |
+
<option name="migrationStatus" value="COMPLETED" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.10 (DDSProject2_AbaloneExploration)" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Python 3.10 (DDSProject2_AbaloneExploration)" project-jdk-type="Python SDK">
|
| 7 |
+
<output url="file://$PROJECT_DIR$/out" />
|
| 8 |
+
</component>
|
| 9 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/abalone_chat_application.iml" filepath="$PROJECT_DIR$/.idea/abalone_chat_application.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app.py
CHANGED
|
@@ -33,6 +33,32 @@ top_k = st.sidebar.slider(
|
|
| 33 |
value=4,
|
| 34 |
)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
data_dir = "./data"
|
| 37 |
persist_dir = "./vectorstore"
|
| 38 |
|
|
@@ -110,16 +136,12 @@ if st.session_state["chat_history"]:
|
|
| 110 |
for src in sources:
|
| 111 |
label = format_source_label(src.get("metadata", {}) or {}, src.get("index", 0))
|
| 112 |
st.markdown(f"- {label}")
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
st.write(meta)
|
| 120 |
-
preview = src.get("content_preview", "")
|
| 121 |
-
if preview:
|
| 122 |
-
st.write(preview)
|
| 123 |
|
| 124 |
user_input = st.chat_input("Ask a question about abalone (biology, data, methodology, etc.)")
|
| 125 |
|
|
@@ -132,8 +154,10 @@ if user_input:
|
|
| 132 |
(h.get("question"), h.get("answer", "")) for h in st.session_state["chat_history"]
|
| 133 |
]
|
| 134 |
|
|
|
|
|
|
|
| 135 |
result = chain(
|
| 136 |
-
{"question":
|
| 137 |
)
|
| 138 |
|
| 139 |
answer = (
|
|
@@ -148,19 +172,19 @@ if user_input:
|
|
| 148 |
for idx, sd in enumerate(source_docs, start=1):
|
| 149 |
if isinstance(sd, dict):
|
| 150 |
meta = sd.get("metadata", {}) or {}
|
| 151 |
-
|
| 152 |
else:
|
| 153 |
meta = getattr(sd, "metadata", {}) or {}
|
| 154 |
-
|
| 155 |
-
if
|
| 156 |
-
|
| 157 |
-
if
|
| 158 |
-
|
| 159 |
sources_for_ui.append(
|
| 160 |
{
|
| 161 |
"index": idx,
|
| 162 |
"metadata": meta,
|
| 163 |
-
"
|
| 164 |
}
|
| 165 |
)
|
| 166 |
|
|
@@ -174,16 +198,12 @@ if user_input:
|
|
| 174 |
for src in sources_for_ui:
|
| 175 |
label = format_source_label(src.get("metadata", {}) or {}, src.get("index", 0))
|
| 176 |
st.markdown(f"- {label}")
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
st.write(meta)
|
| 184 |
-
preview = src.get("content_preview", "")
|
| 185 |
-
if preview:
|
| 186 |
-
st.write(preview)
|
| 187 |
|
| 188 |
st.session_state["chat_history"].append(
|
| 189 |
{
|
|
|
|
| 33 |
value=4,
|
| 34 |
)
|
| 35 |
|
| 36 |
+
temperature = st.sidebar.slider(
|
| 37 |
+
"Temperature",
|
| 38 |
+
min_value=0.0,
|
| 39 |
+
max_value=1.0,
|
| 40 |
+
value=0.2,
|
| 41 |
+
step=0.05,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
answer_length = st.sidebar.selectbox(
|
| 45 |
+
"Answer length",
|
| 46 |
+
["Short", "Medium", "Long"],
|
| 47 |
+
index=1,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
length_instruction_map = {
|
| 51 |
+
"Short": "Answer in 1–3 sentences.",
|
| 52 |
+
"Medium": "Answer in 1–2 paragraphs.",
|
| 53 |
+
"Long": "Provide a detailed, multi-paragraph explanation.",
|
| 54 |
+
}
|
| 55 |
+
length_instruction = length_instruction_map[answer_length]
|
| 56 |
+
style_instruction = (
|
| 57 |
+
length_instruction
|
| 58 |
+
+ f" Use a response style appropriate for a temperature of {temperature:.2f}, "
|
| 59 |
+
"where lower values are more factual and higher values are more exploratory."
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
data_dir = "./data"
|
| 63 |
persist_dir = "./vectorstore"
|
| 64 |
|
|
|
|
| 136 |
for src in sources:
|
| 137 |
label = format_source_label(src.get("metadata", {}) or {}, src.get("index", 0))
|
| 138 |
st.markdown(f"- {label}")
|
| 139 |
+
for src in sources:
|
| 140 |
+
idx = src.get("index", 0)
|
| 141 |
+
chunk_text = src.get("content", "")
|
| 142 |
+
if chunk_text:
|
| 143 |
+
with st.expander(f"Show chunk [{idx}]"):
|
| 144 |
+
st.write(chunk_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
user_input = st.chat_input("Ask a question about abalone (biology, data, methodology, etc.)")
|
| 147 |
|
|
|
|
| 154 |
(h.get("question"), h.get("answer", "")) for h in st.session_state["chat_history"]
|
| 155 |
]
|
| 156 |
|
| 157 |
+
styled_question = style_instruction + "\n\nQuestion: " + user_input
|
| 158 |
+
|
| 159 |
result = chain(
|
| 160 |
+
{"question": styled_question, "chat_history": prior_history}
|
| 161 |
)
|
| 162 |
|
| 163 |
answer = (
|
|
|
|
| 172 |
for idx, sd in enumerate(source_docs, start=1):
|
| 173 |
if isinstance(sd, dict):
|
| 174 |
meta = sd.get("metadata", {}) or {}
|
| 175 |
+
content_full = sd.get("page_content") or sd.get("content") or sd.get("text", "")
|
| 176 |
else:
|
| 177 |
meta = getattr(sd, "metadata", {}) or {}
|
| 178 |
+
content_full = getattr(sd, "page_content", None)
|
| 179 |
+
if content_full is None:
|
| 180 |
+
content_full = getattr(sd, "content", "")
|
| 181 |
+
if content_full is None:
|
| 182 |
+
content_full = ""
|
| 183 |
sources_for_ui.append(
|
| 184 |
{
|
| 185 |
"index": idx,
|
| 186 |
"metadata": meta,
|
| 187 |
+
"content": str(content_full),
|
| 188 |
}
|
| 189 |
)
|
| 190 |
|
|
|
|
| 198 |
for src in sources_for_ui:
|
| 199 |
label = format_source_label(src.get("metadata", {}) or {}, src.get("index", 0))
|
| 200 |
st.markdown(f"- {label}")
|
| 201 |
+
for src in sources_for_ui:
|
| 202 |
+
idx = src.get("index", 0)
|
| 203 |
+
chunk_text = src.get("content", "")
|
| 204 |
+
if chunk_text:
|
| 205 |
+
with st.expander(f"Show chunk [{idx}]"):
|
| 206 |
+
st.write(chunk_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
st.session_state["chat_history"].append(
|
| 209 |
{
|