-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <preetam@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 --------- Co-authored-by: Preetam Joshi <preetam@aimon.ai>
- Loading branch information
Showing
10 changed files
with
114 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ llama-index | |
llama-index-readers-web | ||
streamlit | ||
openai | ||
aimon | ||
aimon>=0.5.0 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
langchain | ||
langchain-community | ||
metaflow | ||
aimon | ||
aimon>=0.5.0 | ||
openai | ||
|
383 changes: 0 additions & 383 deletions
383
.../postman_collections/aimon_hallucination_detection_beta.postman_collection.march2024.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Summarization | ||
|
||
This is a simple streamlit based Langchain Summarization application with an inline AIMon detector. | ||
|
||
## Setup | ||
|
||
Make sure you have the AIMon API key which can be obtained by signing up on the AIMon website. | ||
|
||
### Installation | ||
|
||
Install the required packages from the `requirements.txt` file specified in this directory. | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### API Keys | ||
|
||
You will need to specify AIMon and OpenAI API keys in a `secrets.toml` file inside the | ||
`.streamlit` directory. | ||
|
||
```toml | ||
openai_key=YOUR_OPENAI_API_KEY | ||
aimon_api_key=YOUR_AIMON_API_KEY | ||
``` | ||
|
||
### Running the Summarization App | ||
|
||
The summarization app is a streamlit app. You can run it using this command: | ||
|
||
```bash | ||
streamlit run langchain_summarization_app.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import streamlit as st | ||
from langchain.text_splitter import CharacterTextSplitter | ||
from langchain.docstore.document import Document | ||
from langchain.llms.openai import OpenAI | ||
from langchain.chains.summarize import load_summarize_chain | ||
|
||
from aimon import Detect | ||
|
||
# Streamlit app | ||
st.title('LangChain Text Summarizer') | ||
|
||
# Get OpenAI API key and source text input | ||
openai_api_key = st.secrets.openai_key | ||
aimon_api_key = st.secrets.aimon_api_key | ||
source_text = st.text_area("Source Text", height=200) | ||
|
||
config = {"hallucination": {"detector_name": "default"}, | ||
"conciseness": {"detector_name": "default"}, | ||
"completeness": {"detector_name": "default"}, | ||
"toxicity": {"detector_name": "default"} | ||
} | ||
detect = Detect(['context', 'generated_text'], api_key=aimon_api_key, config=config) | ||
|
||
|
||
@detect | ||
def summarize(): | ||
# Split the source text | ||
text_splitter = CharacterTextSplitter() | ||
texts = text_splitter.split_text(source_text) | ||
# Create Document objects for the texts | ||
docs = [Document(page_content=t) for t in texts[:3]] | ||
# Initialize the OpenAI module, load and run the summarize chain | ||
llm = OpenAI(temperature=0, openai_api_key=openai_api_key) | ||
chain = load_summarize_chain(llm, chain_type="map_reduce") | ||
doc_summary = chain.run(docs) | ||
return source_text, doc_summary | ||
|
||
|
||
# Check if the 'Summarize' button is clicked | ||
if st.button("Summarize"): | ||
# Validate inputs | ||
if not openai_api_key.strip() or not aimon_api_key.strip(): | ||
st.write("Please provide the OpenAI and AIMon API keys in the .streamlit/secrets.toml file.") | ||
if not source_text.strip(): | ||
st.write(f"Please complete the missing fields.") | ||
else: | ||
try: | ||
context, summary, aimon_res = summarize() | ||
# Display summary | ||
st.header('Summary') | ||
st.write(summary) | ||
|
||
# You could perform any action based on the AIMon response (aimon_res) here | ||
# .... | ||
|
||
# Display the Aimon Rely response | ||
st.header('Aimon Rely - Hallucination Detector Response') | ||
st.json(aimon_res.hallucination) | ||
|
||
st.header('Aimon Rely - Conciseness Detector Response') | ||
st.json(aimon_res.conciseness) | ||
|
||
st.header('Aimon Rely - Completeness Detector Response') | ||
st.json(aimon_res.completeness) | ||
|
||
st.header('Aimon Rely - Toxicity Detector Response') | ||
st.json(aimon_res.toxicity) | ||
|
||
except Exception as e: | ||
st.write(f"An error occurred: {e}") |
7 changes: 2 additions & 5 deletions
7
examples/requirements.txt → examples/summarization/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
openai | ||
langchain | ||
langchain-community | ||
tiktoken | ||
requests | ||
pytest | ||
streamlit | ||
pandas | ||
boto3 | ||
tiktoken | ||
aimon>=0.5.0 |