Skip to content

Commit c40d449

Browse files
pjoshi30Preetam Joshi
andauthored
Adding analyze to the example chatbot application (#29)
* 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 --------- Co-authored-by: Preetam Joshi <info@aimon.ai>
1 parent 70e0b50 commit c40d449

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

examples/streamlit_apps/chatbot/aimon_chatbot_demo.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from llama_index.core.memory import ChatMemoryBuffer
66
from llama_index.core import StorageContext, load_index_from_storage
77
from llama_index.readers.web import SimpleWebPageReader
8-
from aimon import Detect
8+
from aimon import Detect, AnalyzeProd, Application, Model
99
from aimon import AuthenticationError
1010
import logging
1111
import os
@@ -21,8 +21,9 @@
2121
'completeness': {'detector_name': 'default'},
2222
'toxicity': {'detector_name': 'default'},
2323
}
24-
detect = Detect(values_returned=['context', 'user_query', 'instructions', 'generated_text'], api_key=os.getenv("AIMON_API_KEY"), config=aimon_config)
25-
24+
values_returned = ['context', 'user_query', 'instructions', 'generated_text']
25+
detect = Detect(values_returned=values_returned, api_key=os.getenv("AIMON_API_KEY"), config=aimon_config)
26+
analyze_prod = AnalyzeProd(Application("paul_graham_chatbot_aug_2024"), Model("gpt_4o_model", "GPT-4o"), values_returned=values_returned, config=aimon_config)
2627

2728
@st.cache_resource(show_spinner=False)
2829
def load_data():
@@ -88,10 +89,11 @@ def split_into_paragraphs(text):
8889
return paragraphs
8990

9091

92+
@analyze_prod
9193
@detect
9294
def am_chat(usr_prompt, instructions):
9395
response = st.session_state.chat_engine.chat(usr_prompt)
94-
context = get_source_docs(response)
96+
context, relevance_scores = get_source_docs(response)
9597
return context, usr_prompt, instructions, response.response
9698

9799

@@ -145,7 +147,7 @@ def execute():
145147
if st.session_state.messages[-1]["role"] != "assistant":
146148
with st.chat_message("assistant"):
147149
if cprompt:
148-
context, usr_prompt, instructions, response, am_res = am_chat(cprompt, instructions)
150+
context, usr_prompt, instructions, response, am_res, am_analyze_res = am_chat(cprompt, instructions)
149151
message = {"role": "assistant", "content": response}
150152
am_res_json = am_res.to_json()
151153
st.write(response)

0 commit comments

Comments
 (0)