Merge branch 'dev' into vecstores

This commit is contained in:
Ibis Prevedello 2023-04-07 13:06:49 -03:00
commit 616dfd0370
22 changed files with 1890 additions and 128 deletions

View file

@ -0,0 +1,176 @@
from fastapi.testclient import TestClient
from langflow.settings import settings
# check that all agents are in settings.agents
# are in json_response["agents"]
def test_agents_settings(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
agents = json_response["agents"]
assert set(agents.keys()) == set(settings.agents)
def test_zero_shot_agent(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
agents = json_response["agents"]
zero_shot_agent = agents["ZeroShotAgent"]
assert set(zero_shot_agent["base_classes"]) == {
"ZeroShotAgent",
"BaseSingleActionAgent",
"Agent",
"function",
}
template = zero_shot_agent["template"]
assert template["llm_chain"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm_chain",
"type": "LLMChain",
"list": False,
}
assert template["allowed_tools"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "allowed_tools",
"type": "Tool",
"list": True,
}
def test_json_agent(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
agents = json_response["agents"]
json_agent = agents["JsonAgent"]
assert json_agent["base_classes"] == ["AgentExecutor"]
template = json_agent["template"]
assert template["toolkit"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "toolkit",
"type": "BaseToolkit",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
def test_csv_agent(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
agents = json_response["agents"]
csv_agent = agents["CSVAgent"]
assert csv_agent["base_classes"] == ["AgentExecutor"]
template = csv_agent["template"]
assert template["path"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"value": "",
"suffixes": [".csv"],
"fileTypes": ["csv"],
"password": False,
"name": "path",
"type": "file",
"list": False,
"content": None,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
def test_initialize_agent(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
agents = json_response["agents"]
initialize_agent = agents["initialize_agent"]
assert initialize_agent["base_classes"] == ["AgentExecutor"]
template = initialize_agent["template"]
assert template["agent"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"value": "zero-shot-react-description",
"password": False,
"options": [
"zero-shot-react-description",
"react-docstore",
"self-ask-with-search",
"conversational-react-description",
],
"name": "agent",
"type": "str",
"list": True,
}
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "memory",
"type": "BaseChatMemory",
"list": False,
}
assert template["tools"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "tools",
"type": "Tool",
"list": True,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}

View file

@ -0,0 +1,664 @@
from fastapi.testclient import TestClient
from langflow.settings import settings
def test_chains_settings(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
assert set(chains.keys()) == set(settings.chains)
# Test the ConversationChain object
def test_conversation_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["ConversationChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {"LLMChain", "ConversationChain", "Chain"}
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "input",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "response",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["_type"] == "ConversationChain"
# Test the description object
assert (
chain["description"]
== "Chain to have a conversation and load context from memory."
)
def test_llm_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["LLMChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {"LLMChain", "Chain"}
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "text",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
def test_llm_checker_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["LLMCheckerChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {"LLMCheckerChain", "Chain"}
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLLM",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "query",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "result",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["_type"] == "LLMCheckerChain"
# Test the description object
assert (
chain["description"] == "Chain for question-answering with self-verification."
)
def test_llm_math_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["LLMMathChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {"LLMMathChain", "Chain"}
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "question",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "answer",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["_type"] == "LLMMathChain"
# Test the description object
assert (
chain["description"]
== "Chain that interprets a prompt and executes python code to do math."
)
def test_series_character_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["SeriesCharacterChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {
"LLMChain",
"BaseCustomChain",
"Chain",
"ConversationChain",
"SeriesCharacterChain",
}
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": {
"chat_memory": {"messages": []},
"output_key": None,
"input_key": None,
"return_messages": False,
"human_prefix": "Human",
"ai_prefix": "AI",
"memory_key": "history",
},
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "input",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "response",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["template"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": True,
"value": "I want you to act like {character} from {series}.\nI want you to respond and answer like {character}. do not write any explanations. only answer like {character}.\nYou must know all of the knowledge of {character}.\nCurrent conversation:\n{history}\nHuman: {input}\n{character}:", # noqa: E501
"password": False,
"name": "template",
"type": "str",
"list": False,
}
assert template["ai_prefix_value"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "character",
"password": False,
"name": "ai_prefix_value",
"type": "str",
"list": False,
}
assert template["character"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "character",
"type": "str",
"list": False,
}
assert template["series"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "series",
"type": "str",
"list": False,
}
assert template["_type"] == "SeriesCharacterChain"
# Test the description object
assert (
chain["description"]
== "SeriesCharacterChain is a chain you can use to have a conversation with a character from a series."
)
def test_mid_journey_prompt_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["MidJourneyPromptChain"]
assert isinstance(chain, dict)
# Test the base_classes object
assert set(chain["base_classes"]) == {
"LLMChain",
"BaseCustomChain",
"Chain",
"ConversationChain",
"MidJourneyPromptChain",
}
# Test the template object
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": {
"chat_memory": {"messages": []},
"output_key": None,
"input_key": None,
"return_messages": False,
"human_prefix": "Human",
"ai_prefix": "AI",
"memory_key": "history",
},
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
# Continue with other template object assertions
assert template["prompt"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": {
"input_variables": ["history", "input"],
"output_parser": None,
"partial_variables": {},
"template": "The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:", # noqa: E501
"template_format": "f-string",
"validate_template": True,
"_type": "prompt",
},
"password": False,
"name": "prompt",
"type": "BasePromptTemplate",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "response",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "input",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["template"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": True,
"value": 'I want you to act as a prompt generator for Midjourney\'s artificial intelligence program.\n Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI.\n Keep in mind that the AI is capable of understanding a wide range of language and can interpret abstract concepts, so feel free to be as imaginative and descriptive as possible.\n For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures.\n The more detailed and imaginative your description, the more interesting the resulting image will be. Here is your first prompt:\n "A field of wildflowers stretches out as far as the eye can see, each one a different color and shape. In the distance, a massive tree towers over the landscape, its branches reaching up to the sky like tentacles."\n\n Current conversation:\n {history}\n Human: {input}\n AI:', # noqa: E501
"password": False,
"name": "template",
"type": "str",
"list": False,
}
assert template["ai_prefix_value"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "ai_prefix_value",
"type": "str",
"list": False,
}
# Test the description object
assert (
chain["description"]
== "MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts."
)
def test_time_travel_guide_chain(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
chains = json_response["chains"]
chain = chains["TimeTravelGuideChain"]
assert isinstance(chain, dict)
# Test the base_classes object
assert set(chain["base_classes"]) == {
"LLMChain",
"BaseCustomChain",
"TimeTravelGuideChain",
"Chain",
"ConversationChain",
}
# Test the template object
template = chain["template"]
assert template["memory"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": {
"chat_memory": {"messages": []},
"output_key": None,
"input_key": None,
"return_messages": False,
"human_prefix": "Human",
"ai_prefix": "AI",
"memory_key": "history",
},
"password": False,
"name": "memory",
"type": "BaseMemory",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["prompt"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": {
"input_variables": ["history", "input"],
"output_parser": None,
"partial_variables": {},
"template": "The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:", # noqa: E501
"template_format": "f-string",
"validate_template": True,
"_type": "prompt",
},
"password": False,
"name": "prompt",
"type": "BasePromptTemplate",
"list": False,
}
assert template["llm"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "llm",
"type": "BaseLanguageModel",
"list": False,
}
assert template["output_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "response",
"password": False,
"name": "output_key",
"type": "str",
"list": False,
}
assert template["input_key"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "input",
"password": False,
"name": "input_key",
"type": "str",
"list": False,
}
assert template["template"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": True,
"value": "I want you to act as my time travel guide. You are helpful and creative. I will provide you with the historical period or future time I want to visit and you will suggest the best events, sights, or people to experience. Provide the suggestions and any necessary information.\n Current conversation:\n {history}\n Human: {input}\n AI:", # noqa: E501
"password": False,
"name": "template",
"type": "str",
"list": False,
}
assert template["ai_prefix_value"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "ai_prefix_value",
"type": "str",
"list": False,
}
assert chain["description"] == ""

447
tests/test_llms_template.py Normal file
View file

@ -0,0 +1,447 @@
from fastapi.testclient import TestClient
from langflow.settings import settings
def test_llms_settings(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
llms = json_response["llms"]
assert set(llms.keys()) == set(settings.llms)
def test_hugging_face_hub(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
language_models = json_response["llms"]
model = language_models["HuggingFaceHub"]
template = model["template"]
assert template["cache"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "cache",
"type": "bool",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["client"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "client",
"type": "Any",
"list": False,
}
assert template["repo_id"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "gpt2",
"password": False,
"name": "repo_id",
"type": "str",
"list": False,
}
assert template["task"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "task",
"type": "str",
"list": False,
}
assert template["model_kwargs"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "model_kwargs",
"type": "code",
"list": False,
}
assert template["huggingfacehub_api_token"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": True,
"name": "huggingfacehub_api_token",
"type": "str",
"list": False,
}
def test_openai(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
language_models = json_response["llms"]
model = language_models["OpenAI"]
template = model["template"]
assert template["cache"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "cache",
"type": "bool",
"list": False,
}
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["client"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "client",
"type": "Any",
"list": False,
}
assert template["model_name"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": "text-davinci-003",
"password": False,
"options": [
"text-davinci-003",
"text-davinci-002",
"text-curie-001",
"text-babbage-001",
"text-ada-001",
],
"name": "model_name",
"type": "str",
"list": True,
}
# Add more assertions for other properties here
assert template["temperature"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": 0.7,
"password": False,
"name": "temperature",
"type": "float",
"list": False,
}
assert template["max_tokens"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": 256,
"password": True,
"name": "max_tokens",
"type": "int",
"list": False,
}
assert template["top_p"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 1,
"password": False,
"name": "top_p",
"type": "float",
"list": False,
}
assert template["frequency_penalty"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 0,
"password": False,
"name": "frequency_penalty",
"type": "float",
"list": False,
}
assert template["presence_penalty"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 0,
"password": False,
"name": "presence_penalty",
"type": "float",
"list": False,
}
assert template["n"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 1,
"password": False,
"name": "n",
"type": "int",
"list": False,
}
assert template["best_of"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 1,
"password": False,
"name": "best_of",
"type": "int",
"list": False,
}
assert template["model_kwargs"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "model_kwargs",
"type": "code",
"list": False,
}
assert template["openai_api_key"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"value": "",
"password": True,
"name": "openai_api_key",
"display_name": "OpenAI API Key",
"type": "str",
"list": False,
}
assert template["batch_size"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 20,
"password": False,
"name": "batch_size",
"type": "int",
"list": False,
}
assert template["request_timeout"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "request_timeout",
"type": "Union[float, Tuple[float, float], NoneType]",
"list": False,
}
assert template["logit_bias"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "logit_bias",
"type": "code",
"list": False,
}
assert template["max_retries"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 6,
"password": False,
"name": "max_retries",
"type": "int",
"list": False,
}
assert template["streaming"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "streaming",
"type": "bool",
"list": False,
}
def test_chat_open_ai(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
language_models = json_response["llms"]
model = language_models["ChatOpenAI"]
template = model["template"]
assert template["verbose"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "verbose",
"type": "bool",
"list": False,
}
assert template["client"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "client",
"type": "Any",
"list": False,
}
assert template["model_name"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": "gpt-3.5-turbo",
"password": False,
"options": ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"],
"name": "model_name",
"type": "str",
"list": True,
}
assert template["temperature"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"value": 0.7,
"password": False,
"name": "temperature",
"type": "float",
"list": False,
}
assert template["model_kwargs"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "model_kwargs",
"type": "code",
"list": False,
}
assert template["openai_api_key"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"value": "",
"password": True,
"name": "openai_api_key",
"display_name": "OpenAI API Key",
"type": "str",
"list": False,
}
assert template["request_timeout"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 60,
"password": False,
"name": "request_timeout",
"type": "int",
"list": False,
}
assert template["max_retries"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 6,
"password": False,
"name": "max_retries",
"type": "int",
"list": False,
}
assert template["streaming"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": False,
"password": False,
"name": "streaming",
"type": "bool",
"list": False,
}
assert template["n"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": 1,
"password": False,
"name": "n",
"type": "int",
"list": False,
}
assert template["max_tokens"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": False,
"password": True,
"name": "max_tokens",
"type": "int",
"list": False,
}
assert template["_type"] == "ChatOpenAI"
assert (
model["description"]
== "Wrapper around OpenAI Chat large language models.To use, you should have the ``openai`` python package installed, and theenvironment variable ``OPENAI_API_KEY`` set with your API key.Any parameters that are valid to be passed to the openai.create call can be passedin, even if not explicitly saved on this class." # noqa E501
)
assert set(model["base_classes"]) == {
"BaseChatModel",
"ChatOpenAI",
"BaseLanguageModel",
}

View file

@ -0,0 +1,197 @@
from fastapi.testclient import TestClient
from langflow.settings import settings
def test_prompts_settings(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
prompts = json_response["prompts"]
assert set(prompts.keys()) == set(settings.prompts)
def test_prompt_template(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
prompts = json_response["prompts"]
prompt = prompts["PromptTemplate"]
template = prompt["template"]
assert template["input_variables"] == {
"required": True,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "input_variables",
"type": "str",
"list": True,
}
assert template["output_parser"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "output_parser",
"type": "BaseOutputParser",
"list": False,
}
assert template["partial_variables"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "partial_variables",
"type": "code",
"list": False,
}
assert template["template"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": True,
"password": False,
"name": "template",
"type": "prompt",
"list": False,
}
assert template["template_format"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "f-string",
"password": False,
"name": "template_format",
"type": "str",
"list": False,
}
assert template["validate_template"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": True,
"password": False,
"name": "validate_template",
"type": "bool",
"list": False,
}
def test_few_shot_prompt_template(client: TestClient):
response = client.get("/all")
assert response.status_code == 200
json_response = response.json()
prompts = json_response["prompts"]
prompt = prompts["FewShotPromptTemplate"]
template = prompt["template"]
# Test other fields in the template similar to PromptTemplate
assert template["examples"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": True,
"password": False,
"name": "examples",
"type": "prompt",
"list": True,
}
assert template["example_selector"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"password": False,
"name": "example_selector",
"type": "BaseExampleSelector",
"list": False,
}
assert template["example_prompt"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": False,
"password": False,
"name": "example_prompt",
"type": "PromptTemplate",
"list": False,
}
assert template["suffix"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": True,
"password": False,
"name": "suffix",
"type": "prompt",
"list": False,
}
assert template["example_separator"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"value": "\n\n",
"password": False,
"name": "example_separator",
"type": "str",
"list": False,
}
assert template["prefix"] == {
"required": False,
"placeholder": "",
"show": True,
"multiline": True,
"value": "",
"password": False,
"name": "prefix",
"type": "prompt",
"list": False,
}
def test_zero_shot_prompt(client: TestClient):
response = client.get("/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": "str",
"list": False,
}
assert template["suffix"] == {
"required": True,
"placeholder": "",
"show": True,
"multiline": True,
"value": "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}",
"password": False,
"name": "suffix",
"type": "str",
"list": False,
}
assert template["format_instructions"] == {
"required": False,
"placeholder": "",
"show": False,
"multiline": False,
"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": "str",
"list": False,
}