Spaces:
Sleeping
Sleeping
update
Browse files- .gitignore +142 -0
- app.py +21 -5
- requirements.txt +1 -8
.gitignore
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
crawlers/__pycache__/
|
6 |
+
core/__pycache__/
|
7 |
+
*.py[cod]
|
8 |
+
*$py.class
|
9 |
+
|
10 |
+
# C extensions
|
11 |
+
*.so
|
12 |
+
|
13 |
+
# Distribution / packaging
|
14 |
+
.Python
|
15 |
+
build/
|
16 |
+
develop-eggs/
|
17 |
+
dist/
|
18 |
+
downloads/
|
19 |
+
eggs/
|
20 |
+
.eggs/
|
21 |
+
lib/
|
22 |
+
lib64/
|
23 |
+
parts/
|
24 |
+
sdist/
|
25 |
+
var/
|
26 |
+
wheels/
|
27 |
+
pip-wheel-metadata/
|
28 |
+
share/python-wheels/
|
29 |
+
*.egg-info/
|
30 |
+
.installed.cfg
|
31 |
+
*.egg
|
32 |
+
MANIFEST
|
33 |
+
|
34 |
+
# PyInstaller
|
35 |
+
# Usually these files are written by a python script from a template
|
36 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
37 |
+
*.manifest
|
38 |
+
*.spec
|
39 |
+
|
40 |
+
# Installer logs
|
41 |
+
pip-log.txt
|
42 |
+
pip-delete-this-directory.txt
|
43 |
+
|
44 |
+
# Unit test / coverage reports
|
45 |
+
htmlcov/
|
46 |
+
.tox/
|
47 |
+
.nox/
|
48 |
+
.coverage
|
49 |
+
.coverage.*
|
50 |
+
.cache
|
51 |
+
nosetests.xml
|
52 |
+
coverage.xml
|
53 |
+
*.cover
|
54 |
+
*.py,cover
|
55 |
+
.hypothesis/
|
56 |
+
.pytest_cache/
|
57 |
+
|
58 |
+
# Translations
|
59 |
+
*.mo
|
60 |
+
*.pot
|
61 |
+
|
62 |
+
# Django stuff:
|
63 |
+
*.log
|
64 |
+
local_settings.py
|
65 |
+
db.sqlite3
|
66 |
+
db.sqlite3-journal
|
67 |
+
|
68 |
+
# Flask stuff:
|
69 |
+
instance/
|
70 |
+
.webassets-cache
|
71 |
+
|
72 |
+
# Scrapy stuff:
|
73 |
+
.scrapy
|
74 |
+
|
75 |
+
# Sphinx documentation
|
76 |
+
docs/_build/
|
77 |
+
|
78 |
+
# PyBuilder
|
79 |
+
target/
|
80 |
+
|
81 |
+
# Jupyter Notebook
|
82 |
+
.ipynb_checkpoints
|
83 |
+
|
84 |
+
# IPython
|
85 |
+
profile_default/
|
86 |
+
ipython_config.py
|
87 |
+
|
88 |
+
# pyenv
|
89 |
+
.python-version
|
90 |
+
|
91 |
+
# pipenv
|
92 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
93 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
94 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
95 |
+
# install all needed dependencies.
|
96 |
+
#Pipfile.lock
|
97 |
+
|
98 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
99 |
+
__pypackages__/
|
100 |
+
|
101 |
+
# Celery stuff
|
102 |
+
celerybeat-schedule
|
103 |
+
celerybeat.pid
|
104 |
+
|
105 |
+
# SageMath parsed files
|
106 |
+
*.sage.py
|
107 |
+
|
108 |
+
# Environments
|
109 |
+
.env
|
110 |
+
.env*
|
111 |
+
.venv
|
112 |
+
env/
|
113 |
+
venv/
|
114 |
+
ENV/
|
115 |
+
env.bak/
|
116 |
+
venv.bak/
|
117 |
+
|
118 |
+
# secrets file in TOML format
|
119 |
+
secrets.toml
|
120 |
+
|
121 |
+
# Spyder project settings
|
122 |
+
.spyderproject
|
123 |
+
.spyproject
|
124 |
+
|
125 |
+
# Rope project settings
|
126 |
+
.ropeproject
|
127 |
+
|
128 |
+
# mkdocs documentation
|
129 |
+
/site
|
130 |
+
|
131 |
+
# mypy
|
132 |
+
.mypy_cache/
|
133 |
+
.dmypy.json
|
134 |
+
dmypy.json
|
135 |
+
|
136 |
+
# Pyre type checker
|
137 |
+
.pyre/
|
138 |
+
|
139 |
+
# project file
|
140 |
+
project.yaml
|
141 |
+
|
142 |
+
.idea/
|
app.py
CHANGED
@@ -6,6 +6,7 @@ from PIL import Image
|
|
6 |
import re
|
7 |
import sys
|
8 |
import datetime
|
|
|
9 |
|
10 |
from pydantic import Field, BaseModel
|
11 |
from vectara_agent.agent import Agent, AgentType, AgentStatusType
|
@@ -18,6 +19,7 @@ languages = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', '
|
|
18 |
'Hebrew': 'he', 'Hindi': 'hi', 'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Portuguese': 'pt'}
|
19 |
initial_prompt = "How can I help you today?"
|
20 |
|
|
|
21 |
|
22 |
def create_tools(cfg):
|
23 |
|
@@ -90,7 +92,7 @@ def initialize_agent(agent_type: AgentType, _cfg):
|
|
90 |
|
91 |
def update_func(status_type: AgentStatusType, msg: str):
|
92 |
output = f"{status_type.value} - {msg}"
|
93 |
-
st.session_state.
|
94 |
|
95 |
agent = Agent(
|
96 |
agent_type=agent_type,
|
@@ -107,6 +109,8 @@ def launch_bot(agent_type: AgentType):
|
|
107 |
st.session_state.messages = [{"role": "assistant", "content": initial_prompt, "avatar": "π¦"}]
|
108 |
st.session_state.thinking_message = "Agent at work..."
|
109 |
st.session_state.agent = initialize_agent(agent_type, cfg)
|
|
|
|
|
110 |
|
111 |
st.set_page_config(page_title="Justice Harvard Teaching Assistant", layout="wide")
|
112 |
if 'cfg' not in st.session_state:
|
@@ -155,8 +159,13 @@ def launch_bot(agent_type: AgentType):
|
|
155 |
reset()
|
156 |
|
157 |
st.markdown("\n\n")
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
st.markdown("---")
|
162 |
st.markdown(
|
@@ -185,14 +194,21 @@ def launch_bot(agent_type: AgentType):
|
|
185 |
if st.session_state.messages[-1]["role"] != "assistant":
|
186 |
with st.chat_message("assistant", avatar='π€'):
|
187 |
with st.spinner(st.session_state.thinking_message):
|
188 |
-
st.session_state.thinking_placeholder = st.empty()
|
189 |
res = st.session_state.agent.chat(prompt)
|
190 |
cleaned = re.sub(r'\[\d+\]', '', res).replace('$', '\\$')
|
191 |
message = {"role": "assistant", "content": cleaned, "avatar": 'π€'}
|
192 |
st.session_state.messages.append(message)
|
193 |
-
st.session_state.thinking_placeholder.empty()
|
194 |
st.rerun()
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
sys.stdout.flush()
|
197 |
|
198 |
|
|
|
6 |
import re
|
7 |
import sys
|
8 |
import datetime
|
9 |
+
from dotenv import load_dotenv
|
10 |
|
11 |
from pydantic import Field, BaseModel
|
12 |
from vectara_agent.agent import Agent, AgentType, AgentStatusType
|
|
|
19 |
'Hebrew': 'he', 'Hindi': 'hi', 'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Portuguese': 'pt'}
|
20 |
initial_prompt = "How can I help you today?"
|
21 |
|
22 |
+
load_dotenv()
|
23 |
|
24 |
def create_tools(cfg):
|
25 |
|
|
|
92 |
|
93 |
def update_func(status_type: AgentStatusType, msg: str):
|
94 |
output = f"{status_type.value} - {msg}"
|
95 |
+
st.session_state.log_messages.append(output)
|
96 |
|
97 |
agent = Agent(
|
98 |
agent_type=agent_type,
|
|
|
109 |
st.session_state.messages = [{"role": "assistant", "content": initial_prompt, "avatar": "π¦"}]
|
110 |
st.session_state.thinking_message = "Agent at work..."
|
111 |
st.session_state.agent = initialize_agent(agent_type, cfg)
|
112 |
+
st.session_state.log_messages = []
|
113 |
+
st.session_state.show_logs = False
|
114 |
|
115 |
st.set_page_config(page_title="Justice Harvard Teaching Assistant", layout="wide")
|
116 |
if 'cfg' not in st.session_state:
|
|
|
159 |
reset()
|
160 |
|
161 |
st.markdown("\n\n")
|
162 |
+
bc1, bc2 = st.columns([1, 1])
|
163 |
+
with bc1:
|
164 |
+
if st.button('Start Over'):
|
165 |
+
reset()
|
166 |
+
with bc2:
|
167 |
+
if st.button('Show Logs'):
|
168 |
+
st.session_state.show_logs = not st.session_state.show_logs
|
169 |
|
170 |
st.markdown("---")
|
171 |
st.markdown(
|
|
|
194 |
if st.session_state.messages[-1]["role"] != "assistant":
|
195 |
with st.chat_message("assistant", avatar='π€'):
|
196 |
with st.spinner(st.session_state.thinking_message):
|
|
|
197 |
res = st.session_state.agent.chat(prompt)
|
198 |
cleaned = re.sub(r'\[\d+\]', '', res).replace('$', '\\$')
|
199 |
message = {"role": "assistant", "content": cleaned, "avatar": 'π€'}
|
200 |
st.session_state.messages.append(message)
|
|
|
201 |
st.rerun()
|
202 |
|
203 |
+
# Display log messages in an expander
|
204 |
+
if st.session_state.show_logs:
|
205 |
+
with st.expander("Agent Log Messages", expanded=True):
|
206 |
+
for msg in st.session_state.log_messages:
|
207 |
+
st.write(msg)
|
208 |
+
if st.button('Close Logs'):
|
209 |
+
st.session_state.show_logs = False
|
210 |
+
st.rerun()
|
211 |
+
|
212 |
sys.stdout.flush()
|
213 |
|
214 |
|
requirements.txt
CHANGED
@@ -1,12 +1,5 @@
|
|
1 |
-
requests_to_curl==1.1.0
|
2 |
-
toml==0.10.2
|
3 |
omegaconf==2.3.0
|
4 |
-
syrupy==4.0.8
|
5 |
streamlit==1.32.2
|
6 |
-
translate==3.6.1
|
7 |
-
llama-index==0.10.42
|
8 |
-
llama-index-indices-managed-vectara==0.1.4
|
9 |
-
llama-index-agent-openai==0.1.5
|
10 |
pydantic==1.10.15
|
|
|
11 |
git+https://{GITHUB_TOKEN}@github.com/vectara/vectara-agent.git
|
12 |
-
|
|
|
|
|
|
|
1 |
omegaconf==2.3.0
|
|
|
2 |
streamlit==1.32.2
|
|
|
|
|
|
|
|
|
3 |
pydantic==1.10.15
|
4 |
+
python-dotenv==1.0.1
|
5 |
git+https://{GITHUB_TOKEN}@github.com/vectara/vectara-agent.git
|
|