abdoh-alkhateeb commited on
Commit
fbeb50a
1 Parent(s): fe128cb

Create accountability_agent.py

Browse files
Files changed (1) hide show
  1. accountability_agent.py +22 -0
accountability_agent.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.callbacks import get_openai_callback
2
+ from langchain_core.prompts import PromptTemplate
3
+ from langchain_openai import ChatOpenAI
4
+
5
+
6
+ class AccountabilityAgent:
7
+ def __init__(self, prompt_template_path) -> None:
8
+ self._llm = ChatOpenAI(model="gpt-4-1106-preview", temperature=0.3)
9
+
10
+ with open(prompt_template_path) as f:
11
+ self._prompt = PromptTemplate(input_variables=["query", "synthesis"], template=f.read().strip())
12
+
13
+ self._chain = self._prompt | self._llm
14
+
15
+ def run(self, query: str, cynthesis: str):
16
+ with get_openai_callback() as cb:
17
+ accountability = self._chain.invoke({"query": query, "synthesis": cynthesis}).content.strip()
18
+
19
+ tokens = cb.total_tokens
20
+ cost = cb.total_cost
21
+
22
+ return {"tokens": tokens, "cost": cost}, accountability