-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
18 lines (15 loc) · 714 Bytes
/
Copy pathutils.py
File metadata and controls
18 lines (15 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import json
from langchain.llms import OpenAI
from langchain.chains import RetrievalQA
from langchain.document_loaders import JSONLoader
class AuditResponseGenerator:
def __init__(self, api_key):
self.llm = OpenAI(openai_api_key=api_key, temperature=0.3)
self.policy_db = "policy_database.json"
def load_policies(self):
loader = JSONLoader(file_path=self.policy_db, jq_schema='.policies[]')
return loader.load()
def generate_response(self, question):
docs = self.load_policies()
qa_chain = RetrievalQA.from_chain_type(self.llm, chain_type="stuff")
return qa_chain.run(question + " Answer professionally citing relevant controls.")