Skip to content

Commit cdeb6ba

Browse files
pjoshi30Preetam Joshi
andauthored
Fixed issue in detect decorator. Improved code organization. (#21)
* 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 <[email protected]> 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 --------- Co-authored-by: Preetam Joshi <[email protected]>
1 parent 44342ad commit cdeb6ba

File tree

10 files changed

+114
-460
lines changed

10 files changed

+114
-460
lines changed

aimon/decorators/detect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def wrapper(*args, **kwargs):
3838
aimon_payload['user_query'] = result_dict['user_query']
3939
if 'instructions' in result_dict:
4040
aimon_payload['instructions'] = result_dict['instructions']
41+
aimon_payload['config'] = self.config
4142

4243
data_to_send = [aimon_payload]
4344

examples/chatbot/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ related to the webpage, in which case it is likely to answer out of its own lear
77

88
## Setup
99

10+
Make sure you have the AIMon API key which can be obtained by signing up on the AIMon website.
11+
1012
### Installation
1113

1214
Install the required packages from the `requirements.txt` file specified in this directory.

examples/chatbot/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ llama-index
22
llama-index-readers-web
33
streamlit
44
openai
5-
aimon
5+
aimon>=0.5.0
66

examples/langchain_summarization_app.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/metaflow/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The summarizer is built using Langchain.
66

77
## Setup
88

9+
Make sure you have the AIMon API key which can be obtained by signing up on the AIMon website.
10+
911
### Installation
1012

1113
Install the required packages from the `requirements.txt` file specified in this directory.
@@ -19,8 +21,8 @@ pip install -r requirements.txt
1921
You will need to specify AIMon and OpenAI API keys as part of their respective environment variables.
2022

2123
```bash
22-
export OPENAI_KEY=YOUR_OPENAI_API
23-
export AIMON_API_KEY=YOUR_AIMON_API
24+
export OPENAI_KEY=YOUR_OPENAI_API_KEY
25+
export AIMON_API_KEY=YOUR_AIMON_API_KEY
2426
```
2527

2628
### Running the flow

examples/metaflow/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
langchain
22
langchain-community
33
metaflow
4-
aimon
4+
aimon>=0.5.0
55
openai
66

examples/postman_collections/aimon_hallucination_detection_beta.postman_collection.march2024.json

Lines changed: 0 additions & 383 deletions
This file was deleted.

examples/summarization/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Summarization
2+
3+
This is a simple streamlit based Langchain Summarization application with an inline AIMon detector.
4+
5+
## Setup
6+
7+
Make sure you have the AIMon API key which can be obtained by signing up on the AIMon website.
8+
9+
### Installation
10+
11+
Install the required packages from the `requirements.txt` file specified in this directory.
12+
13+
```bash
14+
pip install -r requirements.txt
15+
```
16+
17+
### API Keys
18+
19+
You will need to specify AIMon and OpenAI API keys in a `secrets.toml` file inside the
20+
`.streamlit` directory.
21+
22+
```toml
23+
openai_key=YOUR_OPENAI_API_KEY
24+
aimon_api_key=YOUR_AIMON_API_KEY
25+
```
26+
27+
### Running the Summarization App
28+
29+
The summarization app is a streamlit app. You can run it using this command:
30+
31+
```bash
32+
streamlit run langchain_summarization_app.py
33+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import streamlit as st
2+
from langchain.text_splitter import CharacterTextSplitter
3+
from langchain.docstore.document import Document
4+
from langchain.llms.openai import OpenAI
5+
from langchain.chains.summarize import load_summarize_chain
6+
7+
from aimon import Detect
8+
9+
# Streamlit app
10+
st.title('LangChain Text Summarizer')
11+
12+
# Get OpenAI API key and source text input
13+
openai_api_key = st.secrets.openai_key
14+
aimon_api_key = st.secrets.aimon_api_key
15+
source_text = st.text_area("Source Text", height=200)
16+
17+
config = {"hallucination": {"detector_name": "default"},
18+
"conciseness": {"detector_name": "default"},
19+
"completeness": {"detector_name": "default"},
20+
"toxicity": {"detector_name": "default"}
21+
}
22+
detect = Detect(['context', 'generated_text'], api_key=aimon_api_key, config=config)
23+
24+
25+
@detect
26+
def summarize():
27+
# Split the source text
28+
text_splitter = CharacterTextSplitter()
29+
texts = text_splitter.split_text(source_text)
30+
# Create Document objects for the texts
31+
docs = [Document(page_content=t) for t in texts[:3]]
32+
# Initialize the OpenAI module, load and run the summarize chain
33+
llm = OpenAI(temperature=0, openai_api_key=openai_api_key)
34+
chain = load_summarize_chain(llm, chain_type="map_reduce")
35+
doc_summary = chain.run(docs)
36+
return source_text, doc_summary
37+
38+
39+
# Check if the 'Summarize' button is clicked
40+
if st.button("Summarize"):
41+
# Validate inputs
42+
if not openai_api_key.strip() or not aimon_api_key.strip():
43+
st.write("Please provide the OpenAI and AIMon API keys in the .streamlit/secrets.toml file.")
44+
if not source_text.strip():
45+
st.write(f"Please complete the missing fields.")
46+
else:
47+
try:
48+
context, summary, aimon_res = summarize()
49+
# Display summary
50+
st.header('Summary')
51+
st.write(summary)
52+
53+
# You could perform any action based on the AIMon response (aimon_res) here
54+
# ....
55+
56+
# Display the Aimon Rely response
57+
st.header('Aimon Rely - Hallucination Detector Response')
58+
st.json(aimon_res.hallucination)
59+
60+
st.header('Aimon Rely - Conciseness Detector Response')
61+
st.json(aimon_res.conciseness)
62+
63+
st.header('Aimon Rely - Completeness Detector Response')
64+
st.json(aimon_res.completeness)
65+
66+
st.header('Aimon Rely - Toxicity Detector Response')
67+
st.json(aimon_res.toxicity)
68+
69+
except Exception as e:
70+
st.write(f"An error occurred: {e}")
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
openai
22
langchain
33
langchain-community
4-
tiktoken
5-
requests
6-
pytest
74
streamlit
8-
pandas
9-
boto3
5+
tiktoken
6+
aimon>=0.5.0

0 commit comments

Comments
 (0)