Skip to content

Commit a39128d

Browse files
Bat ai/log analysis (#275)
* log_analysis using self corrective RAG * updated to ChatNVIDIA * removed chatopenai * updated with the minor changes * minor changes * minor changes readme * minor fixes * minor changes in readme * updated readme
1 parent df391f7 commit a39128d

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_KEY = ADD_YOUR_API_KEY

community/log_analysis_multi_agent_rag/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ We are calling this tool as BAT.AI (Bug Automation Tool)
88
# Target Audience
99
Devlopers : This tool is designed for developers who need to quickly analyze log files and gain actionable insights using large language model (LLM). The system automatically refines prompts to ensure optimal results, offering developers an intuitive way to interact with log data and streamline their debugging process.
1010

11+
# How to Use
12+
13+
This repository provides a sample code to demonstrate how you can use the log analysis tool for your logs. Follow the instructions below to set up and integrate the tool into your workflow.
14+
15+
### Set up your API Key:
16+
17+
- **Generate your API key** by following the steps in the link below:
18+
[Click here to view the steps for generating an API Key](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#generate-an-api-key)
19+
20+
- **Store your API key** : You can securely store your API key by creating a `.env` file in the root directory of your project
21+
- **example.py** : The sample script showcases how to integrate log analysis into your workflow. It demonstrates how to pass your log data through the system, generate insights, and manage the output.
22+
1123
# Components
1224
- bat_ai.py: Defines the main workflow graph using LangGraph.
1325
- graphnodes.py: Contains the node implementations for the workflow graph.
1426
- multiagent.py: Implements the HybridRetriever class for document retrieval.
1527
- graphedges.py: Contains the implementation of the edges for decision making
1628
- binaryscroes.py: Contains the formatted output information
17-
- utils.py : It helps to implement the queries, retrieve relevant documents, grade their relevance, and generate responses using a multi-agent RAG system.
18-
- example.py: The script that analyzes a specified log file for errors based on a user-provided question, leveraging the workflow module to process and generate relevant insights.
29+
- utils.py : It helps to implement the queries, retrieve relevant documents, grade their relevance, and generate responses using a multi-agent RAG system.
30+
1931

2032
![SW Architecture](<BAT.AI SW Architecture Diagram.drawio.png>)
2133

@@ -30,8 +42,9 @@ Devlopers : This tool is designed for developers who need to quickly analyze log
3042
Set up the NVIDIA API key in your environment.
3143
Prepare your document corpus and update the file path in the code.
3244

45+
3346
# Code
34-
`python main.py path/to/your/logfile.txt --question "What are the critical errors in the log file?"`
47+
`python example.py path/to/your/logfile.txt --question "What are the critical errors in the log file?"`
3548

3649
# Software Components
3750
NVIDIA NIM Microservices

community/log_analysis_multi_agent_rag/graphnodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from langchain_nvidia_ai_endpoints import NVIDIARerank
2-
api_key = "<add your api key>"
2+
import os
33
from multiagent import HybridRetriever
44
import io
55
from contextlib import redirect_stdout, redirect_stderr
66
from utils import automation
7-
7+
from dotenv import load_dotenv
8+
load_dotenv()
9+
api_key = os.getenv('API_KEY')
810

911
class Nodes:
1012
@staticmethod

community/log_analysis_multi_agent_rag/multiagent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from langchain.retrievers import EnsembleRetriever
66
from langchain_community.retrievers import BM25Retriever
77
from langchain_community.vectorstores.faiss import FAISS
8-
import argparse
8+
from dotenv import load_dotenv
9+
load_dotenv()
10+
api_key = os.getenv('API_KEY')
911
class HybridRetriever:
1012
def __init__(self, file_path, api_key):
1113
self.file_path = file_path

community/log_analysis_multi_agent_rag/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from langchain_core.output_parsers import StrOutputParser
44
from binary_score_models import GradeAnswer,GradeDocuments,GradeHallucinations
55
import os
6-
6+
from dotenv import load_dotenv
7+
load_dotenv()
78
import json
89

910
class Nodeoutputs:
10-
def __init__(self, api_key, base_url, model, prompts_file):
11+
def __init__(self, api_key, model, prompts_file):
1112
os.environ["NVIDIA_API_KEY"] = api_key
12-
self.llm = ChatNVIDIA(base_url=base_url, api_key=api_key, model=model)
13+
self.llm = ChatNVIDIA( api_key=api_key, model=model)
1314
self.prompts = self.load_prompts(prompts_file)
1415
self.setup_prompts()
1516

@@ -62,8 +63,10 @@ def format_docs(self, docs):
6263
return "\n\n".join(doc.page_content for doc in docs)
6364

6465
# Usage
65-
api_key = "<addd your api key>"
66-
base_url = "<add your endpoint>"
66+
67+
68+
# Access the API key from environment variables
69+
api_key = os.getenv('API_KEY')
6770
model = "meta/llama-3.1-70b-instruct"
6871
prompts_file = "prompt.json"
69-
automation = Nodeoutputs(api_key, base_url, model, prompts_file)
72+
automation = Nodeoutputs(api_key, model, prompts_file)

0 commit comments

Comments
 (0)