Skip to content

Commit

Permalink
Fixed issue in detect decorator. Improved code organization. (#21)
Browse files Browse the repository at this point in the history
* 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
pjoshi30 and Preetam Joshi authored Jul 29, 2024
1 parent 44342ad commit cdeb6ba
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 460 deletions.
1 change: 1 addition & 0 deletions aimon/decorators/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def wrapper(*args, **kwargs):
aimon_payload['user_query'] = result_dict['user_query']
if 'instructions' in result_dict:
aimon_payload['instructions'] = result_dict['instructions']
aimon_payload['config'] = self.config

data_to_send = [aimon_payload]

Expand Down
2 changes: 2 additions & 0 deletions examples/chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ related to the webpage, in which case it is likely to answer out of its own lear

## 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/chatbot/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ llama-index
llama-index-readers-web
streamlit
openai
aimon
aimon>=0.5.0

68 changes: 0 additions & 68 deletions examples/langchain_summarization_app.py

This file was deleted.

6 changes: 4 additions & 2 deletions examples/metaflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The summarizer is built using Langchain.

## 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.
Expand All @@ -19,8 +21,8 @@ pip install -r requirements.txt
You will need to specify AIMon and OpenAI API keys as part of their respective environment variables.

```bash
export OPENAI_KEY=YOUR_OPENAI_API
export AIMON_API_KEY=YOUR_AIMON_API
export OPENAI_KEY=YOUR_OPENAI_API_KEY
export AIMON_API_KEY=YOUR_AIMON_API_KEY
```

### Running the flow
Expand Down
2 changes: 1 addition & 1 deletion examples/metaflow/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
langchain
langchain-community
metaflow
aimon
aimon>=0.5.0
openai

This file was deleted.

33 changes: 33 additions & 0 deletions examples/summarization/README.md
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
```
70 changes: 70 additions & 0 deletions examples/summarization/langchain_summarization_app.py
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}")
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

0 comments on commit cdeb6ba

Please sign in to comment.