From 268335fe3eb339ae85689329abae07a5a0dd78f7 Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 10:52:53 -0600 Subject: [PATCH 1/6] feat(prompts): update gpt4 prompts --- app/schemas/schemas.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/schemas/schemas.py b/app/schemas/schemas.py index 38b40b06..c4ca0f6e 100644 --- a/app/schemas/schemas.py +++ b/app/schemas/schemas.py @@ -3,6 +3,7 @@ class NaturalLanguageQuery(BaseModel): query:str + chat_history:List[Tuple] = None class GSQLQueryInfo(BaseModel): function_header: str From d95521327aef2d228b49ea1cdefc095c2fba0519 Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 10:53:16 -0600 Subject: [PATCH 2/6] feat(prompts): gpt4 prompts --- .../generate_function.txt | 6 ++---- .../map_question_to_schema.txt | 8 +++++--- 2 files changed, 7 insertions(+), 7 deletions(-) rename app/prompts/{open_ai_davinci-003 => openai_gpt4}/generate_function.txt (58%) rename app/prompts/{open_ai_davinci-003 => openai_gpt4}/map_question_to_schema.txt (61%) diff --git a/app/prompts/open_ai_davinci-003/generate_function.txt b/app/prompts/openai_gpt4/generate_function.txt similarity index 58% rename from app/prompts/open_ai_davinci-003/generate_function.txt rename to app/prompts/openai_gpt4/generate_function.txt index 1651fd71..34af47d3 100644 --- a/app/prompts/open_ai_davinci-003/generate_function.txt +++ b/app/prompts/openai_gpt4/generate_function.txt @@ -1,8 +1,5 @@ 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. -YOU ARE INTERACTING WITH A LABELED PROPERTY GRAPH DATABSE THROUGH PYTHON FUNCTION CALLS, WHERE VERTICES AND EDGES HAVE UNIQUE TYPES AND ATTRIBUTES. -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. Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute. -ONLY WRITE THE FUNCTION CALL, without `conn` in front of it. Vertex Types: {vertex_types} Vertex Attributes: {vertex_attributes} Vertex IDs: {vertex_ids} @@ -12,4 +9,5 @@ Question: {question} First Docstring: {doc1} Second Docstring: {doc2} Third Docstring: {doc3} -Python Call: conn. \ No newline at end of file + +Given a pyTigerGraph TigerGraphConnection object named `conn`, what would be the Python function to answer the question? Only answer with the function call. \ No newline at end of file diff --git a/app/prompts/open_ai_davinci-003/map_question_to_schema.txt b/app/prompts/openai_gpt4/map_question_to_schema.txt similarity index 61% rename from app/prompts/open_ai_davinci-003/map_question_to_schema.txt rename to app/prompts/openai_gpt4/map_question_to_schema.txt index e4b2f020..3d489bee 100644 --- a/app/prompts/open_ai_davinci-003/map_question_to_schema.txt +++ b/app/prompts/openai_gpt4/map_question_to_schema.txt @@ -1,6 +1,8 @@ +You are mapping a question from a user to entities represented in a graph database. +The question is: {question} Replace the entites mentioned in the question to one of these choices: {vertices}. Replace the relationships mentioned in the question to one of these choices: {edges}. If there are words that are synonyms with the entities or relationships above, make sure to output the cannonical form found in the choices above. -Generate the complete question with the appropriate replacements. Keep the case of the schema elements the same. -{format_instructions} -QUESTION: {question} +Generate the complete question with the appropriate replacements. Keep the case of the schema elements the same. Format your response following the directions below. + +{format_instructions} \ No newline at end of file From 6d681b6a8189aca3224d940cedd5efeba1cce094 Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 11:40:42 -0600 Subject: [PATCH 3/6] fix(pr): remove addition from other branch --- app/schemas/schemas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/schemas/schemas.py b/app/schemas/schemas.py index c4ca0f6e..38b40b06 100644 --- a/app/schemas/schemas.py +++ b/app/schemas/schemas.py @@ -3,7 +3,6 @@ class NaturalLanguageQuery(BaseModel): query:str - chat_history:List[Tuple] = None class GSQLQueryInfo(BaseModel): function_header: str From 94aef098fc458b9fcac38f644cb4605933726580 Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 13:51:14 -0600 Subject: [PATCH 4/6] feat(prompt): clarify generate function prompt for gpt4 --- app/prompts/openai_gpt4/generate_function.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/prompts/openai_gpt4/generate_function.txt b/app/prompts/openai_gpt4/generate_function.txt index 34af47d3..417d0ecd 100644 --- a/app/prompts/openai_gpt4/generate_function.txt +++ b/app/prompts/openai_gpt4/generate_function.txt @@ -10,4 +10,6 @@ First Docstring: {doc1} Second Docstring: {doc2} Third Docstring: {doc3} -Given a pyTigerGraph TigerGraphConnection object named `conn`, what would be the Python function to answer the question? Only answer with the function call. \ No newline at end of file +Given a pyTigerGraph TigerGraphConnection object named `conn`, what would be the Python function to answer the question? Only complete the function call below: + +conn. \ No newline at end of file From 6824c57b0c94899a494324605c7a958fb669f13b Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 13:55:19 -0600 Subject: [PATCH 5/6] feat(prompt): add clarifying graph prompt --- app/prompts/openai_gpt4/generate_function.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/prompts/openai_gpt4/generate_function.txt b/app/prompts/openai_gpt4/generate_function.txt index 417d0ecd..10b00315 100644 --- a/app/prompts/openai_gpt4/generate_function.txt +++ b/app/prompts/openai_gpt4/generate_function.txt @@ -1,4 +1,5 @@ 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. +You are interacting with a graph database that contains edges and vertices, and some functions may traverse between vertices or count edges based upon vertex filters. Documentation contains helpful Python docstrings for the various functions. Use this knowledge to construct the proper function call. Choose one function to execute. Vertex Types: {vertex_types} Vertex Attributes: {vertex_attributes} From 53f1eba5546eeb011c2acb00332ee38c48af6b71 Mon Sep 17 00:00:00 2001 From: Parker Erickson Date: Wed, 24 Jan 2024 14:42:40 -0600 Subject: [PATCH 6/6] fix(response size): limit response size to 4 MB. --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index be8edc68..5e6c9c2d 100644 --- a/app/main.py +++ b/app/main.py @@ -115,7 +115,7 @@ def retrieve_answer(graphname, query: NaturalLanguageQuery, credentials: Annotat apiToken = apiToken ) - conn.customizeHeader(timeout=config["default_timeout"]*1000, responseSize=50000000) + conn.customizeHeader(timeout=config["default_timeout"]*1000, responseSize=5000000) logger.debug(f"/{graphname}/query request_id={req_id_cv.get()} database connection created") if llm_config["completion_service"]["llm_service"].lower() == "openai":