qa_with_structure.py — langchain Source File
Architecture documentation for qa_with_structure.py, a python file in the langchain codebase. 12 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c4d776aa_af27_d81b_af91_432812868d2f["qa_with_structure.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] c4d776aa_af27_d81b_af91_432812868d2f --> feec1ec4_6917_867b_d228_b134d0ff8099 2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"] c4d776aa_af27_d81b_af91_432812868d2f --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6 e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"] c4d776aa_af27_d81b_af91_432812868d2f --> e929cf21_6ab8_6ff3_3765_0d35a099a053 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] c4d776aa_af27_d81b_af91_432812868d2f --> 9444498b_8066_55c7_b3a2_1d90c4162a32 628cbc5d_711f_ac0c_2f53_db992d48d7da["langchain_core.output_parsers"] c4d776aa_af27_d81b_af91_432812868d2f --> 628cbc5d_711f_ac0c_2f53_db992d48d7da 2b2663e7_3c78_e2fb_75f2_99a68ca124a7["langchain_core.output_parsers.openai_functions"] c4d776aa_af27_d81b_af91_432812868d2f --> 2b2663e7_3c78_e2fb_75f2_99a68ca124a7 435e49bf_bb2e_2016_ead7_0afb9d57ad71["langchain_core.prompts"] c4d776aa_af27_d81b_af91_432812868d2f --> 435e49bf_bb2e_2016_ead7_0afb9d57ad71 16c7d167_e2e4_cd42_2bc2_d182459cd93c["langchain_core.prompts.chat"] c4d776aa_af27_d81b_af91_432812868d2f --> 16c7d167_e2e4_cd42_2bc2_d182459cd93c 314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7["langchain_core.utils.pydantic"] c4d776aa_af27_d81b_af91_432812868d2f --> 314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7 dd5e7909_a646_84f1_497b_cae69735550e["pydantic"] c4d776aa_af27_d81b_af91_432812868d2f --> dd5e7909_a646_84f1_497b_cae69735550e 4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"] c4d776aa_af27_d81b_af91_432812868d2f --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac 0c185122_d3ba_0c43_f0ed_a34e98a95301["langchain_classic.chains.openai_functions.utils"] c4d776aa_af27_d81b_af91_432812868d2f --> 0c185122_d3ba_0c43_f0ed_a34e98a95301 style c4d776aa_af27_d81b_af91_432812868d2f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Any, cast
from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.output_parsers import BaseLLMOutputParser
from langchain_core.output_parsers.openai_functions import (
OutputFunctionsParser,
PydanticOutputFunctionsParser,
)
from langchain_core.prompts import PromptTemplate
from langchain_core.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain_core.utils.pydantic import is_basemodel_subclass
from pydantic import BaseModel, Field
from langchain_classic.chains.llm import LLMChain
from langchain_classic.chains.openai_functions.utils import get_llm_kwargs
class AnswerWithSources(BaseModel):
"""An answer to the question, with sources."""
answer: str = Field(..., description="Answer to the question that was asked")
sources: list[str] = Field(
...,
description="List of sources used to answer the question",
)
@deprecated(
since="0.2.13",
removal="1.0",
message=(
"This function is deprecated. Refer to this guide on retrieval and question "
"answering with structured responses: "
"https://python.langchain.com/docs/how_to/qa_sources/#structure-sources-in-model-response"
),
)
def create_qa_with_structure_chain(
llm: BaseLanguageModel,
schema: dict | type[BaseModel],
output_parser: str = "base",
prompt: PromptTemplate | ChatPromptTemplate | None = None,
verbose: bool = False, # noqa: FBT001,FBT002
) -> LLMChain:
"""Create a question answering chain with structure.
Create a question answering chain that returns an answer with sources
based on schema.
Args:
llm: Language model to use for the chain.
schema: Pydantic schema to use for the output.
output_parser: Output parser to use. Should be one of `'pydantic'` or `'base'`.
prompt: Optional prompt to use for the chain.
verbose: Whether to run the chain in verbose mode.
Returns:
The question answering chain.
// ... (83 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain_classic.chains.llm
- langchain_classic.chains.openai_functions.utils
- langchain_core._api
- langchain_core.language_models
- langchain_core.messages
- langchain_core.output_parsers
- langchain_core.output_parsers.openai_functions
- langchain_core.prompts
- langchain_core.prompts.chat
- langchain_core.utils.pydantic
- pydantic
- typing
Source
Frequently Asked Questions
What does qa_with_structure.py do?
qa_with_structure.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What functions are defined in qa_with_structure.py?
qa_with_structure.py defines 2 function(s): create_qa_with_sources_chain, create_qa_with_structure_chain.
What does qa_with_structure.py depend on?
qa_with_structure.py imports 12 module(s): langchain_classic.chains.llm, langchain_classic.chains.openai_functions.utils, langchain_core._api, langchain_core.language_models, langchain_core.messages, langchain_core.output_parsers, langchain_core.output_parsers.openai_functions, langchain_core.prompts, and 4 more.
Where is qa_with_structure.py in the architecture?
qa_with_structure.py is located at libs/langchain/langchain_classic/chains/openai_functions/qa_with_structure.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/openai_functions).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free