[Python] Changing examples value in langchain chain

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    Assuming we have langchain chain my_chain created using my_schema via:

    from langchain.chat_models import ChatOpenAI
    from kor.extraction import create_extraction_chain
    from kor.nodes import Object, Text, Number
    from langchain.chat.models import ChatOpenAI
    from langchain.llms import OpenAI

    schema = Object(
    id="bank_statement_info",
    description="bank statement information about a given person.",
    attributes=[
    Text(
    id="first_name",
    description="The first name of the person",
    examples=[("John Smith", "John")],
    ),
    Text(
    id="last_name",
    description="The last name of the person",
    examples=[("John Smith", "Smith")],
    ),
    Text(
    id="account_number",
    description="Account Number of the person in Bank statement.",
    examples=[("Account Number: 122-233-566-800", "122-233-566-800")],
    ),
    Text(
    id="address",
    description="address of the person in Bank statement.",
    ),
    Text(
    id="opening_balance",
    description="opening blance of the person in Bank statement.",
    examples=[("opening Balance: 245,800.00","245,800.00")]
    ),
    Text(
    id="closing_balance",
    description="closing blance of the person in Bank statement.",
    examples=[("Closing Balance: 591,800.00","591,800.00")]
    ),
    ],
    examples=[
    (
    """ya 231 Valley Farms Street
    FIRST Santa Monica, CA 90403 STATEMENT OF ACCOUNT
    CITIZENS __firstcitizensbank@domain.com
    BANK
    Account Number: 122-233-566-800
    Statement Date: 11/22/2019 Page 1 of 1
    Period Covered: 05/22/2019 to 11/22/2019
    Eric Nam Opening Balance: 175,800.00
    240 st, apt 15, hill road, Total Credit Amount: 510,000.00
    Baverly Hills, LA, 90209 Total Debit Amount: 94,000.00
    Closing Balance: 591,800.00
    Branch - Baverly Hills Account Type: Saving Account""",
    [
    {"first_name": "John", "last_name": "Smith", "account_number": '122-233-566-800',"address":"240 st, apt 15, hill road,Baverly Hills, LA, 90209",
    "Closing Balance": "458,589.00","opening Balance": "800.00"},
    {"first_name": "Jane", "last_name": "Doe", "age": '923-533-256-205',"address":"850 st, apt 82, hill road,Baverly Hills, New york, 82044",
    "Closing Balance": "1000.00","opening Balance": "125,987.00"},
    ],
    )
    ],
    many=True,
    )
    llm = ChatOpenAI(temperature=0.0, openai_api_key='', open_api_base='', model_kwargs={'engine': 'openai_gpt_4'}
    my_chain = create_extraction_chain(llm, my_schema, encoder_or_encoder_class='json')


    I want to have access to examples of my_chain after creating it. I tried to take access by accesing my_chain.prompt but afterwards could not get to examples. In particular, I would like to be able to dynamically change the examples of my_chain. Is that possible?

    Continue reading...

Compartilhe esta Página