From 94d598b59c95566b9ed1bb87410840ad40d87bb6 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 7 Jul 2023 18:22:59 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(test=5Fendpoints.py):=20fix?= =?UTF-8?q?=20import=20statement=20for=20TimeTravelGuideChainNode=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(test=5Fendpoints.py):=20update=20test=5Fget?= =?UTF-8?q?=5Fall=20to=20assert=20"PromptTemplate"=20instead=20of=20"ZeroS?= =?UTF-8?q?hotPrompt"=20=F0=9F=94=A7=20fix(test=5Fendpoints.py):=20update?= =?UTF-8?q?=20test=5Fvalid=5Fprompt=20and=20test=5Finvalid=5Fprompt=20to?= =?UTF-8?q?=20use=20PROMPT=5FREQUEST=20variable=20=F0=9F=94=A7=20fix(test?= =?UTF-8?q?=5Fendpoints.py):=20update=20test=5Fvarious=5Fprompts=20to=20us?= =?UTF-8?q?e=20PROMPT=5FREQUEST=20variable=20=F0=9F=94=A7=20fix(test=5Fpro?= =?UTF-8?q?mpts=5Ftemplate.py):=20remove=20test=5Fzero=5Fshot=5Fprompt=20a?= =?UTF-8?q?s=20it=20is=20no=20longer=20needed=20The=20import=20statement?= =?UTF-8?q?=20for=20TimeTravelGuideChainNode=20is=20fixed=20to=20ensure=20?= =?UTF-8?q?the=20correct=20module=20is=20imported.=20The=20test=5Fget=5Fal?= =?UTF-8?q?l=20function=20is=20updated=20to=20assert=20the=20presence=20of?= =?UTF-8?q?=20"PromptTemplate"=20instead=20of=20"ZeroShotPrompt"=20in=20th?= =?UTF-8?q?e=20response.=20The=20test=5Fvalid=5Fprompt,=20test=5Finvalid?= =?UTF-8?q?=5Fprompt,=20and=20test=5Fvarious=5Fprompts=20functions=20are?= =?UTF-8?q?=20updated=20to=20use=20the=20PROMPT=5FREQUEST=20variable=20for?= =?UTF-8?q?=20the=20request=20payload.=20The=20test=5Fzero=5Fshot=5Fprompt?= =?UTF-8?q?=20function=20is=20removed=20as=20it=20is=20no=20longer=20neede?= =?UTF-8?q?d.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_endpoints.py | 103 ++++++++++++++++++++++++++++++--- tests/test_prompts_template.py | 48 --------------- 2 files changed, 94 insertions(+), 57 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 9e07dfb24..045af1ba5 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -1,6 +1,86 @@ import pytest from fastapi.testclient import TestClient from langflow.interface.tools.constants import CUSTOM_TOOLS +from langflow.template.frontend_node.chains import TimeTravelGuideChainNode + + +PROMPT_REQUEST = { + "name": "string", + "template": "string", + "frontend_node": { + "template": {}, + "description": "string", + "base_classes": ["string"], + "name": "", + "display_name": "", + "documentation": "", + "custom_fields": {}, + "output_types": [], + "field_formatters": { + "formatters": {"openai_api_key": {}}, + "base_formatters": { + "kwargs": {}, + "optional": {}, + "list": {}, + "dict": {}, + "union": {}, + "multiline": {}, + "show": {}, + "password": {}, + "default": {}, + "headers": {}, + "dict_code_file": {}, + "model_fields": { + "MODEL_DICT": { + "OpenAI": [ + "text-davinci-003", + "text-davinci-002", + "text-curie-001", + "text-babbage-001", + "text-ada-001", + ], + "ChatOpenAI": [ + "gpt-3.5-turbo-0613", + "gpt-3.5-turbo", + "gpt-3.5-turbo-16k-0613", + "gpt-3.5-turbo-16k", + "gpt-4-0613", + "gpt-4-32k-0613", + "gpt-4", + "gpt-4-32k", + ], + "Anthropic": [ + "claude-v1", + "claude-v1-100k", + "claude-instant-v1", + "claude-instant-v1-100k", + "claude-v1.3", + "claude-v1.3-100k", + "claude-v1.2", + "claude-v1.0", + "claude-instant-v1.1", + "claude-instant-v1.1-100k", + "claude-instant-v1.0", + ], + "ChatAnthropic": [ + "claude-v1", + "claude-v1-100k", + "claude-instant-v1", + "claude-instant-v1-100k", + "claude-v1.3", + "claude-v1.3-100k", + "claude-v1.2", + "claude-v1.0", + "claude-instant-v1.1", + "claude-instant-v1.1-100k", + "claude-instant-v1.0", + ], + } + }, + }, + }, + }, +} def test_get_all(client: TestClient): @@ -8,7 +88,7 @@ def test_get_all(client: TestClient): assert response.status_code == 200 json_response = response.json() # We need to test the custom nodes - assert "ZeroShotPrompt" in json_response["prompts"] + assert "PromptTemplate" in json_response["prompts"] # All CUSTOM_TOOLS(dict) should be in the response assert all(tool in json_response["tools"] for tool in CUSTOM_TOOLS.keys()) @@ -95,15 +175,20 @@ INVALID_PROMPT = "This is an invalid prompt without any input variable." def test_valid_prompt(client: TestClient): - response = client.post("api/v1/validate/prompt", json={"template": VALID_PROMPT}) + PROMPT_REQUEST["template"] = VALID_PROMPT + response = client.post("api/v1/validate/prompt", json=PROMPT_REQUEST) assert response.status_code == 200 - assert response.json() == {"input_variables": ["product"]} + assert response.json()["input_variables"] == ["product"] def test_invalid_prompt(client: TestClient): - response = client.post("api/v1/validate/prompt", json={"template": INVALID_PROMPT}) + PROMPT_REQUEST["template"] = INVALID_PROMPT + response = client.post( + "api/v1/validate/prompt", + json=PROMPT_REQUEST, + ) assert response.status_code == 200 - assert response.json() == {"input_variables": []} + assert response.json()["input_variables"] == [] @pytest.mark.parametrize( @@ -116,8 +201,8 @@ def test_invalid_prompt(client: TestClient): ], ) def test_various_prompts(client, prompt, expected_input_variables): - response = client.post("api/v1/validate/prompt", json={"template": prompt}) + TimeTravelGuideChainNode().to_dict() + PROMPT_REQUEST["template"] = prompt + response = client.post("api/v1/validate/prompt", json=PROMPT_REQUEST) assert response.status_code == 200 - assert response.json() == { - "input_variables": expected_input_variables, - } + assert response.json()["input_variables"] == expected_input_variables diff --git a/tests/test_prompts_template.py b/tests/test_prompts_template.py index 4e6030cab..5486f3034 100644 --- a/tests/test_prompts_template.py +++ b/tests/test_prompts_template.py @@ -92,51 +92,3 @@ def test_prompt_template(client: TestClient): "advanced": False, "info": "", } - - -def test_zero_shot_prompt(client: TestClient): - response = client.get("api/v1/all") - assert response.status_code == 200 - json_response = response.json() - prompts = json_response["prompts"] - prompt = prompts["ZeroShotPrompt"] - template = prompt["template"] - assert template["prefix"] == { - "required": False, - "placeholder": "", - "show": True, - "multiline": True, - "value": "Answer the following questions as best you can. You have access to the following tools:", # noqa: E501 - "password": False, - "name": "prefix", - "type": "prompt", - "list": False, - "advanced": False, - "info": "", - } - assert template["suffix"] == { - "required": True, - "placeholder": "", - "show": True, - "multiline": True, - "value": "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}", - "password": False, - "name": "suffix", - "type": "prompt", - "list": False, - "advanced": False, - "info": "", - } - assert template["format_instructions"] == { - "required": True, - "placeholder": "", - "show": True, - "multiline": True, - "value": "Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question", # noqa: E501 - "password": False, - "name": "format_instructions", - "type": "prompt", - "list": False, - "advanced": False, - "info": "", - }