更改langchain链中的示例值

Changing examples value in langchain chain

提问人:singa1994 提问时间:11/18/2023 更新时间:11/18/2023 访问量:20

问:

洛杉矶

假设我们使用 via 创建了 langchain 链:my_chainmy_schema

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 [email protected]
              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')

我想在创建后访问它。我试图通过访问来访问,但后来无法获得示例。特别是,我希望能够动态更改 的 .这可能吗?examplesmy_chainmy_chain.promptexamplesmy_chain

python nlp langchain 大语言模型 chatgpt-api

评论


答:

0赞 Kinjal 11/18/2023 #1

如果需要动态更改架构中的示例,可以在将其传递到 .像这样的东西。create_extraction_chain

def extract(content: str, schema: dict):
    return create_extraction_chain(schema=schema, llm=llm).run(content)

schema = {...} # new examples
extracted_content = extract(content, schema)