test_qa_with_sources.py — langchain Source File
Architecture documentation for test_qa_with_sources.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 79631e59_6cd0_6528_3308_9240c97eabc2["test_qa_with_sources.py"] 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 79631e59_6cd0_6528_3308_9240c97eabc2 --> 120e2591_3e15_b895_72b6_cb26195e40a6 a85812ae_1e45_eb7c_7e8b_9e227e93604a["langchain_classic.chains.qa_with_sources.base"] 79631e59_6cd0_6528_3308_9240c97eabc2 --> a85812ae_1e45_eb7c_7e8b_9e227e93604a 7e88f5ce_ff41_7d87_8fb2_f355489a149e["tests.unit_tests.llms.fake_llm"] 79631e59_6cd0_6528_3308_9240c97eabc2 --> 7e88f5ce_ff41_7d87_8fb2_f355489a149e style 79631e59_6cd0_6528_3308_9240c97eabc2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import pytest
from langchain_classic.chains.qa_with_sources.base import QAWithSourcesChain
from tests.unit_tests.llms.fake_llm import FakeLLM
@pytest.mark.parametrize(
("text", "answer", "sources"),
[
(
"This Agreement is governed by English law.\nSOURCES: 28-pl",
"This Agreement is governed by English law.\n",
"28-pl",
),
(
"This Agreement is governed by English law.\nSources: 28-pl",
"This Agreement is governed by English law.\n",
"28-pl",
),
(
"This Agreement is governed by English law.\nsource: 28-pl",
"This Agreement is governed by English law.\n",
"28-pl",
),
(
"This Agreement is governed by English law.\nSource: 28-pl",
"This Agreement is governed by English law.\n",
"28-pl",
),
(
"According to the sources the agreement is governed by English law.\n"
"Source: 28-pl",
"According to the sources the agreement is governed by English law.\n",
"28-pl",
),
(
"This Agreement is governed by English law.\n"
"SOURCES: 28-pl\n\n"
"QUESTION: Which state/country's law governs the interpretation of the "
"contract?\n"
"FINAL ANSWER: This Agreement is governed by English law.\n"
"SOURCES: 28-pl",
"This Agreement is governed by English law.\n",
"28-pl",
),
(
"The president did not mention Michael Jackson in the provided content.\n"
"SOURCES: \n\n"
"Note: Since the content provided does not contain any information about "
"Michael Jackson, there are no sources to cite for this specific question.",
"The president did not mention Michael Jackson in the provided content.\n",
"",
),
# The following text was generated by gpt-3.5-turbo
(
"To diagnose the problem, please answer the following questions and send "
"them in one message to IT:\nA1. Are you connected to the office network? "
"VPN will not work from the office network.\nA2. Are you sure about your "
"login/password?\nA3. Are you using any other VPN (e.g. from a client)?\n"
"A4. When was the last time you used the company VPN?\n"
"SOURCES: 1\n\n"
"ALTERNATIVE OPTION: Another option is to run the VPN in CLI, but keep in "
"mind that DNS settings may not work and there may be a need for manual "
"modification of the local resolver or /etc/hosts and/or ~/.ssh/config "
"files to be able to connect to machines in the company. With the "
"appropriate packages installed, the only thing needed to establish "
"a connection is to run the command:\nsudo openvpn --config config.ovpn"
"\n\nWe will be asked for a username and password - provide the login "
"details, the same ones that have been used so far for VPN connection, "
"connecting to the company's WiFi, or printers (in the Warsaw office)."
"\n\nFinally, just use the VPN connection.\n"
"SOURCES: 2\n\n"
"ALTERNATIVE OPTION (for Windows): Download the"
"OpenVPN client application version 2.6 or newer from the official "
"website: https://openvpn.net/community-downloads/\n"
"SOURCES: 3",
"To diagnose the problem, please answer the following questions and send "
"them in one message to IT:\nA1. Are you connected to the office network? "
"VPN will not work from the office network.\nA2. Are you sure about your "
"login/password?\nA3. Are you using any other VPN (e.g. from a client)?\n"
"A4. When was the last time you used the company VPN?\n",
"1",
),
],
)
def test_spliting_answer_into_answer_and_sources(
text: str,
answer: str,
sources: str,
) -> None:
qa_chain = QAWithSourcesChain.from_llm(FakeLLM())
generated_answer, generated_sources = qa_chain._split_sources(text)
assert generated_answer == answer
assert generated_sources == sources
Domain
Subdomains
Dependencies
- langchain_classic.chains.qa_with_sources.base
- pytest
- tests.unit_tests.llms.fake_llm
Source
Frequently Asked Questions
What does test_qa_with_sources.py do?
test_qa_with_sources.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_qa_with_sources.py?
test_qa_with_sources.py defines 1 function(s): test_spliting_answer_into_answer_and_sources.
What does test_qa_with_sources.py depend on?
test_qa_with_sources.py imports 3 module(s): langchain_classic.chains.qa_with_sources.base, pytest, tests.unit_tests.llms.fake_llm.
Where is test_qa_with_sources.py in the architecture?
test_qa_with_sources.py is located at libs/langchain/tests/unit_tests/chains/test_qa_with_sources.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/unit_tests/chains).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free