Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gml 1824 regression test with cypher support and no hallucination and usefulness check #248

Merged
merged 49 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
19c51f2
select llm
RobRossmiller-TG Jun 26, 2024
762073a
Merge pull request #222 from tigergraph/llm-by-graphname
RobRossmiller-TG Jun 26, 2024
37607e4
page title and favicon
RobRossmiller-TG Jun 26, 2024
bde5495
login to dialog and remove animation
RobRossmiller-TG Jun 26, 2024
b1ae116
add graph selector to all views
RobRossmiller-TG Jun 26, 2024
5df8c5d
questions based on graph name
RobRossmiller-TG Jun 26, 2024
15f6d26
start questions by graphname fix
RobRossmiller-TG Jun 26, 2024
98b1ca2
Update Start.tsx
RobRossmiller-TG Jun 26, 2024
8d4a14d
Merge pull request #223 from tigergraph/GML-1793-ui-dialog
RobRossmiller-TG Jun 26, 2024
73f747d
fix(ui): handle disconnect websocket
billshitg Jun 26, 2024
1ef9edf
fix(Bot): remove workgroup selector
billshitg Jun 26, 2024
1bbafd4
fix(SideMenu): remove the section from tgcloud
billshitg Jun 26, 2024
c967fd4
url sources as links
RobRossmiller-TG Jun 26, 2024
f617e36
GML-1796 dependency cycle detecte
Jun 26, 2024
acca996
Merge pull request #224 from tigergraph/minor-ui-fixes
RobRossmiller-TG Jun 26, 2024
476f7e2
Merge pull request #225 from tigergraph/GML-1795-explain_urls
RobRossmiller-TG Jun 26, 2024
7625adb
Merge pull request #226 from tigergraph/GML-1796-fix-dependency-cycle…
luzhoutg Jun 26, 2024
5a511c5
fix(agent_graph): "error" key not found error
billshitg Jun 27, 2024
3f216ba
feat(copilot-ui): add markdown
billshitg Jun 27, 2024
7e1604d
fix(nginx): fix proxy for chat-dialog
billshitg Jun 27, 2024
7cde6ba
fix(agent_graph): fix error check in state
billshitg Jun 27, 2024
891e20a
fix(Login): revert back to /chat after login
billshitg Jun 27, 2024
7a5061e
Merge pull request #228 from tigergraph/render-markdown
billshitg Jun 27, 2024
82fc405
[GML-1779-show-response-as-table-or-graph] Knowledge graph/table imp…
neotericmedia Jun 28, 2024
23fcb8f
condition tweak for table vis (#230)
neotericmedia Jun 28, 2024
d5b9445
Demo cleanup & styling tweaks (#231)
neotericmedia Jun 28, 2024
fc1ec3b
Demo - Caret/typewriter animation edit (#232)
neotericmedia Jun 28, 2024
2e2c801
Merge branch 'dev' into GML-1798-debug-the-issue-of-returning-wrong-n…
Jul 1, 2024
25c3fac
Merge branch 'dev' into GML-1798-debug-the-issue-of-returning-wrong-n…
Jul 11, 2024
fe5c156
GML-1798 fix/inconsistent-answer
Jul 11, 2024
d1730b3
Merge branch 'dev' into GML-1798-debug-the-issue-of-returning-wrong-n…
Jul 12, 2024
aade42f
GML-1798 fix/remove cypher and usefullness
Jul 12, 2024
9f01ff0
GML-1798 fix/seperate question and conversation
Jul 12, 2024
0ec4d73
GML-1798 fix: pass one the question to usefulness
Jul 12, 2024
3654479
GML-1798 remove testing logs
Jul 12, 2024
4d0d975
GML-1798 change prompts for all LLM models
Jul 12, 2024
00e0a94
GML-1798 changed prompt of hallucination and usefulness
Jul 12, 2024
5b9af2c
GML-1822 remove hallucination and usefullness check and cypher suppor…
Jul 13, 2024
e21fd6a
GML-1824 regression test with cypher only without halluciation and us…
Jul 15, 2024
a636417
Merge branch 'dev' into GML-1824-regression-test-with-out-cypher-supp…
Jul 17, 2024
cc0a9ba
remove some testing loggers
Jul 17, 2024
a609fe7
restore
Jul 17, 2024
2cbef47
remove cypher
Jul 17, 2024
0cdb1c9
remove cypher
Jul 17, 2024
da3cdbb
add cypher back optionally it generate function fails
Jul 17, 2024
21e2876
remove hardcoded llm provide for graphs
Jul 17, 2024
3f29937
restore cypher
Jul 18, 2024
bd35e71
remove testing log
Jul 18, 2024
7061aef
GML-1824 modify the prompt to make sure always generate count found w…
Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/prompts/aws_bedrock_claude3haiku/generate_function.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs below to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.
Vertex Types: {vertex_types}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Don't generate target_vertex_ids if there is no the term 'id' explicitly mention

Respond in JSON (and only JSON). Follow the format instructions below:
{format_instructions}
QUESTION: {question}
question: {question}
conversation: {conversation}
3 changes: 2 additions & 1 deletion common/prompts/aws_bedrock_titan/generate_function.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.
Vertex Types: {vertices}
Expand Down
3 changes: 2 additions & 1 deletion common/prompts/aws_bedrock_titan/map_question_to_schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Response: What is the schema?
Example: How many transactions are there?
Response: How many TRANSACTION Edges are there?
{format_instructions}
QUESTION: {question}
question: {question}
conversation: {conversation}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs below to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Generate the complete question with the appropriate replacements. Keep the case
Format your response following the directions below.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

{format_instructions}
{format_instructions}
question: {question}
conversation: {conversation}
4 changes: 2 additions & 2 deletions common/prompts/gcp_vertexai_palm/generate_function.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs below to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

Expand Down
3 changes: 2 additions & 1 deletion common/prompts/gcp_vertexai_palm/map_question_to_schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Generate the complete question with the appropriate replacements. Keep the case
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

{format_instructions}
QUESTION: {question}
question: {question}
conversation: {conversation}
4 changes: 2 additions & 2 deletions common/prompts/llama_70b/generate_function.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs below to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.
Vertex Types: {vertex_types}
Expand Down
4 changes: 3 additions & 1 deletion common/prompts/llama_70b/map_question_to_schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ Generate the complete question with the appropriate replacements. Keep the case
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

{format_instructions}
QUESTION: {question}
question: {question}
conversation: {conversation}

4 changes: 2 additions & 2 deletions common/prompts/openai_gpt4/generate_function.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Use the vertex types, edge types, and their attributes and IDs below to write the pyTigerGraph function call to answer the question using a pyTigerGraph connection.
When the question asks for "How many", make sure to select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When the question asks for "How many", make sure to always select a function that contains "Count" in the description/function call. Make sure never to generate a function that is not listed below.
When certain entities are mapped to vertex attributes, may consider to generate a WHERE clause.
If a WHERE clause is generated, please follow the instruction with proper quoting. To construct a WHERE clause string. Ensure that string attribute values are properly quoted.
For example, if the generated function is "conn.getVertices('Person', where='name=William Torres')", Expected Output: "conn.getVertices('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
For example, if the generated function contains "('Person', where='name=William Torres')", Expected Output: "('Person', where='name="William Torres"')", This rule applies to all types of attributes. e.g., name, email, address and so on.
Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute.
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.
Vertex Types: {vertex_types}
Expand Down
3 changes: 2 additions & 1 deletion common/prompts/openai_gpt4/map_question_to_schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Generate the complete question with the appropriate replacements. Keep the case
Don't generate target_vertex_ids if there is no the term 'id' explicitly mentioned in the question.

{format_instructions}
QUESTION: {question}
question: {question}
conversation: {conversation}

15 changes: 12 additions & 3 deletions copilot/app/agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import json
import time
from typing import Dict, List

Expand Down Expand Up @@ -119,20 +120,28 @@ def question_for_agent(

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

if conversation is not None:
input_data["conversation"] = [
{"query": chat["query"], "response": chat["response"]}
for chat in conversation
]

else:
# Handle the case where conversation is None or empty
input_data["conversation"] = []
logger.info(f"input_data: {input_data}")

for output in self.agent.stream({"question": str(input_data)}):
# Validate and convert input_data to JSON string
try:
input_data_str = json.dumps(input_data)
except (TypeError, ValueError) as e:
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["input"], "conversation": input_data["conversation"]}):

for key, value in output.items():
logger.info(f"testing steps {key}: {value}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this line. Do we need to log all the questions and generated answer?

Copy link
Contributor Author

@luzhoutg luzhoutg Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can comment it out. It was trying to understand which step went wrong during testing. I will remove it in next PR.

LogWriter.info(f"request_id={req_id_cv.get()} executed node {key}")

LogWriter.info(f"request_id={req_id_cv.get()} EXIT question_for_agent")
Expand Down
20 changes: 14 additions & 6 deletions copilot/app/agent/agent_generation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import logging
from langchain.prompts import PromptTemplate
from langchain_core.output_parsers import PydanticOutputParser
Expand All @@ -9,7 +8,7 @@
logger = logging.getLogger(__name__)

class CoPilotAnswerOutput(BaseModel):
generated_answer: str = Field(description="The generated answer to the question. Make sure maintain a professional tone and keep the answer consice.")
generated_answer: str = Field(description="The generated answer to the question. Make sure maintain a professional tone.")
citation: list[str] = Field(description="The citation for the answer. List the information used.")

class TigerGraphAgentGenerator:
Expand All @@ -29,19 +28,28 @@ def generate_answer(self, question: str, context: str) -> str:
answer_parser = PydanticOutputParser(pydantic_object=CoPilotAnswerOutput)

prompt = PromptTemplate(
template="""Given the question and the context, generate an answer. \n
Make sure to answer the question in a friendly and informative way. \n
template="""Given the answer context in JSON format, rephrase it to answer the question. \n
Use only the provided information in context without adding any reasoning or additional logic. \n
Make sure all information in the answer are covered in the generated answer.\n
Question: {question} \n
Context: {context}
Answer: {context} \n
Format: {format_instructions}""",
input_variables=["question", "context"],
partial_variables={
"format_instructions": answer_parser.get_format_instructions()
}
)

full_prompt = prompt.format(
question=question,
context=context,
format_instructions=answer_parser.get_format_instructions()
)

# Chain
rag_chain = prompt | self.llm.model | answer_parser
generation = rag_chain.invoke({"context": context, "question": question})
generation = rag_chain.invoke({"question": question, "context": context})

LogWriter.info(f"request_id={req_id_cv.get()} EXIT generate_answer")

return generation
Loading
Loading