Skip to content

Commit d8a6415

Browse files
pjoshi30Preetam Joshi
andauthored
Moving instructions bar to the bottom of the page. (#30)
* Initial commit Adding the Aimon Rely README, images, the postman collection, a simple client and examples. A few small changes for error handling in the client and the example application. Getting the Aimon API key from the streamlit app updating README Updating langchain example gif Updating API endpoint Adding V2 API with support for conciseness, completeness and toxicity checks (#1) * Adding V2 API with support for conciseness, completeness and toxicity checks. * Removing prints and updating config for the example application. * Updating README --------- Co-authored-by: Preetam Joshi <info@aimon.ai> Updating postman collection Fixed the simple aimon client's handling of batch requests. Updated postman collection. Added support for a user_query parameter in the input data dictionary. Updating readme Fixed bug in the example app Uploading client code Adding more convenience APIs Fixing bug in create_dataset Added Github actions config to publish to PyPI. Cleaned up dependencies and updated documentation. Fixing langchain example Fixing doc links Formatting changes Changes for aimon-rely * Adding instruction adherence and hallucination v0.2 to the client Updating git ignore Adding more to gitignore Removing .idea files * Fixing doc string * Updating documentation * Updating Client to use V3 API * Fixing test * Updating tests * Updating documentation in the client * Adding .streamlit dir to .gitignore * initial version of decorators for syntactic sugar * A few more changes * updating analyze and detect decorators * Adding new notebooks * Fixing bug in analyze decorator * Updating Detect decorator to make it simpler. Adding Metaflow example. Adding documentation for the chatbot. * fixing chatbot example * Fixed issue in detect decorator. Improved code organization. * fixed typo * Updated the decorators with a more cleaner interface. Added a metaflow analyze example. * Updated version * Updated Notebook * Fixing context parsing issue with analyze_eval decorator * Updating application to production in the analyze_prod decorator * Updating SDK to handle instructions in evaluation and continuous monitoring. * Deleting old notebook * Fixing usability issues in the chatbot. Organizing examples a bit better. * Adding analyze to the chatbot * Fixing readme and adding instruction bar at the bottom --------- Co-authored-by: Preetam Joshi <info@aimon.ai>
1 parent c40d449 commit d8a6415

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

examples/streamlit_apps/chatbot/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You will need to specify AIMon and OpenAI API keys as part of their respective e
2323

2424
```bash
2525
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY
26-
export AIMON_API_KEY=YOUR_AIMON_API
26+
export AIMON_API_KEY=YOUR_AIMON_API_KEY
2727
```
2828

2929
### Running the Chatbot
@@ -34,6 +34,6 @@ The chatbot is a streamlit app. You can run it using this command:
3434
python -m streamlit run aimon_chatbot_demo.py
3535
```
3636

37-
Note that on
37+
Note that on startup, the chatbot will take several seconds to crawl the web page, generate embeddings etc.
3838

3939

examples/streamlit_apps/chatbot/aimon_chatbot_demo.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ def execute():
101101
openai_api_key = os.getenv("OPENAI_API_KEY")
102102

103103
openai.api_key = openai_api_key
104-
instructions = st.text_input(
105-
"Instructions for the chatbot. Ex: Answer the user's question in a professional tone.",
106-
value="Answer the user's question in a professional tone."
107-
)
108104
st.title("Ask questions on Paul Graham's Work Experience")
109105

110106
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
@@ -127,7 +123,7 @@ def execute():
127123
"Here are the relevant documents for the context:\n"
128124
"{context_str}"
129125
"\nInstruction: Use the previous chat history, or the context above, to interact and help the user. " +
130-
"{}".format(instructions if instructions else "")
126+
"{}".format(st.session_state.instructions if "instructions" in st.session_state else "Answer the user's question in a professional tone.")
131127
),
132128
verbose=False,
133129
similarity_top_k=4,
@@ -136,18 +132,23 @@ def execute():
136132
if cprompt := st.chat_input("Example: Where did Paul Graham Work?"):
137133
st.session_state.messages.append({"role": "user", "content": cprompt})
138134

135+
139136
for message in st.session_state.messages: # Write message history to UI
140137
with st.chat_message(message["role"]):
141138
st.write(message["content"])
142139
if "aimon_response" in message:
143140
combined_json = {"AIMon Response": message["aimon_response"], "context": message["context"]}
144141
st.json(combined_json, expanded=False)
142+
143+
instructions = st.text_input("Instructions for the chatbot",
144+
value=st.session_state.instructions if "instructions" in st.session_state else "Answer the user's question in a professional tone.")
145+
st.session_state.instructions = instructions if instructions else "Answer the user's question in a professional tone."
145146

146147
# If last message is not from assistant, generate a new response
147148
if st.session_state.messages[-1]["role"] != "assistant":
148149
with st.chat_message("assistant"):
149150
if cprompt:
150-
context, usr_prompt, instructions, response, am_res, am_analyze_res = am_chat(cprompt, instructions)
151+
context, usr_prompt, instructions, response, am_res, am_analyze_res = am_chat(cprompt, st.session_state.instructions if "instructions" in st.session_state else "Answer the user's question in a professional tone.")
151152
message = {"role": "assistant", "content": response}
152153
am_res_json = am_res.to_json()
153154
st.write(response)
@@ -157,6 +158,11 @@ def execute():
157158
message.update({'aimon_response': am_res_json, 'context': {"text": context}})
158159
# Add response to message history
159160
st.session_state.messages.append(message)
161+
instructions = st.text_input(
162+
"Instructions for the chatbot. Ex: Answer the user's question in a professional tone.",
163+
value="Answer the user's question in a professional tone." if "instructions" not in st.session_state else st.session_state.instructions
164+
)
165+
st.session_state.instructions = instructions
160166

161167

162168
try:

0 commit comments

Comments
 (0)