Skip to content

Commit

Permalink
remove some testing loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Zhou authored and Lu Zhou committed Jul 17, 2024
1 parent a636417 commit cc0a9ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
15 changes: 6 additions & 9 deletions copilot/app/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
db_connection: TigerGraphConnectionProxy,
embedding_model: EmbeddingModel,
embedding_store: EmbeddingStore,
# use_cypher: bool = False,
use_cypher: bool = False,
ws=None,
supportai_retriever="hnsw_overlap"
):
Expand All @@ -74,9 +74,9 @@ def __init__(
embedding_store,
)

# self.cypher_tool = None
# if use_cypher:
# self.cypher_tool = GenerateCypher(self.conn, self.llm)
self.cypher_tool = None
if use_cypher:
self.cypher_tool = GenerateCypher(self.conn, self.llm)

self.q = None
if ws is not None:
Expand All @@ -91,7 +91,7 @@ def __init__(
self.embedding_store,
self.mq2s,
self.gen_func,
# cypher_gen_tool=self.cypher_tool,
cypher_gen_tool=self.cypher_tool,
q=self.q,
supportai_retriever=supportai_retriever
).create_graph()
Expand Down Expand Up @@ -120,7 +120,6 @@ def question_for_agent(

input_data = {}
input_data["input"] = question
# logger.info(f"conversation: {conversation}")

if conversation is not None:
input_data["conversation"] = [
Expand All @@ -131,7 +130,6 @@ def question_for_agent(
else:
# Handle the case where conversation is None or empty
input_data["conversation"] = []
# logger.info(f"input_data: {input_data}")

# Validate and convert input_data to JSON string
try:
Expand All @@ -140,7 +138,6 @@ def question_for_agent(
logger.error(f"Failed to serialize input_data to JSON: {e}")
raise ValueError("Invalid input data format. Unable to convert to JSON.")

# for output in self.agent.stream({"question": input_data_str}):
for output in self.agent.stream({"question": input_data["input"], "conversation": input_data["conversation"]}):

for key, value in output.items():
Expand Down Expand Up @@ -205,7 +202,7 @@ def make_agent(graphname, conn, use_cypher, ws: WebSocket = None, supportai_retr
conn,
embedding_service,
embedding_store,
# use_cypher=use_cypher,
use_cypher=use_cypher,
ws=ws,
supportai_retriever=supportai_retriever
)
Expand Down
10 changes: 5 additions & 5 deletions copilot/app/agent/agent_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ def generate_answer(self, state):
logger.error(f"Failed to serialize context to JSON: {e}")
raise ValueError("Invalid context data format. Unable to convert to JSON.")

# answer = step.generate_answer(state["question"], state["context"]["result"])
answer = step.generate_answer(state["question"], context_data_str)
# answer = step.generate_answer(question, context_data_str)

elif state["lookup_source"] == "cypher":
answer = step.generate_answer(state["question"], state["context"]["answer"])
Expand Down Expand Up @@ -348,11 +346,11 @@ def rewrite_question(self, state):
"""
self.emit_progress("Rephrasing the question")
step = TigerGraphAgentRewriter(self.llm_provider)
# logger.info(f"question for rewrite: {state['question']}")
question_str = state["question"]
state["question"] = step.rewrite_question(question_str)
return state

# remove halucinaton check, always return grounded
def check_answer_for_hallucinations(self, state):
"""
Run the agent hallucination check.
Expand Down Expand Up @@ -380,6 +378,7 @@ def check_answer_for_hallucinations(self, state):
# return "hallucination"
return "grounded"

# remove usefulness check, always return useful
def check_answer_for_usefulness(self, state):
"""
Run the agent usefulness check.
Expand All @@ -404,12 +403,10 @@ def check_answer_for_usefulness_and_hallucinations(self, state):
Run the agent usefulness and hallucination check.
"""
hallucinated = self.check_answer_for_hallucinations(state)
logger.info(f"hallucinated: {hallucinated}")
if hallucinated == "hallucination":
return "hallucination"
else:
useful = self.check_answer_for_usefulness(state)
logger.info(f"useful: {useful}")
if useful == "useful":
self.emit_progress(DONE)
return "grounded"
Expand Down Expand Up @@ -462,6 +459,7 @@ def create_graph(self):
self.check_state_for_generation_error,
{"error": "apologize", "success": "generate_answer"},
)
# remove hallucination and usefulness check
# if self.supportai_enabled:
# self.workflow.add_conditional_edges(
# "generate_answer",
Expand Down Expand Up @@ -495,6 +493,7 @@ def create_graph(self):
if self.supportai_enabled:
self.workflow.add_conditional_edges(
"generate_answer",
# alwasy return grounded
self.check_answer_for_usefulness_and_hallucinations,
{
"hallucination": "rewrite_question",
Expand All @@ -507,6 +506,7 @@ def create_graph(self):
else:
self.workflow.add_conditional_edges(
"generate_answer",
# always return grounded
self.check_answer_for_usefulness_and_hallucinations,
{
"hallucination": "rewrite_question",
Expand Down

0 comments on commit cc0a9ba

Please sign in to comment.