-
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.
Simplifing Detect decorator. Added more documentation. (#20)
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 --------- 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. --------- Co-authored-by: Preetam Joshi <preetam@aimon.ai>
- Loading branch information
Showing
10 changed files
with
181 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,8 @@ lib64 | |
# Installer logs | ||
pip-log.txt | ||
|
||
.streamlit/* | ||
.streamlit | ||
.streamlit/ | ||
.metaflow | ||
.metaflow/ | ||
.ipynb_checkpoints |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# AIMon Chatbot Demo | ||
|
||
This is a simple chatbot demo that uses AIMon to check responses to user queries. | ||
The chatbot is built using LLamaIndex. This chatbot application intentionally crawls a [single webpage](http://paulgraham.com/worked.html). | ||
This way we can demonstrate how AIMon's hallucination detector works when the chatbot is asked questions that are not | ||
related to the webpage, in which case it is likely to answer out of its own learned knowledge. | ||
|
||
## Setup | ||
|
||
### 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 | ||
aimon_api_key=YOUR_AIMON_API | ||
``` | ||
|
||
### Running the Chatbot | ||
|
||
The chatbot is a streamlit app. You can run it using this command: | ||
|
||
```bash | ||
streamlit run chatbot.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
2 changes: 2 additions & 0 deletions
2
examples/requirements_chatbot.txt → examples/chatbot/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,4 +1,6 @@ | ||
llama-index | ||
llama-index-readers-web | ||
streamlit | ||
openai | ||
aimon | ||
|
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,34 @@ | ||
# AIMon Metaflow Demo | ||
|
||
This is a simple Metaflow flow that generates a summary of an input document. | ||
It uses AIMon to check the quality of the generated summary. | ||
The summarizer is built using Langchain. | ||
|
||
## Setup | ||
|
||
### 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 as part of their respective environment variables. | ||
|
||
```bash | ||
export OPENAI_KEY=YOUR_OPENAI_API | ||
export AIMON_API_KEY=YOUR_AIMON_API | ||
``` | ||
|
||
### Running the flow | ||
|
||
The flow can be run using the following command: | ||
|
||
```bash | ||
python summarization_flow.py run | ||
``` | ||
|
||
|
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,6 @@ | ||
langchain | ||
langchain-community | ||
metaflow | ||
aimon | ||
openai | ||
|
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,60 @@ | ||
from metaflow import FlowSpec, step | ||
from langchain_community.llms import OpenAI | ||
from langchain.text_splitter import CharacterTextSplitter | ||
from langchain.docstore.document import Document | ||
from langchain.chains.summarize import load_summarize_chain | ||
from aimon import Detect | ||
import os | ||
|
||
detect = Detect(values_returned=['context', 'generated_text'], config={"hallucination": {"detector_name": "default"}}) | ||
|
||
class SummarizeFlow(FlowSpec): | ||
|
||
@step | ||
def start(self): | ||
# Load your document here | ||
self.document = """ | ||
Your document text goes here. Replace this text with the actual content you want to summarize. | ||
""" | ||
|
||
context, summary, aimon_res = self.summarize(self.document) | ||
|
||
# Print the summary | ||
print("Summary:") | ||
print(summary) | ||
|
||
|
||
# Print the AIMon result | ||
print("AIMon hallucination detection:") | ||
print(aimon_res.hallucination) | ||
|
||
self.next(self.end) | ||
|
||
@detect | ||
def summarize(self, context): | ||
# Split the source text | ||
text_splitter = CharacterTextSplitter() | ||
texts = text_splitter.split_text(context) | ||
|
||
# Create Document objects for the texts | ||
docs = [Document(page_content=t) for t in texts[:3]] | ||
|
||
openai_key = os.getenv("OPENAI_KEY") | ||
|
||
|
||
# Initialize the OpenAI model | ||
llm = OpenAI(temperature=0, api_key=openai_key) | ||
|
||
# Create the summarization chain | ||
summarize_chain = load_summarize_chain(llm) | ||
|
||
# Summarize the document | ||
return context, summarize_chain.run(docs) | ||
|
||
@step | ||
def end(self): | ||
print("Flow completed.") | ||
|
||
if __name__ == "__main__": | ||
SummarizeFlow() | ||
|
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