langchain 0.3.27__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of langchain might be problematic. Click here for more details.
- langchain/__init__.py +2 -452
- langchain/agents/__init__.py +9 -178
- langchain/agents/factory.py +1582 -0
- langchain/agents/middleware/__init__.py +80 -0
- langchain/agents/middleware/_execution.py +388 -0
- langchain/agents/middleware/_redaction.py +350 -0
- langchain/agents/middleware/context_editing.py +274 -0
- langchain/agents/middleware/file_search.py +382 -0
- langchain/agents/middleware/human_in_the_loop.py +351 -0
- langchain/agents/middleware/model_call_limit.py +210 -0
- langchain/agents/middleware/model_fallback.py +137 -0
- langchain/agents/middleware/pii.py +317 -0
- langchain/agents/middleware/shell_tool.py +718 -0
- langchain/agents/middleware/summarization.py +249 -0
- langchain/agents/middleware/todo.py +219 -0
- langchain/agents/middleware/tool_call_limit.py +333 -0
- langchain/agents/middleware/tool_emulator.py +200 -0
- langchain/agents/middleware/tool_retry.py +384 -0
- langchain/agents/middleware/tool_selection.py +310 -0
- langchain/agents/middleware/types.py +1572 -0
- langchain/agents/structured_output.py +426 -0
- langchain/chat_models/__init__.py +7 -72
- langchain/chat_models/base.py +264 -317
- langchain/embeddings/__init__.py +7 -217
- langchain/embeddings/base.py +32 -42
- langchain/messages/__init__.py +72 -0
- langchain/rate_limiters/__init__.py +13 -0
- langchain/tools/__init__.py +17 -197
- langchain/tools/tool_node.py +1700 -0
- langchain-1.0.0.dist-info/METADATA +87 -0
- langchain-1.0.0.dist-info/RECORD +34 -0
- {langchain-0.3.27.dist-info → langchain-1.0.0.dist-info}/WHEEL +1 -1
- langchain/_api/__init__.py +0 -28
- langchain/_api/deprecation.py +0 -32
- langchain/_api/interactive_env.py +0 -5
- langchain/_api/module_import.py +0 -153
- langchain/_api/path.py +0 -3
- langchain/adapters/__init__.py +0 -0
- langchain/adapters/openai.py +0 -63
- langchain/agents/agent.py +0 -1828
- langchain/agents/agent_iterator.py +0 -431
- langchain/agents/agent_toolkits/__init__.py +0 -167
- langchain/agents/agent_toolkits/ainetwork/__init__.py +0 -1
- langchain/agents/agent_toolkits/ainetwork/toolkit.py +0 -25
- langchain/agents/agent_toolkits/amadeus/toolkit.py +0 -23
- langchain/agents/agent_toolkits/azure_cognitive_services.py +0 -29
- langchain/agents/agent_toolkits/base.py +0 -3
- langchain/agents/agent_toolkits/clickup/__init__.py +0 -0
- langchain/agents/agent_toolkits/clickup/toolkit.py +0 -25
- langchain/agents/agent_toolkits/conversational_retrieval/__init__.py +0 -0
- langchain/agents/agent_toolkits/conversational_retrieval/openai_functions.py +0 -87
- langchain/agents/agent_toolkits/conversational_retrieval/tool.py +0 -3
- langchain/agents/agent_toolkits/csv/__init__.py +0 -28
- langchain/agents/agent_toolkits/file_management/__init__.py +0 -31
- langchain/agents/agent_toolkits/file_management/toolkit.py +0 -29
- langchain/agents/agent_toolkits/github/__init__.py +0 -1
- langchain/agents/agent_toolkits/github/toolkit.py +0 -69
- langchain/agents/agent_toolkits/gitlab/__init__.py +0 -1
- langchain/agents/agent_toolkits/gitlab/toolkit.py +0 -25
- langchain/agents/agent_toolkits/gmail/__init__.py +0 -1
- langchain/agents/agent_toolkits/gmail/toolkit.py +0 -23
- langchain/agents/agent_toolkits/jira/__init__.py +0 -1
- langchain/agents/agent_toolkits/jira/toolkit.py +0 -23
- langchain/agents/agent_toolkits/json/__init__.py +0 -1
- langchain/agents/agent_toolkits/json/base.py +0 -25
- langchain/agents/agent_toolkits/json/prompt.py +0 -24
- langchain/agents/agent_toolkits/json/toolkit.py +0 -23
- langchain/agents/agent_toolkits/multion/__init__.py +0 -1
- langchain/agents/agent_toolkits/multion/toolkit.py +0 -25
- langchain/agents/agent_toolkits/nasa/__init__.py +0 -1
- langchain/agents/agent_toolkits/nasa/toolkit.py +0 -23
- langchain/agents/agent_toolkits/nla/__init__.py +0 -0
- langchain/agents/agent_toolkits/nla/tool.py +0 -23
- langchain/agents/agent_toolkits/nla/toolkit.py +0 -23
- langchain/agents/agent_toolkits/office365/__init__.py +0 -1
- langchain/agents/agent_toolkits/office365/toolkit.py +0 -25
- langchain/agents/agent_toolkits/openapi/__init__.py +0 -1
- langchain/agents/agent_toolkits/openapi/base.py +0 -25
- langchain/agents/agent_toolkits/openapi/planner.py +0 -52
- langchain/agents/agent_toolkits/openapi/planner_prompt.py +0 -103
- langchain/agents/agent_toolkits/openapi/prompt.py +0 -29
- langchain/agents/agent_toolkits/openapi/spec.py +0 -30
- langchain/agents/agent_toolkits/openapi/toolkit.py +0 -30
- langchain/agents/agent_toolkits/pandas/__init__.py +0 -28
- langchain/agents/agent_toolkits/playwright/__init__.py +0 -29
- langchain/agents/agent_toolkits/playwright/toolkit.py +0 -27
- langchain/agents/agent_toolkits/powerbi/__init__.py +0 -1
- langchain/agents/agent_toolkits/powerbi/base.py +0 -25
- langchain/agents/agent_toolkits/powerbi/chat_base.py +0 -27
- langchain/agents/agent_toolkits/powerbi/prompt.py +0 -36
- langchain/agents/agent_toolkits/powerbi/toolkit.py +0 -25
- langchain/agents/agent_toolkits/python/__init__.py +0 -28
- langchain/agents/agent_toolkits/slack/__init__.py +0 -1
- langchain/agents/agent_toolkits/slack/toolkit.py +0 -23
- langchain/agents/agent_toolkits/spark/__init__.py +0 -28
- langchain/agents/agent_toolkits/spark_sql/__init__.py +0 -1
- langchain/agents/agent_toolkits/spark_sql/base.py +0 -25
- langchain/agents/agent_toolkits/spark_sql/prompt.py +0 -27
- langchain/agents/agent_toolkits/spark_sql/toolkit.py +0 -25
- langchain/agents/agent_toolkits/sql/__init__.py +0 -1
- langchain/agents/agent_toolkits/sql/base.py +0 -23
- langchain/agents/agent_toolkits/sql/prompt.py +0 -29
- langchain/agents/agent_toolkits/sql/toolkit.py +0 -25
- langchain/agents/agent_toolkits/steam/__init__.py +0 -1
- langchain/agents/agent_toolkits/steam/toolkit.py +0 -23
- langchain/agents/agent_toolkits/vectorstore/__init__.py +0 -1
- langchain/agents/agent_toolkits/vectorstore/base.py +0 -217
- langchain/agents/agent_toolkits/vectorstore/prompt.py +0 -11
- langchain/agents/agent_toolkits/vectorstore/toolkit.py +0 -97
- langchain/agents/agent_toolkits/xorbits/__init__.py +0 -28
- langchain/agents/agent_toolkits/zapier/__init__.py +0 -1
- langchain/agents/agent_toolkits/zapier/toolkit.py +0 -25
- langchain/agents/agent_types.py +0 -57
- langchain/agents/chat/__init__.py +0 -0
- langchain/agents/chat/base.py +0 -178
- langchain/agents/chat/output_parser.py +0 -74
- langchain/agents/chat/prompt.py +0 -29
- langchain/agents/conversational/__init__.py +0 -1
- langchain/agents/conversational/base.py +0 -176
- langchain/agents/conversational/output_parser.py +0 -51
- langchain/agents/conversational/prompt.py +0 -35
- langchain/agents/conversational_chat/__init__.py +0 -1
- langchain/agents/conversational_chat/base.py +0 -181
- langchain/agents/conversational_chat/output_parser.py +0 -57
- langchain/agents/conversational_chat/prompt.py +0 -56
- langchain/agents/format_scratchpad/__init__.py +0 -25
- langchain/agents/format_scratchpad/log.py +0 -25
- langchain/agents/format_scratchpad/log_to_messages.py +0 -26
- langchain/agents/format_scratchpad/openai_functions.py +0 -80
- langchain/agents/format_scratchpad/openai_tools.py +0 -5
- langchain/agents/format_scratchpad/tools.py +0 -65
- langchain/agents/format_scratchpad/xml.py +0 -52
- langchain/agents/initialize.py +0 -105
- langchain/agents/json_chat/__init__.py +0 -0
- langchain/agents/json_chat/base.py +0 -195
- langchain/agents/json_chat/prompt.py +0 -8
- langchain/agents/load_tools.py +0 -13
- langchain/agents/loading.py +0 -148
- langchain/agents/mrkl/__init__.py +0 -1
- langchain/agents/mrkl/base.py +0 -216
- langchain/agents/mrkl/output_parser.py +0 -103
- langchain/agents/mrkl/prompt.py +0 -15
- langchain/agents/openai_assistant/__init__.py +0 -3
- langchain/agents/openai_assistant/base.py +0 -818
- langchain/agents/openai_functions_agent/__init__.py +0 -0
- langchain/agents/openai_functions_agent/agent_token_buffer_memory.py +0 -101
- langchain/agents/openai_functions_agent/base.py +0 -381
- langchain/agents/openai_functions_multi_agent/__init__.py +0 -0
- langchain/agents/openai_functions_multi_agent/base.py +0 -337
- langchain/agents/openai_tools/__init__.py +0 -0
- langchain/agents/openai_tools/base.py +0 -108
- langchain/agents/output_parsers/__init__.py +0 -35
- langchain/agents/output_parsers/json.py +0 -62
- langchain/agents/output_parsers/openai_functions.py +0 -96
- langchain/agents/output_parsers/openai_tools.py +0 -70
- langchain/agents/output_parsers/react_json_single_input.py +0 -84
- langchain/agents/output_parsers/react_single_input.py +0 -99
- langchain/agents/output_parsers/self_ask.py +0 -51
- langchain/agents/output_parsers/tools.py +0 -107
- langchain/agents/output_parsers/xml.py +0 -123
- langchain/agents/react/__init__.py +0 -1
- langchain/agents/react/agent.py +0 -144
- langchain/agents/react/base.py +0 -185
- langchain/agents/react/output_parser.py +0 -33
- langchain/agents/react/textworld_prompt.py +0 -51
- langchain/agents/react/wiki_prompt.py +0 -70
- langchain/agents/schema.py +0 -35
- langchain/agents/self_ask_with_search/__init__.py +0 -4
- langchain/agents/self_ask_with_search/base.py +0 -215
- langchain/agents/self_ask_with_search/output_parser.py +0 -4
- langchain/agents/self_ask_with_search/prompt.py +0 -43
- langchain/agents/structured_chat/__init__.py +0 -0
- langchain/agents/structured_chat/base.py +0 -304
- langchain/agents/structured_chat/output_parser.py +0 -99
- langchain/agents/structured_chat/prompt.py +0 -34
- langchain/agents/tool_calling_agent/__init__.py +0 -0
- langchain/agents/tool_calling_agent/base.py +0 -110
- langchain/agents/tools.py +0 -47
- langchain/agents/types.py +0 -27
- langchain/agents/utils.py +0 -19
- langchain/agents/xml/__init__.py +0 -0
- langchain/agents/xml/base.py +0 -231
- langchain/agents/xml/prompt.py +0 -21
- langchain/base_language.py +0 -7
- langchain/cache.py +0 -72
- langchain/callbacks/__init__.py +0 -139
- langchain/callbacks/aim_callback.py +0 -33
- langchain/callbacks/argilla_callback.py +0 -25
- langchain/callbacks/arize_callback.py +0 -25
- langchain/callbacks/arthur_callback.py +0 -25
- langchain/callbacks/base.py +0 -29
- langchain/callbacks/clearml_callback.py +0 -25
- langchain/callbacks/comet_ml_callback.py +0 -25
- langchain/callbacks/confident_callback.py +0 -25
- langchain/callbacks/context_callback.py +0 -25
- langchain/callbacks/file.py +0 -3
- langchain/callbacks/flyte_callback.py +0 -25
- langchain/callbacks/human.py +0 -33
- langchain/callbacks/infino_callback.py +0 -25
- langchain/callbacks/labelstudio_callback.py +0 -33
- langchain/callbacks/llmonitor_callback.py +0 -27
- langchain/callbacks/manager.py +0 -89
- langchain/callbacks/mlflow_callback.py +0 -38
- langchain/callbacks/openai_info.py +0 -25
- langchain/callbacks/promptlayer_callback.py +0 -27
- langchain/callbacks/sagemaker_callback.py +0 -27
- langchain/callbacks/stdout.py +0 -3
- langchain/callbacks/streaming_aiter.py +0 -75
- langchain/callbacks/streaming_aiter_final_only.py +0 -91
- langchain/callbacks/streaming_stdout.py +0 -5
- langchain/callbacks/streaming_stdout_final_only.py +0 -91
- langchain/callbacks/streamlit/__init__.py +0 -86
- langchain/callbacks/streamlit/mutable_expander.py +0 -33
- langchain/callbacks/streamlit/streamlit_callback_handler.py +0 -49
- langchain/callbacks/tracers/__init__.py +0 -38
- langchain/callbacks/tracers/base.py +0 -6
- langchain/callbacks/tracers/comet.py +0 -30
- langchain/callbacks/tracers/evaluation.py +0 -8
- langchain/callbacks/tracers/langchain.py +0 -8
- langchain/callbacks/tracers/langchain_v1.py +0 -3
- langchain/callbacks/tracers/log_stream.py +0 -9
- langchain/callbacks/tracers/logging.py +0 -46
- langchain/callbacks/tracers/root_listeners.py +0 -3
- langchain/callbacks/tracers/run_collector.py +0 -3
- langchain/callbacks/tracers/schemas.py +0 -27
- langchain/callbacks/tracers/stdout.py +0 -6
- langchain/callbacks/tracers/wandb.py +0 -27
- langchain/callbacks/trubrics_callback.py +0 -25
- langchain/callbacks/utils.py +0 -48
- langchain/callbacks/wandb_callback.py +0 -25
- langchain/callbacks/whylabs_callback.py +0 -25
- langchain/chains/__init__.py +0 -96
- langchain/chains/api/__init__.py +0 -1
- langchain/chains/api/base.py +0 -394
- langchain/chains/api/news_docs.py +0 -31
- langchain/chains/api/open_meteo_docs.py +0 -32
- langchain/chains/api/openapi/__init__.py +0 -0
- langchain/chains/api/openapi/chain.py +0 -23
- langchain/chains/api/openapi/prompts.py +0 -27
- langchain/chains/api/openapi/requests_chain.py +0 -29
- langchain/chains/api/openapi/response_chain.py +0 -29
- langchain/chains/api/podcast_docs.py +0 -27
- langchain/chains/api/prompt.py +0 -35
- langchain/chains/api/tmdb_docs.py +0 -36
- langchain/chains/base.py +0 -800
- langchain/chains/chat_vector_db/__init__.py +0 -0
- langchain/chains/chat_vector_db/prompts.py +0 -19
- langchain/chains/combine_documents/__init__.py +0 -15
- langchain/chains/combine_documents/base.py +0 -287
- langchain/chains/combine_documents/map_reduce.py +0 -300
- langchain/chains/combine_documents/map_rerank.py +0 -247
- langchain/chains/combine_documents/reduce.py +0 -381
- langchain/chains/combine_documents/refine.py +0 -236
- langchain/chains/combine_documents/stuff.py +0 -288
- langchain/chains/constitutional_ai/__init__.py +0 -2
- langchain/chains/constitutional_ai/base.py +0 -321
- langchain/chains/constitutional_ai/models.py +0 -11
- langchain/chains/constitutional_ai/principles.py +0 -278
- langchain/chains/constitutional_ai/prompts.py +0 -120
- langchain/chains/conversation/__init__.py +0 -1
- langchain/chains/conversation/base.py +0 -143
- langchain/chains/conversation/memory.py +0 -45
- langchain/chains/conversation/prompt.py +0 -28
- langchain/chains/conversational_retrieval/__init__.py +0 -1
- langchain/chains/conversational_retrieval/base.py +0 -568
- langchain/chains/conversational_retrieval/prompts.py +0 -19
- langchain/chains/elasticsearch_database/__init__.py +0 -3
- langchain/chains/elasticsearch_database/base.py +0 -211
- langchain/chains/elasticsearch_database/prompts.py +0 -35
- langchain/chains/ernie_functions/__init__.py +0 -44
- langchain/chains/ernie_functions/base.py +0 -49
- langchain/chains/example_generator.py +0 -22
- langchain/chains/flare/__init__.py +0 -1
- langchain/chains/flare/base.py +0 -282
- langchain/chains/flare/prompts.py +0 -44
- langchain/chains/graph_qa/__init__.py +0 -0
- langchain/chains/graph_qa/arangodb.py +0 -23
- langchain/chains/graph_qa/base.py +0 -23
- langchain/chains/graph_qa/cypher.py +0 -39
- langchain/chains/graph_qa/cypher_utils.py +0 -27
- langchain/chains/graph_qa/falkordb.py +0 -29
- langchain/chains/graph_qa/gremlin.py +0 -36
- langchain/chains/graph_qa/hugegraph.py +0 -23
- langchain/chains/graph_qa/kuzu.py +0 -29
- langchain/chains/graph_qa/nebulagraph.py +0 -23
- langchain/chains/graph_qa/neptune_cypher.py +0 -39
- langchain/chains/graph_qa/neptune_sparql.py +0 -36
- langchain/chains/graph_qa/ontotext_graphdb.py +0 -25
- langchain/chains/graph_qa/prompts.py +0 -96
- langchain/chains/graph_qa/sparql.py +0 -23
- langchain/chains/history_aware_retriever.py +0 -68
- langchain/chains/hyde/__init__.py +0 -4
- langchain/chains/hyde/base.py +0 -124
- langchain/chains/hyde/prompts.py +0 -46
- langchain/chains/llm.py +0 -442
- langchain/chains/llm_bash/__init__.py +0 -10
- langchain/chains/llm_checker/__init__.py +0 -4
- langchain/chains/llm_checker/base.py +0 -194
- langchain/chains/llm_checker/prompt.py +0 -30
- langchain/chains/llm_math/__init__.py +0 -4
- langchain/chains/llm_math/base.py +0 -311
- langchain/chains/llm_math/prompt.py +0 -43
- langchain/chains/llm_requests.py +0 -23
- langchain/chains/llm_summarization_checker/__init__.py +0 -7
- langchain/chains/llm_summarization_checker/base.py +0 -205
- langchain/chains/llm_summarization_checker/prompts/are_all_true_prompt.txt +0 -38
- langchain/chains/llm_summarization_checker/prompts/check_facts.txt +0 -10
- langchain/chains/llm_summarization_checker/prompts/create_facts.txt +0 -10
- langchain/chains/llm_summarization_checker/prompts/revise_summary.txt +0 -17
- langchain/chains/llm_symbolic_math/__init__.py +0 -10
- langchain/chains/loading.py +0 -732
- langchain/chains/mapreduce.py +0 -121
- langchain/chains/moderation.py +0 -132
- langchain/chains/natbot/__init__.py +0 -4
- langchain/chains/natbot/base.py +0 -163
- langchain/chains/natbot/crawler.py +0 -443
- langchain/chains/natbot/prompt.py +0 -143
- langchain/chains/openai_functions/__init__.py +0 -44
- langchain/chains/openai_functions/base.py +0 -235
- langchain/chains/openai_functions/citation_fuzzy_match.py +0 -160
- langchain/chains/openai_functions/extraction.py +0 -197
- langchain/chains/openai_functions/openapi.py +0 -405
- langchain/chains/openai_functions/qa_with_structure.py +0 -142
- langchain/chains/openai_functions/tagging.py +0 -172
- langchain/chains/openai_functions/utils.py +0 -40
- langchain/chains/openai_tools/__init__.py +0 -3
- langchain/chains/openai_tools/extraction.py +0 -79
- langchain/chains/prompt_selector.py +0 -65
- langchain/chains/qa_generation/__init__.py +0 -0
- langchain/chains/qa_generation/base.py +0 -124
- langchain/chains/qa_generation/prompt.py +0 -50
- langchain/chains/qa_with_sources/__init__.py +0 -5
- langchain/chains/qa_with_sources/base.py +0 -263
- langchain/chains/qa_with_sources/loading.py +0 -209
- langchain/chains/qa_with_sources/map_reduce_prompt.py +0 -54
- langchain/chains/qa_with_sources/refine_prompts.py +0 -37
- langchain/chains/qa_with_sources/retrieval.py +0 -75
- langchain/chains/qa_with_sources/stuff_prompt.py +0 -43
- langchain/chains/qa_with_sources/vector_db.py +0 -86
- langchain/chains/query_constructor/__init__.py +0 -3
- langchain/chains/query_constructor/base.py +0 -376
- langchain/chains/query_constructor/ir.py +0 -23
- langchain/chains/query_constructor/parser.py +0 -210
- langchain/chains/query_constructor/prompt.py +0 -226
- langchain/chains/query_constructor/schema.py +0 -14
- langchain/chains/question_answering/__init__.py +0 -6
- langchain/chains/question_answering/chain.py +0 -279
- langchain/chains/question_answering/map_reduce_prompt.py +0 -80
- langchain/chains/question_answering/map_rerank_prompt.py +0 -66
- langchain/chains/question_answering/refine_prompts.py +0 -72
- langchain/chains/question_answering/stuff_prompt.py +0 -33
- langchain/chains/retrieval.py +0 -67
- langchain/chains/retrieval_qa/__init__.py +0 -1
- langchain/chains/retrieval_qa/base.py +0 -370
- langchain/chains/retrieval_qa/prompt.py +0 -11
- langchain/chains/router/__init__.py +0 -12
- langchain/chains/router/base.py +0 -142
- langchain/chains/router/embedding_router.py +0 -93
- langchain/chains/router/llm_router.py +0 -196
- langchain/chains/router/multi_prompt.py +0 -181
- langchain/chains/router/multi_prompt_prompt.py +0 -32
- langchain/chains/router/multi_retrieval_prompt.py +0 -30
- langchain/chains/router/multi_retrieval_qa.py +0 -109
- langchain/chains/sequential.py +0 -220
- langchain/chains/sql_database/__init__.py +0 -1
- langchain/chains/sql_database/prompt.py +0 -282
- langchain/chains/sql_database/query.py +0 -166
- langchain/chains/structured_output/__init__.py +0 -6
- langchain/chains/structured_output/base.py +0 -582
- langchain/chains/summarize/__init__.py +0 -6
- langchain/chains/summarize/chain.py +0 -174
- langchain/chains/summarize/map_reduce_prompt.py +0 -10
- langchain/chains/summarize/refine_prompts.py +0 -23
- langchain/chains/summarize/stuff_prompt.py +0 -10
- langchain/chains/transform.py +0 -84
- langchain/chat_loaders/__init__.py +0 -19
- langchain/chat_loaders/base.py +0 -3
- langchain/chat_loaders/facebook_messenger.py +0 -32
- langchain/chat_loaders/gmail.py +0 -23
- langchain/chat_loaders/imessage.py +0 -23
- langchain/chat_loaders/langsmith.py +0 -30
- langchain/chat_loaders/slack.py +0 -23
- langchain/chat_loaders/telegram.py +0 -23
- langchain/chat_loaders/utils.py +0 -36
- langchain/chat_loaders/whatsapp.py +0 -23
- langchain/chat_models/anthropic.py +0 -30
- langchain/chat_models/anyscale.py +0 -23
- langchain/chat_models/azure_openai.py +0 -23
- langchain/chat_models/azureml_endpoint.py +0 -30
- langchain/chat_models/baichuan.py +0 -23
- langchain/chat_models/baidu_qianfan_endpoint.py +0 -27
- langchain/chat_models/bedrock.py +0 -27
- langchain/chat_models/cohere.py +0 -23
- langchain/chat_models/databricks.py +0 -23
- langchain/chat_models/ernie.py +0 -23
- langchain/chat_models/everlyai.py +0 -23
- langchain/chat_models/fake.py +0 -30
- langchain/chat_models/fireworks.py +0 -23
- langchain/chat_models/gigachat.py +0 -23
- langchain/chat_models/google_palm.py +0 -30
- langchain/chat_models/human.py +0 -23
- langchain/chat_models/hunyuan.py +0 -23
- langchain/chat_models/javelin_ai_gateway.py +0 -30
- langchain/chat_models/jinachat.py +0 -23
- langchain/chat_models/konko.py +0 -23
- langchain/chat_models/litellm.py +0 -30
- langchain/chat_models/meta.py +0 -25
- langchain/chat_models/minimax.py +0 -23
- langchain/chat_models/mlflow.py +0 -23
- langchain/chat_models/mlflow_ai_gateway.py +0 -30
- langchain/chat_models/ollama.py +0 -23
- langchain/chat_models/openai.py +0 -23
- langchain/chat_models/pai_eas_endpoint.py +0 -25
- langchain/chat_models/promptlayer_openai.py +0 -25
- langchain/chat_models/tongyi.py +0 -23
- langchain/chat_models/vertexai.py +0 -23
- langchain/chat_models/volcengine_maas.py +0 -30
- langchain/chat_models/yandex.py +0 -23
- langchain/docstore/__init__.py +0 -48
- langchain/docstore/arbitrary_fn.py +0 -23
- langchain/docstore/base.py +0 -27
- langchain/docstore/document.py +0 -3
- langchain/docstore/in_memory.py +0 -23
- langchain/docstore/wikipedia.py +0 -23
- langchain/document_loaders/__init__.py +0 -553
- langchain/document_loaders/acreom.py +0 -23
- langchain/document_loaders/airbyte.py +0 -48
- langchain/document_loaders/airbyte_json.py +0 -23
- langchain/document_loaders/airtable.py +0 -23
- langchain/document_loaders/apify_dataset.py +0 -23
- langchain/document_loaders/arcgis_loader.py +0 -23
- langchain/document_loaders/arxiv.py +0 -23
- langchain/document_loaders/assemblyai.py +0 -28
- langchain/document_loaders/async_html.py +0 -23
- langchain/document_loaders/azlyrics.py +0 -23
- langchain/document_loaders/azure_ai_data.py +0 -23
- langchain/document_loaders/azure_blob_storage_container.py +0 -25
- langchain/document_loaders/azure_blob_storage_file.py +0 -25
- langchain/document_loaders/baiducloud_bos_directory.py +0 -29
- langchain/document_loaders/baiducloud_bos_file.py +0 -27
- langchain/document_loaders/base.py +0 -3
- langchain/document_loaders/base_o365.py +0 -23
- langchain/document_loaders/bibtex.py +0 -23
- langchain/document_loaders/bigquery.py +0 -23
- langchain/document_loaders/bilibili.py +0 -23
- langchain/document_loaders/blackboard.py +0 -23
- langchain/document_loaders/blob_loaders/__init__.py +0 -36
- langchain/document_loaders/blob_loaders/file_system.py +0 -23
- langchain/document_loaders/blob_loaders/schema.py +0 -29
- langchain/document_loaders/blob_loaders/youtube_audio.py +0 -23
- langchain/document_loaders/blockchain.py +0 -28
- langchain/document_loaders/brave_search.py +0 -23
- langchain/document_loaders/browserless.py +0 -23
- langchain/document_loaders/chatgpt.py +0 -28
- langchain/document_loaders/chromium.py +0 -23
- langchain/document_loaders/college_confidential.py +0 -25
- langchain/document_loaders/concurrent.py +0 -23
- langchain/document_loaders/confluence.py +0 -28
- langchain/document_loaders/conllu.py +0 -23
- langchain/document_loaders/couchbase.py +0 -23
- langchain/document_loaders/csv_loader.py +0 -27
- langchain/document_loaders/cube_semantic.py +0 -23
- langchain/document_loaders/datadog_logs.py +0 -23
- langchain/document_loaders/dataframe.py +0 -28
- langchain/document_loaders/diffbot.py +0 -23
- langchain/document_loaders/directory.py +0 -23
- langchain/document_loaders/discord.py +0 -23
- langchain/document_loaders/docugami.py +0 -23
- langchain/document_loaders/docusaurus.py +0 -23
- langchain/document_loaders/dropbox.py +0 -23
- langchain/document_loaders/duckdb_loader.py +0 -23
- langchain/document_loaders/email.py +0 -30
- langchain/document_loaders/epub.py +0 -23
- langchain/document_loaders/etherscan.py +0 -23
- langchain/document_loaders/evernote.py +0 -23
- langchain/document_loaders/excel.py +0 -23
- langchain/document_loaders/facebook_chat.py +0 -28
- langchain/document_loaders/fauna.py +0 -23
- langchain/document_loaders/figma.py +0 -23
- langchain/document_loaders/gcs_directory.py +0 -23
- langchain/document_loaders/gcs_file.py +0 -23
- langchain/document_loaders/generic.py +0 -23
- langchain/document_loaders/geodataframe.py +0 -23
- langchain/document_loaders/git.py +0 -23
- langchain/document_loaders/gitbook.py +0 -23
- langchain/document_loaders/github.py +0 -28
- langchain/document_loaders/google_speech_to_text.py +0 -23
- langchain/document_loaders/googledrive.py +0 -23
- langchain/document_loaders/gutenberg.py +0 -23
- langchain/document_loaders/helpers.py +0 -30
- langchain/document_loaders/hn.py +0 -23
- langchain/document_loaders/html.py +0 -23
- langchain/document_loaders/html_bs.py +0 -23
- langchain/document_loaders/hugging_face_dataset.py +0 -23
- langchain/document_loaders/ifixit.py +0 -23
- langchain/document_loaders/image.py +0 -23
- langchain/document_loaders/image_captions.py +0 -23
- langchain/document_loaders/imsdb.py +0 -23
- langchain/document_loaders/iugu.py +0 -23
- langchain/document_loaders/joplin.py +0 -23
- langchain/document_loaders/json_loader.py +0 -23
- langchain/document_loaders/lakefs.py +0 -33
- langchain/document_loaders/larksuite.py +0 -23
- langchain/document_loaders/markdown.py +0 -25
- langchain/document_loaders/mastodon.py +0 -23
- langchain/document_loaders/max_compute.py +0 -23
- langchain/document_loaders/mediawikidump.py +0 -23
- langchain/document_loaders/merge.py +0 -23
- langchain/document_loaders/mhtml.py +0 -23
- langchain/document_loaders/modern_treasury.py +0 -23
- langchain/document_loaders/mongodb.py +0 -23
- langchain/document_loaders/news.py +0 -23
- langchain/document_loaders/notebook.py +0 -33
- langchain/document_loaders/notion.py +0 -23
- langchain/document_loaders/notiondb.py +0 -23
- langchain/document_loaders/nuclia.py +0 -23
- langchain/document_loaders/obs_directory.py +0 -23
- langchain/document_loaders/obs_file.py +0 -23
- langchain/document_loaders/obsidian.py +0 -23
- langchain/document_loaders/odt.py +0 -23
- langchain/document_loaders/onedrive.py +0 -23
- langchain/document_loaders/onedrive_file.py +0 -23
- langchain/document_loaders/onenote.py +0 -23
- langchain/document_loaders/open_city_data.py +0 -23
- langchain/document_loaders/org_mode.py +0 -25
- langchain/document_loaders/parsers/__init__.py +0 -58
- langchain/document_loaders/parsers/audio.py +0 -33
- langchain/document_loaders/parsers/docai.py +0 -30
- langchain/document_loaders/parsers/generic.py +0 -25
- langchain/document_loaders/parsers/grobid.py +0 -30
- langchain/document_loaders/parsers/html/__init__.py +0 -25
- langchain/document_loaders/parsers/html/bs4.py +0 -25
- langchain/document_loaders/parsers/language/__init__.py +0 -29
- langchain/document_loaders/parsers/language/cobol.py +0 -27
- langchain/document_loaders/parsers/language/code_segmenter.py +0 -29
- langchain/document_loaders/parsers/language/javascript.py +0 -29
- langchain/document_loaders/parsers/language/language_parser.py +0 -29
- langchain/document_loaders/parsers/language/python.py +0 -27
- langchain/document_loaders/parsers/msword.py +0 -25
- langchain/document_loaders/parsers/pdf.py +0 -50
- langchain/document_loaders/parsers/registry.py +0 -25
- langchain/document_loaders/parsers/txt.py +0 -23
- langchain/document_loaders/pdf.py +0 -65
- langchain/document_loaders/polars_dataframe.py +0 -23
- langchain/document_loaders/powerpoint.py +0 -25
- langchain/document_loaders/psychic.py +0 -23
- langchain/document_loaders/pubmed.py +0 -23
- langchain/document_loaders/pyspark_dataframe.py +0 -26
- langchain/document_loaders/python.py +0 -22
- langchain/document_loaders/quip.py +0 -23
- langchain/document_loaders/readthedocs.py +0 -23
- langchain/document_loaders/recursive_url_loader.py +0 -23
- langchain/document_loaders/reddit.py +0 -23
- langchain/document_loaders/roam.py +0 -23
- langchain/document_loaders/rocksetdb.py +0 -23
- langchain/document_loaders/rspace.py +0 -23
- langchain/document_loaders/rss.py +0 -23
- langchain/document_loaders/rst.py +0 -23
- langchain/document_loaders/rtf.py +0 -23
- langchain/document_loaders/s3_directory.py +0 -23
- langchain/document_loaders/s3_file.py +0 -23
- langchain/document_loaders/sharepoint.py +0 -23
- langchain/document_loaders/sitemap.py +0 -23
- langchain/document_loaders/slack_directory.py +0 -23
- langchain/document_loaders/snowflake_loader.py +0 -23
- langchain/document_loaders/spreedly.py +0 -23
- langchain/document_loaders/srt.py +0 -23
- langchain/document_loaders/stripe.py +0 -23
- langchain/document_loaders/telegram.py +0 -38
- langchain/document_loaders/tencent_cos_directory.py +0 -25
- langchain/document_loaders/tencent_cos_file.py +0 -23
- langchain/document_loaders/tensorflow_datasets.py +0 -23
- langchain/document_loaders/text.py +0 -23
- langchain/document_loaders/tomarkdown.py +0 -23
- langchain/document_loaders/toml.py +0 -23
- langchain/document_loaders/trello.py +0 -23
- langchain/document_loaders/tsv.py +0 -23
- langchain/document_loaders/twitter.py +0 -23
- langchain/document_loaders/unstructured.py +0 -54
- langchain/document_loaders/url.py +0 -23
- langchain/document_loaders/url_playwright.py +0 -33
- langchain/document_loaders/url_selenium.py +0 -23
- langchain/document_loaders/weather.py +0 -23
- langchain/document_loaders/web_base.py +0 -23
- langchain/document_loaders/whatsapp_chat.py +0 -28
- langchain/document_loaders/wikipedia.py +0 -23
- langchain/document_loaders/word_document.py +0 -30
- langchain/document_loaders/xml.py +0 -23
- langchain/document_loaders/xorbits.py +0 -23
- langchain/document_loaders/youtube.py +0 -33
- langchain/document_transformers/__init__.py +0 -77
- langchain/document_transformers/beautiful_soup_transformer.py +0 -25
- langchain/document_transformers/doctran_text_extract.py +0 -25
- langchain/document_transformers/doctran_text_qa.py +0 -25
- langchain/document_transformers/doctran_text_translate.py +0 -25
- langchain/document_transformers/embeddings_redundant_filter.py +0 -50
- langchain/document_transformers/google_translate.py +0 -25
- langchain/document_transformers/html2text.py +0 -25
- langchain/document_transformers/long_context_reorder.py +0 -23
- langchain/document_transformers/nuclia_text_transform.py +0 -25
- langchain/document_transformers/openai_functions.py +0 -32
- langchain/document_transformers/xsl/html_chunks_with_headers.xslt +0 -199
- langchain/embeddings/aleph_alpha.py +0 -30
- langchain/embeddings/awa.py +0 -23
- langchain/embeddings/azure_openai.py +0 -23
- langchain/embeddings/baidu_qianfan_endpoint.py +0 -23
- langchain/embeddings/bedrock.py +0 -23
- langchain/embeddings/bookend.py +0 -23
- langchain/embeddings/cache.py +0 -368
- langchain/embeddings/clarifai.py +0 -23
- langchain/embeddings/cloudflare_workersai.py +0 -29
- langchain/embeddings/cohere.py +0 -23
- langchain/embeddings/dashscope.py +0 -23
- langchain/embeddings/databricks.py +0 -23
- langchain/embeddings/deepinfra.py +0 -23
- langchain/embeddings/edenai.py +0 -23
- langchain/embeddings/elasticsearch.py +0 -23
- langchain/embeddings/embaas.py +0 -23
- langchain/embeddings/ernie.py +0 -23
- langchain/embeddings/fake.py +0 -30
- langchain/embeddings/fastembed.py +0 -23
- langchain/embeddings/google_palm.py +0 -23
- langchain/embeddings/gpt4all.py +0 -23
- langchain/embeddings/gradient_ai.py +0 -23
- langchain/embeddings/huggingface.py +0 -36
- langchain/embeddings/huggingface_hub.py +0 -23
- langchain/embeddings/infinity.py +0 -30
- langchain/embeddings/javelin_ai_gateway.py +0 -23
- langchain/embeddings/jina.py +0 -23
- langchain/embeddings/johnsnowlabs.py +0 -23
- langchain/embeddings/llamacpp.py +0 -23
- langchain/embeddings/llm_rails.py +0 -23
- langchain/embeddings/localai.py +0 -23
- langchain/embeddings/minimax.py +0 -23
- langchain/embeddings/mlflow.py +0 -23
- langchain/embeddings/mlflow_gateway.py +0 -23
- langchain/embeddings/modelscope_hub.py +0 -23
- langchain/embeddings/mosaicml.py +0 -23
- langchain/embeddings/nlpcloud.py +0 -23
- langchain/embeddings/octoai_embeddings.py +0 -23
- langchain/embeddings/ollama.py +0 -23
- langchain/embeddings/openai.py +0 -23
- langchain/embeddings/sagemaker_endpoint.py +0 -30
- langchain/embeddings/self_hosted.py +0 -23
- langchain/embeddings/self_hosted_hugging_face.py +0 -30
- langchain/embeddings/sentence_transformer.py +0 -21
- langchain/embeddings/spacy_embeddings.py +0 -23
- langchain/embeddings/tensorflow_hub.py +0 -23
- langchain/embeddings/vertexai.py +0 -23
- langchain/embeddings/voyageai.py +0 -23
- langchain/embeddings/xinference.py +0 -23
- langchain/env.py +0 -17
- langchain/evaluation/__init__.py +0 -128
- langchain/evaluation/agents/__init__.py +0 -5
- langchain/evaluation/agents/trajectory_eval_chain.py +0 -415
- langchain/evaluation/agents/trajectory_eval_prompt.py +0 -146
- langchain/evaluation/comparison/__init__.py +0 -36
- langchain/evaluation/comparison/eval_chain.py +0 -461
- langchain/evaluation/comparison/prompt.py +0 -59
- langchain/evaluation/criteria/__init__.py +0 -56
- langchain/evaluation/criteria/eval_chain.py +0 -603
- langchain/evaluation/criteria/prompt.py +0 -37
- langchain/evaluation/embedding_distance/__init__.py +0 -13
- langchain/evaluation/embedding_distance/base.py +0 -602
- langchain/evaluation/exact_match/__init__.py +0 -0
- langchain/evaluation/exact_match/base.py +0 -97
- langchain/evaluation/loading.py +0 -206
- langchain/evaluation/parsing/__init__.py +0 -0
- langchain/evaluation/parsing/base.py +0 -162
- langchain/evaluation/parsing/json_distance.py +0 -97
- langchain/evaluation/parsing/json_schema.py +0 -100
- langchain/evaluation/qa/__init__.py +0 -10
- langchain/evaluation/qa/eval_chain.py +0 -364
- langchain/evaluation/qa/eval_prompt.py +0 -78
- langchain/evaluation/qa/generate_chain.py +0 -34
- langchain/evaluation/qa/generate_prompt.py +0 -21
- langchain/evaluation/regex_match/__init__.py +0 -0
- langchain/evaluation/regex_match/base.py +0 -86
- langchain/evaluation/schema.py +0 -491
- langchain/evaluation/scoring/__init__.py +0 -31
- langchain/evaluation/scoring/eval_chain.py +0 -475
- langchain/evaluation/scoring/prompt.py +0 -53
- langchain/evaluation/string_distance/__init__.py +0 -13
- langchain/evaluation/string_distance/base.py +0 -466
- langchain/example_generator.py +0 -5
- langchain/formatting.py +0 -5
- langchain/globals.py +0 -180
- langchain/graphs/__init__.py +0 -57
- langchain/graphs/arangodb_graph.py +0 -28
- langchain/graphs/falkordb_graph.py +0 -23
- langchain/graphs/graph_document.py +0 -33
- langchain/graphs/graph_store.py +0 -23
- langchain/graphs/hugegraph.py +0 -23
- langchain/graphs/kuzu_graph.py +0 -23
- langchain/graphs/memgraph_graph.py +0 -23
- langchain/graphs/nebula_graph.py +0 -23
- langchain/graphs/neo4j_graph.py +0 -23
- langchain/graphs/neptune_graph.py +0 -23
- langchain/graphs/networkx_graph.py +0 -36
- langchain/graphs/rdf_graph.py +0 -23
- langchain/hub.py +0 -131
- langchain/indexes/__init__.py +0 -50
- langchain/indexes/_api.py +0 -5
- langchain/indexes/_sql_record_manager.py +0 -539
- langchain/indexes/graph.py +0 -28
- langchain/indexes/prompts/__init__.py +0 -13
- langchain/indexes/prompts/entity_extraction.py +0 -39
- langchain/indexes/prompts/entity_summarization.py +0 -24
- langchain/indexes/prompts/knowledge_triplet_extraction.py +0 -36
- langchain/indexes/vectorstore.py +0 -269
- langchain/input.py +0 -15
- langchain/llms/__init__.py +0 -734
- langchain/llms/ai21.py +0 -28
- langchain/llms/aleph_alpha.py +0 -23
- langchain/llms/amazon_api_gateway.py +0 -23
- langchain/llms/anthropic.py +0 -23
- langchain/llms/anyscale.py +0 -23
- langchain/llms/arcee.py +0 -23
- langchain/llms/aviary.py +0 -23
- langchain/llms/azureml_endpoint.py +0 -48
- langchain/llms/baidu_qianfan_endpoint.py +0 -23
- langchain/llms/bananadev.py +0 -23
- langchain/llms/base.py +0 -20
- langchain/llms/baseten.py +0 -23
- langchain/llms/beam.py +0 -23
- langchain/llms/bedrock.py +0 -28
- langchain/llms/bittensor.py +0 -23
- langchain/llms/cerebriumai.py +0 -23
- langchain/llms/chatglm.py +0 -23
- langchain/llms/clarifai.py +0 -23
- langchain/llms/cloudflare_workersai.py +0 -25
- langchain/llms/cohere.py +0 -23
- langchain/llms/ctransformers.py +0 -23
- langchain/llms/ctranslate2.py +0 -23
- langchain/llms/databricks.py +0 -23
- langchain/llms/deepinfra.py +0 -23
- langchain/llms/deepsparse.py +0 -23
- langchain/llms/edenai.py +0 -23
- langchain/llms/fake.py +0 -28
- langchain/llms/fireworks.py +0 -23
- langchain/llms/forefrontai.py +0 -23
- langchain/llms/gigachat.py +0 -23
- langchain/llms/google_palm.py +0 -23
- langchain/llms/gooseai.py +0 -23
- langchain/llms/gpt4all.py +0 -23
- langchain/llms/gradient_ai.py +0 -28
- langchain/llms/grammars/json.gbnf +0 -29
- langchain/llms/grammars/list.gbnf +0 -14
- langchain/llms/huggingface_endpoint.py +0 -23
- langchain/llms/huggingface_hub.py +0 -23
- langchain/llms/huggingface_pipeline.py +0 -23
- langchain/llms/huggingface_text_gen_inference.py +0 -23
- langchain/llms/human.py +0 -23
- langchain/llms/javelin_ai_gateway.py +0 -28
- langchain/llms/koboldai.py +0 -23
- langchain/llms/llamacpp.py +0 -23
- langchain/llms/loading.py +0 -27
- langchain/llms/manifest.py +0 -23
- langchain/llms/minimax.py +0 -23
- langchain/llms/mlflow.py +0 -23
- langchain/llms/mlflow_ai_gateway.py +0 -23
- langchain/llms/modal.py +0 -23
- langchain/llms/mosaicml.py +0 -23
- langchain/llms/nlpcloud.py +0 -23
- langchain/llms/octoai_endpoint.py +0 -23
- langchain/llms/ollama.py +0 -23
- langchain/llms/opaqueprompts.py +0 -23
- langchain/llms/openai.py +0 -32
- langchain/llms/openllm.py +0 -23
- langchain/llms/openlm.py +0 -23
- langchain/llms/pai_eas_endpoint.py +0 -23
- langchain/llms/petals.py +0 -23
- langchain/llms/pipelineai.py +0 -23
- langchain/llms/predibase.py +0 -23
- langchain/llms/predictionguard.py +0 -23
- langchain/llms/promptlayer_openai.py +0 -27
- langchain/llms/replicate.py +0 -23
- langchain/llms/rwkv.py +0 -23
- langchain/llms/sagemaker_endpoint.py +0 -28
- langchain/llms/self_hosted.py +0 -23
- langchain/llms/self_hosted_hugging_face.py +0 -23
- langchain/llms/stochasticai.py +0 -23
- langchain/llms/symblai_nebula.py +0 -23
- langchain/llms/textgen.py +0 -23
- langchain/llms/titan_takeoff.py +0 -23
- langchain/llms/titan_takeoff_pro.py +0 -23
- langchain/llms/together.py +0 -23
- langchain/llms/tongyi.py +0 -23
- langchain/llms/utils.py +0 -23
- langchain/llms/vertexai.py +0 -27
- langchain/llms/vllm.py +0 -27
- langchain/llms/volcengine_maas.py +0 -28
- langchain/llms/watsonxllm.py +0 -23
- langchain/llms/writer.py +0 -23
- langchain/llms/xinference.py +0 -23
- langchain/llms/yandex.py +0 -23
- langchain/load/__init__.py +0 -11
- langchain/load/dump.py +0 -3
- langchain/load/load.py +0 -3
- langchain/load/serializable.py +0 -19
- langchain/memory/__init__.py +0 -153
- langchain/memory/buffer.py +0 -173
- langchain/memory/buffer_window.py +0 -60
- langchain/memory/chat_memory.py +0 -104
- langchain/memory/chat_message_histories/__init__.py +0 -84
- langchain/memory/chat_message_histories/astradb.py +0 -25
- langchain/memory/chat_message_histories/cassandra.py +0 -25
- langchain/memory/chat_message_histories/cosmos_db.py +0 -25
- langchain/memory/chat_message_histories/dynamodb.py +0 -25
- langchain/memory/chat_message_histories/elasticsearch.py +0 -27
- langchain/memory/chat_message_histories/file.py +0 -25
- langchain/memory/chat_message_histories/firestore.py +0 -25
- langchain/memory/chat_message_histories/in_memory.py +0 -5
- langchain/memory/chat_message_histories/momento.py +0 -25
- langchain/memory/chat_message_histories/mongodb.py +0 -25
- langchain/memory/chat_message_histories/neo4j.py +0 -25
- langchain/memory/chat_message_histories/postgres.py +0 -25
- langchain/memory/chat_message_histories/redis.py +0 -25
- langchain/memory/chat_message_histories/rocksetdb.py +0 -25
- langchain/memory/chat_message_histories/singlestoredb.py +0 -27
- langchain/memory/chat_message_histories/sql.py +0 -33
- langchain/memory/chat_message_histories/streamlit.py +0 -25
- langchain/memory/chat_message_histories/upstash_redis.py +0 -27
- langchain/memory/chat_message_histories/xata.py +0 -25
- langchain/memory/chat_message_histories/zep.py +0 -25
- langchain/memory/combined.py +0 -85
- langchain/memory/entity.py +0 -564
- langchain/memory/kg.py +0 -23
- langchain/memory/motorhead_memory.py +0 -23
- langchain/memory/prompt.py +0 -164
- langchain/memory/readonly.py +0 -24
- langchain/memory/simple.py +0 -24
- langchain/memory/summary.py +0 -140
- langchain/memory/summary_buffer.py +0 -148
- langchain/memory/token_buffer.py +0 -72
- langchain/memory/utils.py +0 -21
- langchain/memory/vectorstore.py +0 -120
- langchain/memory/vectorstore_token_buffer_memory.py +0 -184
- langchain/memory/zep_memory.py +0 -23
- langchain/model_laboratory.py +0 -99
- langchain/output_parsers/__init__.py +0 -87
- langchain/output_parsers/boolean.py +0 -54
- langchain/output_parsers/combining.py +0 -57
- langchain/output_parsers/datetime.py +0 -58
- langchain/output_parsers/enum.py +0 -41
- langchain/output_parsers/ernie_functions.py +0 -45
- langchain/output_parsers/fix.py +0 -148
- langchain/output_parsers/format_instructions.py +0 -79
- langchain/output_parsers/json.py +0 -15
- langchain/output_parsers/list.py +0 -13
- langchain/output_parsers/loading.py +0 -22
- langchain/output_parsers/openai_functions.py +0 -13
- langchain/output_parsers/openai_tools.py +0 -7
- langchain/output_parsers/pandas_dataframe.py +0 -156
- langchain/output_parsers/prompts.py +0 -21
- langchain/output_parsers/pydantic.py +0 -3
- langchain/output_parsers/rail_parser.py +0 -25
- langchain/output_parsers/regex.py +0 -39
- langchain/output_parsers/regex_dict.py +0 -43
- langchain/output_parsers/retry.py +0 -296
- langchain/output_parsers/structured.py +0 -106
- langchain/output_parsers/xml.py +0 -3
- langchain/output_parsers/yaml.py +0 -73
- langchain/prompts/__init__.py +0 -102
- langchain/prompts/base.py +0 -21
- langchain/prompts/chat.py +0 -37
- langchain/prompts/example_selector/__init__.py +0 -42
- langchain/prompts/example_selector/base.py +0 -3
- langchain/prompts/example_selector/length_based.py +0 -5
- langchain/prompts/example_selector/ngram_overlap.py +0 -32
- langchain/prompts/example_selector/semantic_similarity.py +0 -11
- langchain/prompts/few_shot.py +0 -11
- langchain/prompts/few_shot_with_templates.py +0 -3
- langchain/prompts/loading.py +0 -23
- langchain/prompts/pipeline.py +0 -3
- langchain/prompts/prompt.py +0 -6
- langchain/pydantic_v1/__init__.py +0 -38
- langchain/pydantic_v1/dataclasses.py +0 -20
- langchain/pydantic_v1/main.py +0 -20
- langchain/python.py +0 -19
- langchain/requests.py +0 -35
- langchain/retrievers/__init__.py +0 -178
- langchain/retrievers/arcee.py +0 -23
- langchain/retrievers/arxiv.py +0 -23
- langchain/retrievers/azure_ai_search.py +0 -30
- langchain/retrievers/bedrock.py +0 -33
- langchain/retrievers/bm25.py +0 -28
- langchain/retrievers/chaindesk.py +0 -23
- langchain/retrievers/chatgpt_plugin_retriever.py +0 -23
- langchain/retrievers/cohere_rag_retriever.py +0 -23
- langchain/retrievers/contextual_compression.py +0 -81
- langchain/retrievers/databerry.py +0 -23
- langchain/retrievers/docarray.py +0 -28
- langchain/retrievers/document_compressors/__init__.py +0 -44
- langchain/retrievers/document_compressors/base.py +0 -82
- langchain/retrievers/document_compressors/chain_extract.py +0 -121
- langchain/retrievers/document_compressors/chain_extract_prompt.py +0 -10
- langchain/retrievers/document_compressors/chain_filter.py +0 -133
- langchain/retrievers/document_compressors/chain_filter_prompt.py +0 -8
- langchain/retrievers/document_compressors/cohere_rerank.py +0 -124
- langchain/retrievers/document_compressors/cross_encoder.py +0 -16
- langchain/retrievers/document_compressors/cross_encoder_rerank.py +0 -48
- langchain/retrievers/document_compressors/embeddings_filter.py +0 -137
- langchain/retrievers/document_compressors/flashrank_rerank.py +0 -27
- langchain/retrievers/document_compressors/listwise_rerank.py +0 -144
- langchain/retrievers/elastic_search_bm25.py +0 -23
- langchain/retrievers/embedchain.py +0 -23
- langchain/retrievers/ensemble.py +0 -336
- langchain/retrievers/google_cloud_documentai_warehouse.py +0 -25
- langchain/retrievers/google_vertex_ai_search.py +0 -33
- langchain/retrievers/kay.py +0 -23
- langchain/retrievers/kendra.py +0 -66
- langchain/retrievers/knn.py +0 -23
- langchain/retrievers/llama_index.py +0 -30
- langchain/retrievers/merger_retriever.py +0 -123
- langchain/retrievers/metal.py +0 -23
- langchain/retrievers/milvus.py +0 -28
- langchain/retrievers/multi_query.py +0 -231
- langchain/retrievers/multi_vector.py +0 -132
- langchain/retrievers/outline.py +0 -23
- langchain/retrievers/parent_document_retriever.py +0 -157
- langchain/retrievers/pinecone_hybrid_search.py +0 -23
- langchain/retrievers/pubmed.py +0 -23
- langchain/retrievers/pupmed.py +0 -23
- langchain/retrievers/re_phraser.py +0 -89
- langchain/retrievers/remote_retriever.py +0 -23
- langchain/retrievers/self_query/__init__.py +0 -0
- langchain/retrievers/self_query/astradb.py +0 -23
- langchain/retrievers/self_query/base.py +0 -397
- langchain/retrievers/self_query/chroma.py +0 -23
- langchain/retrievers/self_query/dashvector.py +0 -23
- langchain/retrievers/self_query/databricks_vector_search.py +0 -27
- langchain/retrievers/self_query/deeplake.py +0 -27
- langchain/retrievers/self_query/dingo.py +0 -23
- langchain/retrievers/self_query/elasticsearch.py +0 -25
- langchain/retrievers/self_query/milvus.py +0 -27
- langchain/retrievers/self_query/mongodb_atlas.py +0 -25
- langchain/retrievers/self_query/myscale.py +0 -23
- langchain/retrievers/self_query/opensearch.py +0 -23
- langchain/retrievers/self_query/pgvector.py +0 -23
- langchain/retrievers/self_query/pinecone.py +0 -23
- langchain/retrievers/self_query/qdrant.py +0 -23
- langchain/retrievers/self_query/redis.py +0 -23
- langchain/retrievers/self_query/supabase.py +0 -23
- langchain/retrievers/self_query/tencentvectordb.py +0 -27
- langchain/retrievers/self_query/timescalevector.py +0 -27
- langchain/retrievers/self_query/vectara.py +0 -27
- langchain/retrievers/self_query/weaviate.py +0 -23
- langchain/retrievers/svm.py +0 -23
- langchain/retrievers/tavily_search_api.py +0 -28
- langchain/retrievers/tfidf.py +0 -23
- langchain/retrievers/time_weighted_retriever.py +0 -193
- langchain/retrievers/vespa_retriever.py +0 -23
- langchain/retrievers/weaviate_hybrid_search.py +0 -23
- langchain/retrievers/web_research.py +0 -29
- langchain/retrievers/wikipedia.py +0 -23
- langchain/retrievers/you.py +0 -23
- langchain/retrievers/zep.py +0 -30
- langchain/retrievers/zilliz.py +0 -28
- langchain/runnables/__init__.py +0 -18
- langchain/runnables/hub.py +0 -32
- langchain/runnables/openai_functions.py +0 -51
- langchain/schema/__init__.py +0 -82
- langchain/schema/agent.py +0 -3
- langchain/schema/cache.py +0 -3
- langchain/schema/callbacks/__init__.py +0 -0
- langchain/schema/callbacks/base.py +0 -23
- langchain/schema/callbacks/manager.py +0 -55
- langchain/schema/callbacks/stdout.py +0 -3
- langchain/schema/callbacks/streaming_stdout.py +0 -3
- langchain/schema/callbacks/tracers/__init__.py +0 -0
- langchain/schema/callbacks/tracers/base.py +0 -4
- langchain/schema/callbacks/tracers/evaluation.py +0 -6
- langchain/schema/callbacks/tracers/langchain.py +0 -8
- langchain/schema/callbacks/tracers/langchain_v1.py +0 -3
- langchain/schema/callbacks/tracers/log_stream.py +0 -9
- langchain/schema/callbacks/tracers/root_listeners.py +0 -3
- langchain/schema/callbacks/tracers/run_collector.py +0 -3
- langchain/schema/callbacks/tracers/schemas.py +0 -27
- langchain/schema/callbacks/tracers/stdout.py +0 -13
- langchain/schema/chat.py +0 -3
- langchain/schema/chat_history.py +0 -3
- langchain/schema/document.py +0 -3
- langchain/schema/embeddings.py +0 -3
- langchain/schema/exceptions.py +0 -3
- langchain/schema/language_model.py +0 -15
- langchain/schema/memory.py +0 -3
- langchain/schema/messages.py +0 -51
- langchain/schema/output.py +0 -19
- langchain/schema/output_parser.py +0 -25
- langchain/schema/prompt.py +0 -3
- langchain/schema/prompt_template.py +0 -3
- langchain/schema/retriever.py +0 -3
- langchain/schema/runnable/__init__.py +0 -58
- langchain/schema/runnable/base.py +0 -38
- langchain/schema/runnable/branch.py +0 -3
- langchain/schema/runnable/config.py +0 -27
- langchain/schema/runnable/configurable.py +0 -15
- langchain/schema/runnable/fallbacks.py +0 -3
- langchain/schema/runnable/history.py +0 -11
- langchain/schema/runnable/passthrough.py +0 -8
- langchain/schema/runnable/retry.py +0 -3
- langchain/schema/runnable/router.py +0 -3
- langchain/schema/runnable/utils.py +0 -51
- langchain/schema/storage.py +0 -3
- langchain/schema/vectorstore.py +0 -3
- langchain/serpapi.py +0 -25
- langchain/smith/__init__.py +0 -102
- langchain/smith/evaluation/__init__.py +0 -68
- langchain/smith/evaluation/config.py +0 -382
- langchain/smith/evaluation/name_generation.py +0 -727
- langchain/smith/evaluation/progress.py +0 -137
- langchain/smith/evaluation/runner_utils.py +0 -1572
- langchain/smith/evaluation/string_run_evaluator.py +0 -440
- langchain/smith/evaluation/utils.py +0 -0
- langchain/sql_database.py +0 -25
- langchain/storage/__init__.py +0 -57
- langchain/storage/_lc_store.py +0 -91
- langchain/storage/encoder_backed.py +0 -127
- langchain/storage/exceptions.py +0 -3
- langchain/storage/file_system.py +0 -176
- langchain/storage/in_memory.py +0 -13
- langchain/storage/redis.py +0 -23
- langchain/storage/upstash_redis.py +0 -27
- langchain/text_splitter.py +0 -50
- langchain/tools/ainetwork/__init__.py +0 -0
- langchain/tools/ainetwork/app.py +0 -30
- langchain/tools/ainetwork/base.py +0 -27
- langchain/tools/ainetwork/owner.py +0 -28
- langchain/tools/ainetwork/rule.py +0 -28
- langchain/tools/ainetwork/transfer.py +0 -28
- langchain/tools/ainetwork/value.py +0 -28
- langchain/tools/amadeus/__init__.py +0 -30
- langchain/tools/amadeus/base.py +0 -23
- langchain/tools/amadeus/closest_airport.py +0 -30
- langchain/tools/amadeus/flight_search.py +0 -30
- langchain/tools/arxiv/__init__.py +0 -1
- langchain/tools/arxiv/tool.py +0 -28
- langchain/tools/azure_cognitive_services/__init__.py +0 -41
- langchain/tools/azure_cognitive_services/form_recognizer.py +0 -23
- langchain/tools/azure_cognitive_services/image_analysis.py +0 -23
- langchain/tools/azure_cognitive_services/speech2text.py +0 -23
- langchain/tools/azure_cognitive_services/text2speech.py +0 -23
- langchain/tools/azure_cognitive_services/text_analytics_health.py +0 -23
- langchain/tools/base.py +0 -19
- langchain/tools/bearly/__init__.py +0 -0
- langchain/tools/bearly/tool.py +0 -33
- langchain/tools/bing_search/__init__.py +0 -29
- langchain/tools/bing_search/tool.py +0 -27
- langchain/tools/brave_search/__init__.py +0 -0
- langchain/tools/brave_search/tool.py +0 -23
- langchain/tools/clickup/__init__.py +0 -0
- langchain/tools/clickup/tool.py +0 -23
- langchain/tools/convert_to_openai.py +0 -4
- langchain/tools/dataforseo_api_search/__init__.py +0 -34
- langchain/tools/dataforseo_api_search/tool.py +0 -32
- langchain/tools/ddg_search/__init__.py +0 -25
- langchain/tools/ddg_search/tool.py +0 -32
- langchain/tools/e2b_data_analysis/__init__.py +0 -0
- langchain/tools/e2b_data_analysis/tool.py +0 -33
- langchain/tools/edenai/__init__.py +0 -50
- langchain/tools/edenai/audio_speech_to_text.py +0 -23
- langchain/tools/edenai/audio_text_to_speech.py +0 -23
- langchain/tools/edenai/edenai_base_tool.py +0 -23
- langchain/tools/edenai/image_explicitcontent.py +0 -23
- langchain/tools/edenai/image_objectdetection.py +0 -23
- langchain/tools/edenai/ocr_identityparser.py +0 -23
- langchain/tools/edenai/ocr_invoiceparser.py +0 -23
- langchain/tools/edenai/text_moderation.py +0 -23
- langchain/tools/eleven_labs/__init__.py +0 -25
- langchain/tools/eleven_labs/models.py +0 -23
- langchain/tools/eleven_labs/text2speech.py +0 -23
- langchain/tools/file_management/__init__.py +0 -47
- langchain/tools/file_management/copy.py +0 -28
- langchain/tools/file_management/delete.py +0 -28
- langchain/tools/file_management/file_search.py +0 -28
- langchain/tools/file_management/list_dir.py +0 -28
- langchain/tools/file_management/move.py +0 -28
- langchain/tools/file_management/read.py +0 -28
- langchain/tools/file_management/write.py +0 -28
- langchain/tools/github/__init__.py +0 -1
- langchain/tools/github/tool.py +0 -23
- langchain/tools/gitlab/__init__.py +0 -1
- langchain/tools/gitlab/tool.py +0 -23
- langchain/tools/gmail/__init__.py +0 -41
- langchain/tools/gmail/base.py +0 -23
- langchain/tools/gmail/create_draft.py +0 -28
- langchain/tools/gmail/get_message.py +0 -28
- langchain/tools/gmail/get_thread.py +0 -28
- langchain/tools/gmail/search.py +0 -30
- langchain/tools/gmail/send_message.py +0 -28
- langchain/tools/golden_query/__init__.py +0 -25
- langchain/tools/golden_query/tool.py +0 -23
- langchain/tools/google_cloud/__init__.py +0 -25
- langchain/tools/google_cloud/texttospeech.py +0 -23
- langchain/tools/google_finance/__init__.py +0 -27
- langchain/tools/google_finance/tool.py +0 -25
- langchain/tools/google_jobs/__init__.py +0 -25
- langchain/tools/google_jobs/tool.py +0 -23
- langchain/tools/google_lens/__init__.py +0 -25
- langchain/tools/google_lens/tool.py +0 -23
- langchain/tools/google_places/__init__.py +0 -25
- langchain/tools/google_places/tool.py +0 -28
- langchain/tools/google_scholar/__init__.py +0 -27
- langchain/tools/google_scholar/tool.py +0 -25
- langchain/tools/google_search/__init__.py +0 -29
- langchain/tools/google_search/tool.py +0 -27
- langchain/tools/google_serper/__init__.py +0 -30
- langchain/tools/google_serper/tool.py +0 -27
- langchain/tools/google_trends/__init__.py +0 -27
- langchain/tools/google_trends/tool.py +0 -25
- langchain/tools/graphql/__init__.py +0 -1
- langchain/tools/graphql/tool.py +0 -23
- langchain/tools/human/__init__.py +0 -25
- langchain/tools/human/tool.py +0 -23
- langchain/tools/ifttt.py +0 -23
- langchain/tools/interaction/__init__.py +0 -1
- langchain/tools/interaction/tool.py +0 -23
- langchain/tools/jira/__init__.py +0 -1
- langchain/tools/jira/tool.py +0 -42
- langchain/tools/json/__init__.py +0 -1
- langchain/tools/json/tool.py +0 -52
- langchain/tools/memorize/__init__.py +0 -25
- langchain/tools/memorize/tool.py +0 -27
- langchain/tools/merriam_webster/__init__.py +0 -1
- langchain/tools/merriam_webster/tool.py +0 -23
- langchain/tools/metaphor_search/__init__.py +0 -25
- langchain/tools/metaphor_search/tool.py +0 -23
- langchain/tools/multion/__init__.py +0 -33
- langchain/tools/multion/close_session.py +0 -30
- langchain/tools/multion/create_session.py +0 -30
- langchain/tools/multion/update_session.py +0 -30
- langchain/tools/nasa/__init__.py +0 -0
- langchain/tools/nasa/tool.py +0 -23
- langchain/tools/nuclia/__init__.py +0 -23
- langchain/tools/nuclia/tool.py +0 -27
- langchain/tools/office365/__init__.py +0 -41
- langchain/tools/office365/base.py +0 -23
- langchain/tools/office365/create_draft_message.py +0 -32
- langchain/tools/office365/events_search.py +0 -28
- langchain/tools/office365/messages_search.py +0 -28
- langchain/tools/office365/send_event.py +0 -28
- langchain/tools/office365/send_message.py +0 -28
- langchain/tools/openapi/__init__.py +0 -0
- langchain/tools/openapi/utils/__init__.py +0 -0
- langchain/tools/openapi/utils/api_models.py +0 -54
- langchain/tools/openapi/utils/openapi_utils.py +0 -30
- langchain/tools/openweathermap/__init__.py +0 -25
- langchain/tools/openweathermap/tool.py +0 -23
- langchain/tools/playwright/__init__.py +0 -47
- langchain/tools/playwright/base.py +0 -23
- langchain/tools/playwright/click.py +0 -28
- langchain/tools/playwright/current_page.py +0 -23
- langchain/tools/playwright/extract_hyperlinks.py +0 -32
- langchain/tools/playwright/extract_text.py +0 -23
- langchain/tools/playwright/get_elements.py +0 -28
- langchain/tools/playwright/navigate.py +0 -28
- langchain/tools/playwright/navigate_back.py +0 -23
- langchain/tools/plugin.py +0 -32
- langchain/tools/powerbi/__init__.py +0 -1
- langchain/tools/powerbi/tool.py +0 -33
- langchain/tools/pubmed/__init__.py +0 -1
- langchain/tools/pubmed/tool.py +0 -23
- langchain/tools/python/__init__.py +0 -13
- langchain/tools/reddit_search/__init__.py +0 -0
- langchain/tools/reddit_search/tool.py +0 -27
- langchain/tools/render.py +0 -23
- langchain/tools/requests/__init__.py +0 -1
- langchain/tools/requests/tool.py +0 -42
- langchain/tools/retriever.py +0 -11
- langchain/tools/scenexplain/__init__.py +0 -1
- langchain/tools/scenexplain/tool.py +0 -28
- langchain/tools/searchapi/__init__.py +0 -30
- langchain/tools/searchapi/tool.py +0 -27
- langchain/tools/searx_search/__init__.py +0 -0
- langchain/tools/searx_search/tool.py +0 -27
- langchain/tools/shell/__init__.py +0 -25
- langchain/tools/shell/tool.py +0 -28
- langchain/tools/slack/__init__.py +0 -38
- langchain/tools/slack/base.py +0 -23
- langchain/tools/slack/get_channel.py +0 -23
- langchain/tools/slack/get_message.py +0 -28
- langchain/tools/slack/schedule_message.py +0 -28
- langchain/tools/slack/send_message.py +0 -28
- langchain/tools/sleep/__init__.py +0 -1
- langchain/tools/sleep/tool.py +0 -28
- langchain/tools/spark_sql/__init__.py +0 -1
- langchain/tools/spark_sql/tool.py +0 -39
- langchain/tools/sql_database/__init__.py +0 -1
- langchain/tools/sql_database/prompt.py +0 -24
- langchain/tools/sql_database/tool.py +0 -39
- langchain/tools/stackexchange/__init__.py +0 -1
- langchain/tools/stackexchange/tool.py +0 -23
- langchain/tools/steam/__init__.py +0 -1
- langchain/tools/steam/tool.py +0 -23
- langchain/tools/steamship_image_generation/__init__.py +0 -25
- langchain/tools/steamship_image_generation/tool.py +0 -28
- langchain/tools/tavily_search/__init__.py +0 -32
- langchain/tools/tavily_search/tool.py +0 -33
- langchain/tools/vectorstore/__init__.py +0 -1
- langchain/tools/vectorstore/tool.py +0 -30
- langchain/tools/wikipedia/__init__.py +0 -1
- langchain/tools/wikipedia/tool.py +0 -23
- langchain/tools/wolfram_alpha/__init__.py +0 -25
- langchain/tools/wolfram_alpha/tool.py +0 -23
- langchain/tools/yahoo_finance_news.py +0 -23
- langchain/tools/youtube/__init__.py +0 -0
- langchain/tools/youtube/search.py +0 -23
- langchain/tools/zapier/__init__.py +0 -29
- langchain/tools/zapier/tool.py +0 -49
- langchain/utilities/__init__.py +0 -168
- langchain/utilities/alpha_vantage.py +0 -23
- langchain/utilities/anthropic.py +0 -30
- langchain/utilities/apify.py +0 -23
- langchain/utilities/arcee.py +0 -45
- langchain/utilities/arxiv.py +0 -23
- langchain/utilities/asyncio.py +0 -11
- langchain/utilities/awslambda.py +0 -23
- langchain/utilities/bibtex.py +0 -23
- langchain/utilities/bing_search.py +0 -23
- langchain/utilities/brave_search.py +0 -23
- langchain/utilities/clickup.py +0 -45
- langchain/utilities/dalle_image_generator.py +0 -25
- langchain/utilities/dataforseo_api_search.py +0 -25
- langchain/utilities/duckduckgo_search.py +0 -23
- langchain/utilities/github.py +0 -23
- langchain/utilities/gitlab.py +0 -23
- langchain/utilities/golden_query.py +0 -23
- langchain/utilities/google_finance.py +0 -23
- langchain/utilities/google_jobs.py +0 -23
- langchain/utilities/google_lens.py +0 -23
- langchain/utilities/google_places_api.py +0 -23
- langchain/utilities/google_scholar.py +0 -23
- langchain/utilities/google_search.py +0 -23
- langchain/utilities/google_serper.py +0 -23
- langchain/utilities/google_trends.py +0 -23
- langchain/utilities/graphql.py +0 -23
- langchain/utilities/jira.py +0 -23
- langchain/utilities/loading.py +0 -4
- langchain/utilities/max_compute.py +0 -23
- langchain/utilities/merriam_webster.py +0 -23
- langchain/utilities/metaphor_search.py +0 -23
- langchain/utilities/nasa.py +0 -23
- langchain/utilities/opaqueprompts.py +0 -27
- langchain/utilities/openapi.py +0 -28
- langchain/utilities/openweathermap.py +0 -23
- langchain/utilities/outline.py +0 -23
- langchain/utilities/portkey.py +0 -23
- langchain/utilities/powerbi.py +0 -23
- langchain/utilities/pubmed.py +0 -23
- langchain/utilities/python.py +0 -19
- langchain/utilities/reddit_search.py +0 -25
- langchain/utilities/redis.py +0 -33
- langchain/utilities/requests.py +0 -27
- langchain/utilities/scenexplain.py +0 -23
- langchain/utilities/searchapi.py +0 -23
- langchain/utilities/searx_search.py +0 -28
- langchain/utilities/serpapi.py +0 -28
- langchain/utilities/spark_sql.py +0 -23
- langchain/utilities/sql_database.py +0 -28
- langchain/utilities/stackexchange.py +0 -23
- langchain/utilities/steam.py +0 -23
- langchain/utilities/tavily_search.py +0 -25
- langchain/utilities/tensorflow_datasets.py +0 -23
- langchain/utilities/twilio.py +0 -23
- langchain/utilities/vertexai.py +0 -36
- langchain/utilities/wikipedia.py +0 -23
- langchain/utilities/wolfram_alpha.py +0 -23
- langchain/utilities/zapier.py +0 -23
- langchain/utils/__init__.py +0 -77
- langchain/utils/aiter.py +0 -3
- langchain/utils/env.py +0 -3
- langchain/utils/ernie_functions.py +0 -36
- langchain/utils/formatting.py +0 -3
- langchain/utils/html.py +0 -19
- langchain/utils/input.py +0 -8
- langchain/utils/iter.py +0 -3
- langchain/utils/json_schema.py +0 -11
- langchain/utils/loading.py +0 -3
- langchain/utils/math.py +0 -32
- langchain/utils/openai.py +0 -23
- langchain/utils/openai_functions.py +0 -13
- langchain/utils/pydantic.py +0 -3
- langchain/utils/strings.py +0 -3
- langchain/utils/utils.py +0 -21
- langchain/vectorstores/__init__.py +0 -262
- langchain/vectorstores/alibabacloud_opensearch.py +0 -30
- langchain/vectorstores/analyticdb.py +0 -23
- langchain/vectorstores/annoy.py +0 -23
- langchain/vectorstores/astradb.py +0 -23
- langchain/vectorstores/atlas.py +0 -23
- langchain/vectorstores/awadb.py +0 -23
- langchain/vectorstores/azure_cosmos_db.py +0 -28
- langchain/vectorstores/azuresearch.py +0 -30
- langchain/vectorstores/bageldb.py +0 -23
- langchain/vectorstores/baiducloud_vector_search.py +0 -23
- langchain/vectorstores/base.py +0 -3
- langchain/vectorstores/cassandra.py +0 -23
- langchain/vectorstores/chroma.py +0 -23
- langchain/vectorstores/clarifai.py +0 -23
- langchain/vectorstores/clickhouse.py +0 -27
- langchain/vectorstores/dashvector.py +0 -23
- langchain/vectorstores/databricks_vector_search.py +0 -23
- langchain/vectorstores/deeplake.py +0 -23
- langchain/vectorstores/dingo.py +0 -23
- langchain/vectorstores/docarray/__init__.py +0 -30
- langchain/vectorstores/docarray/base.py +0 -23
- langchain/vectorstores/docarray/hnsw.py +0 -23
- langchain/vectorstores/docarray/in_memory.py +0 -23
- langchain/vectorstores/elastic_vector_search.py +0 -27
- langchain/vectorstores/elasticsearch.py +0 -39
- langchain/vectorstores/epsilla.py +0 -23
- langchain/vectorstores/faiss.py +0 -23
- langchain/vectorstores/hippo.py +0 -23
- langchain/vectorstores/hologres.py +0 -23
- langchain/vectorstores/lancedb.py +0 -23
- langchain/vectorstores/llm_rails.py +0 -28
- langchain/vectorstores/marqo.py +0 -23
- langchain/vectorstores/matching_engine.py +0 -23
- langchain/vectorstores/meilisearch.py +0 -23
- langchain/vectorstores/milvus.py +0 -23
- langchain/vectorstores/momento_vector_index.py +0 -23
- langchain/vectorstores/mongodb_atlas.py +0 -23
- langchain/vectorstores/myscale.py +0 -30
- langchain/vectorstores/neo4j_vector.py +0 -28
- langchain/vectorstores/nucliadb.py +0 -23
- langchain/vectorstores/opensearch_vector_search.py +0 -23
- langchain/vectorstores/pgembedding.py +0 -36
- langchain/vectorstores/pgvecto_rs.py +0 -23
- langchain/vectorstores/pgvector.py +0 -28
- langchain/vectorstores/pinecone.py +0 -23
- langchain/vectorstores/qdrant.py +0 -28
- langchain/vectorstores/redis/__init__.py +0 -42
- langchain/vectorstores/redis/base.py +0 -33
- langchain/vectorstores/redis/filters.py +0 -48
- langchain/vectorstores/redis/schema.py +0 -54
- langchain/vectorstores/rocksetdb.py +0 -23
- langchain/vectorstores/scann.py +0 -23
- langchain/vectorstores/semadb.py +0 -23
- langchain/vectorstores/singlestoredb.py +0 -23
- langchain/vectorstores/sklearn.py +0 -42
- langchain/vectorstores/sqlitevss.py +0 -23
- langchain/vectorstores/starrocks.py +0 -28
- langchain/vectorstores/supabase.py +0 -23
- langchain/vectorstores/tair.py +0 -23
- langchain/vectorstores/tencentvectordb.py +0 -33
- langchain/vectorstores/tigris.py +0 -23
- langchain/vectorstores/tiledb.py +0 -23
- langchain/vectorstores/timescalevector.py +0 -23
- langchain/vectorstores/typesense.py +0 -23
- langchain/vectorstores/usearch.py +0 -23
- langchain/vectorstores/utils.py +0 -33
- langchain/vectorstores/vald.py +0 -23
- langchain/vectorstores/vearch.py +0 -23
- langchain/vectorstores/vectara.py +0 -28
- langchain/vectorstores/vespa.py +0 -23
- langchain/vectorstores/weaviate.py +0 -23
- langchain/vectorstores/xata.py +0 -23
- langchain/vectorstores/yellowbrick.py +0 -23
- langchain/vectorstores/zep.py +0 -28
- langchain/vectorstores/zilliz.py +0 -23
- langchain-0.3.27.dist-info/METADATA +0 -144
- langchain-0.3.27.dist-info/RECORD +0 -1342
- langchain-0.3.27.dist-info/entry_points.txt +0 -4
- {langchain-0.3.27.dist-info → langchain-1.0.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,1572 +0,0 @@
|
|
|
1
|
-
"""Utilities for running language models or Chains over datasets."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import concurrent.futures
|
|
6
|
-
import dataclasses
|
|
7
|
-
import functools
|
|
8
|
-
import inspect
|
|
9
|
-
import logging
|
|
10
|
-
import uuid
|
|
11
|
-
from datetime import datetime, timezone
|
|
12
|
-
from typing import (
|
|
13
|
-
TYPE_CHECKING,
|
|
14
|
-
Any,
|
|
15
|
-
Callable,
|
|
16
|
-
Optional,
|
|
17
|
-
Union,
|
|
18
|
-
cast,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
from langchain_core._api import warn_deprecated
|
|
22
|
-
from langchain_core.callbacks import Callbacks
|
|
23
|
-
from langchain_core.language_models import BaseLanguageModel
|
|
24
|
-
from langchain_core.messages import BaseMessage, messages_from_dict
|
|
25
|
-
from langchain_core.outputs import ChatResult, LLMResult
|
|
26
|
-
from langchain_core.runnables import Runnable, RunnableConfig, RunnableLambda
|
|
27
|
-
from langchain_core.runnables import config as runnable_config
|
|
28
|
-
from langchain_core.runnables import utils as runnable_utils
|
|
29
|
-
from langchain_core.tracers.evaluation import (
|
|
30
|
-
EvaluatorCallbackHandler,
|
|
31
|
-
wait_for_all_evaluators,
|
|
32
|
-
)
|
|
33
|
-
from langchain_core.tracers.langchain import LangChainTracer
|
|
34
|
-
from langsmith.client import Client
|
|
35
|
-
from langsmith.env import get_git_info, get_langchain_env_var_metadata
|
|
36
|
-
from langsmith.evaluation import (
|
|
37
|
-
EvaluationResult,
|
|
38
|
-
RunEvaluator,
|
|
39
|
-
)
|
|
40
|
-
from langsmith.evaluation import (
|
|
41
|
-
run_evaluator as run_evaluator_dec,
|
|
42
|
-
)
|
|
43
|
-
from langsmith.run_helpers import as_runnable, is_traceable_function
|
|
44
|
-
from langsmith.schemas import Dataset, DataType, Example, Run, TracerSession
|
|
45
|
-
from langsmith.utils import LangSmithError
|
|
46
|
-
from requests import HTTPError
|
|
47
|
-
from typing_extensions import TypedDict
|
|
48
|
-
|
|
49
|
-
from langchain.chains.base import Chain
|
|
50
|
-
from langchain.evaluation.loading import load_evaluator
|
|
51
|
-
from langchain.evaluation.schema import (
|
|
52
|
-
EvaluatorType,
|
|
53
|
-
PairwiseStringEvaluator,
|
|
54
|
-
StringEvaluator,
|
|
55
|
-
)
|
|
56
|
-
from langchain.smith import evaluation as smith_eval
|
|
57
|
-
from langchain.smith.evaluation import config as smith_eval_config
|
|
58
|
-
from langchain.smith.evaluation import name_generation, progress
|
|
59
|
-
|
|
60
|
-
if TYPE_CHECKING:
|
|
61
|
-
import pandas as pd
|
|
62
|
-
|
|
63
|
-
logger = logging.getLogger(__name__)
|
|
64
|
-
|
|
65
|
-
MODEL_OR_CHAIN_FACTORY = Union[
|
|
66
|
-
Callable[[], Union[Chain, Runnable]],
|
|
67
|
-
BaseLanguageModel,
|
|
68
|
-
Callable[[dict], Any],
|
|
69
|
-
Runnable,
|
|
70
|
-
Chain,
|
|
71
|
-
]
|
|
72
|
-
MCF = Union[Callable[[], Union[Chain, Runnable]], BaseLanguageModel]
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
class InputFormatError(Exception):
|
|
76
|
-
"""Raised when the input format is invalid."""
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## Shared Utilities
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
class TestResult(dict):
|
|
83
|
-
"""A dictionary of the results of a single test run."""
|
|
84
|
-
|
|
85
|
-
def get_aggregate_feedback(
|
|
86
|
-
self,
|
|
87
|
-
) -> pd.DataFrame:
|
|
88
|
-
"""Return quantiles for the feedback scores.
|
|
89
|
-
|
|
90
|
-
This method calculates and prints the quantiles for the feedback scores
|
|
91
|
-
across all feedback keys.
|
|
92
|
-
|
|
93
|
-
Returns:
|
|
94
|
-
A DataFrame containing the quantiles for each feedback key.
|
|
95
|
-
"""
|
|
96
|
-
df = self.to_dataframe()
|
|
97
|
-
# Drop all things starting with inputs., outputs., and reference
|
|
98
|
-
to_drop = [
|
|
99
|
-
col
|
|
100
|
-
for col in df.columns
|
|
101
|
-
if col.startswith(("inputs.", "outputs.", "reference"))
|
|
102
|
-
or col in {"input", "output"}
|
|
103
|
-
]
|
|
104
|
-
return df.describe(include="all").drop(to_drop, axis=1)
|
|
105
|
-
|
|
106
|
-
def to_dataframe(self) -> pd.DataFrame:
|
|
107
|
-
"""Convert the results to a dataframe."""
|
|
108
|
-
try:
|
|
109
|
-
import pandas as pd
|
|
110
|
-
except ImportError as e:
|
|
111
|
-
msg = (
|
|
112
|
-
"Pandas is required to convert the results to a dataframe."
|
|
113
|
-
" to install pandas, run `pip install pandas`."
|
|
114
|
-
)
|
|
115
|
-
raise ImportError(msg) from e
|
|
116
|
-
|
|
117
|
-
indices = []
|
|
118
|
-
records = []
|
|
119
|
-
for example_id, result in self["results"].items():
|
|
120
|
-
feedback = result["feedback"]
|
|
121
|
-
output_ = result.get("output")
|
|
122
|
-
if isinstance(output_, dict):
|
|
123
|
-
output = {f"outputs.{k}": v for k, v in output_.items()}
|
|
124
|
-
elif output_ is None:
|
|
125
|
-
output = {}
|
|
126
|
-
else:
|
|
127
|
-
output = {"output": output_}
|
|
128
|
-
|
|
129
|
-
r = {
|
|
130
|
-
**{f"inputs.{k}": v for k, v in result["input"].items()},
|
|
131
|
-
**output,
|
|
132
|
-
}
|
|
133
|
-
if "reference" in result:
|
|
134
|
-
if isinstance(result["reference"], dict):
|
|
135
|
-
r.update(
|
|
136
|
-
{f"reference.{k}": v for k, v in result["reference"].items()},
|
|
137
|
-
)
|
|
138
|
-
else:
|
|
139
|
-
r["reference"] = result["reference"]
|
|
140
|
-
r.update(
|
|
141
|
-
{
|
|
142
|
-
**{f"feedback.{f.key}": f.score for f in feedback},
|
|
143
|
-
"error": result.get("Error"),
|
|
144
|
-
"execution_time": result["execution_time"],
|
|
145
|
-
"run_id": result.get("run_id"),
|
|
146
|
-
},
|
|
147
|
-
)
|
|
148
|
-
records.append(r)
|
|
149
|
-
indices.append(example_id)
|
|
150
|
-
|
|
151
|
-
return pd.DataFrame(records, index=indices)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
class EvalError(dict):
|
|
155
|
-
"""Your architecture raised an error."""
|
|
156
|
-
|
|
157
|
-
def __init__(self, Error: BaseException, **kwargs: Any) -> None:
|
|
158
|
-
super().__init__(Error=Error, **kwargs)
|
|
159
|
-
|
|
160
|
-
def __getattr__(self, name: str) -> Any:
|
|
161
|
-
try:
|
|
162
|
-
return self[name]
|
|
163
|
-
except KeyError as e:
|
|
164
|
-
msg = f"'EvalError' object has no attribute '{name}'"
|
|
165
|
-
raise AttributeError(msg) from e
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def _wrap_in_chain_factory(
|
|
169
|
-
llm_or_chain_factory: MODEL_OR_CHAIN_FACTORY,
|
|
170
|
-
dataset_name: str = "<my_dataset>",
|
|
171
|
-
) -> MCF:
|
|
172
|
-
"""Forgive the user if they pass in a chain without memory instead of a chain
|
|
173
|
-
factory. It's a common mistake. Raise a more helpful error message as well."""
|
|
174
|
-
if isinstance(llm_or_chain_factory, Chain):
|
|
175
|
-
chain = llm_or_chain_factory
|
|
176
|
-
chain_class = chain.__class__.__name__
|
|
177
|
-
if llm_or_chain_factory.memory is not None:
|
|
178
|
-
memory_class = chain.memory.__class__.__name__
|
|
179
|
-
msg = (
|
|
180
|
-
"Cannot directly evaluate a chain with stateful memory."
|
|
181
|
-
" To evaluate this chain, pass in a chain constructor"
|
|
182
|
-
" that initializes fresh memory each time it is called."
|
|
183
|
-
" This will safegaurd against information"
|
|
184
|
-
" leakage between dataset examples."
|
|
185
|
-
"\nFor example:\n\n"
|
|
186
|
-
"def chain_constructor():\n"
|
|
187
|
-
f" new_memory = {memory_class}(...)\n"
|
|
188
|
-
f" return {chain_class}"
|
|
189
|
-
"(memory=new_memory, ...)\n\n"
|
|
190
|
-
f'run_on_dataset("{dataset_name}", chain_constructor, ...)'
|
|
191
|
-
)
|
|
192
|
-
raise ValueError(msg)
|
|
193
|
-
return lambda: chain
|
|
194
|
-
if isinstance(llm_or_chain_factory, BaseLanguageModel):
|
|
195
|
-
return llm_or_chain_factory
|
|
196
|
-
if isinstance(llm_or_chain_factory, Runnable):
|
|
197
|
-
# Memory may exist here, but it's not elegant to check all those cases.
|
|
198
|
-
lcf = llm_or_chain_factory
|
|
199
|
-
return lambda: lcf
|
|
200
|
-
if callable(llm_or_chain_factory):
|
|
201
|
-
if is_traceable_function(llm_or_chain_factory):
|
|
202
|
-
runnable_ = as_runnable(cast(Callable, llm_or_chain_factory))
|
|
203
|
-
return lambda: runnable_
|
|
204
|
-
try:
|
|
205
|
-
_model = llm_or_chain_factory() # type: ignore[call-arg]
|
|
206
|
-
except TypeError:
|
|
207
|
-
# It's an arbitrary function, wrap it in a RunnableLambda
|
|
208
|
-
user_func = cast(Callable, llm_or_chain_factory)
|
|
209
|
-
sig = inspect.signature(user_func)
|
|
210
|
-
logger.info("Wrapping function %s as RunnableLambda.", sig)
|
|
211
|
-
wrapped = RunnableLambda(user_func)
|
|
212
|
-
return lambda: wrapped
|
|
213
|
-
constructor = cast(Callable, llm_or_chain_factory)
|
|
214
|
-
if isinstance(_model, BaseLanguageModel):
|
|
215
|
-
# It's not uncommon to do an LLM constructor instead of raw LLM,
|
|
216
|
-
# so we'll unpack it for the user.
|
|
217
|
-
return _model
|
|
218
|
-
if is_traceable_function(cast(Callable, _model)):
|
|
219
|
-
runnable_ = as_runnable(cast(Callable, _model))
|
|
220
|
-
return lambda: runnable_
|
|
221
|
-
if not isinstance(_model, Runnable):
|
|
222
|
-
# This is unlikely to happen - a constructor for a model function
|
|
223
|
-
return lambda: RunnableLambda(constructor)
|
|
224
|
-
# Typical correct case
|
|
225
|
-
return constructor
|
|
226
|
-
return llm_or_chain_factory
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def _get_prompt(inputs: dict[str, Any]) -> str:
|
|
230
|
-
"""Get prompt from inputs.
|
|
231
|
-
|
|
232
|
-
Args:
|
|
233
|
-
inputs: The input dictionary.
|
|
234
|
-
|
|
235
|
-
Returns:
|
|
236
|
-
A string prompt.
|
|
237
|
-
Raises:
|
|
238
|
-
InputFormatError: If the input format is invalid.
|
|
239
|
-
"""
|
|
240
|
-
if not inputs:
|
|
241
|
-
msg = "Inputs should not be empty."
|
|
242
|
-
raise InputFormatError(msg)
|
|
243
|
-
|
|
244
|
-
prompts = []
|
|
245
|
-
if "prompt" in inputs:
|
|
246
|
-
if not isinstance(inputs["prompt"], str):
|
|
247
|
-
msg = f"Expected string for 'prompt', got {type(inputs['prompt']).__name__}"
|
|
248
|
-
raise InputFormatError(msg)
|
|
249
|
-
prompts = [inputs["prompt"]]
|
|
250
|
-
elif "prompts" in inputs:
|
|
251
|
-
if not isinstance(inputs["prompts"], list) or not all(
|
|
252
|
-
isinstance(i, str) for i in inputs["prompts"]
|
|
253
|
-
):
|
|
254
|
-
msg = (
|
|
255
|
-
"Expected list of strings for 'prompts',"
|
|
256
|
-
f" got {type(inputs['prompts']).__name__}"
|
|
257
|
-
)
|
|
258
|
-
raise InputFormatError(msg)
|
|
259
|
-
prompts = inputs["prompts"]
|
|
260
|
-
elif len(inputs) == 1:
|
|
261
|
-
prompt_ = next(iter(inputs.values()))
|
|
262
|
-
if isinstance(prompt_, str):
|
|
263
|
-
prompts = [prompt_]
|
|
264
|
-
elif isinstance(prompt_, list) and all(isinstance(i, str) for i in prompt_):
|
|
265
|
-
prompts = prompt_
|
|
266
|
-
else:
|
|
267
|
-
msg = f"LLM Run expects string prompt input. Got {inputs}"
|
|
268
|
-
raise InputFormatError(msg)
|
|
269
|
-
else:
|
|
270
|
-
msg = f"LLM Run expects 'prompt' or 'prompts' in inputs. Got {inputs}"
|
|
271
|
-
raise InputFormatError(msg)
|
|
272
|
-
if len(prompts) == 1:
|
|
273
|
-
return prompts[0]
|
|
274
|
-
msg = f"LLM Run expects single prompt input. Got {len(prompts)} prompts."
|
|
275
|
-
raise InputFormatError(msg)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
class ChatModelInput(TypedDict):
|
|
279
|
-
"""Input for a chat model.
|
|
280
|
-
|
|
281
|
-
Parameters:
|
|
282
|
-
messages: List of chat messages.
|
|
283
|
-
"""
|
|
284
|
-
|
|
285
|
-
messages: list[BaseMessage]
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
def _get_messages(inputs: dict[str, Any]) -> dict:
|
|
289
|
-
"""Get Chat Messages from inputs.
|
|
290
|
-
|
|
291
|
-
Args:
|
|
292
|
-
inputs: The input dictionary.
|
|
293
|
-
|
|
294
|
-
Returns:
|
|
295
|
-
A list of chat messages.
|
|
296
|
-
Raises:
|
|
297
|
-
InputFormatError: If the input format is invalid.
|
|
298
|
-
"""
|
|
299
|
-
if not inputs:
|
|
300
|
-
msg = "Inputs should not be empty."
|
|
301
|
-
raise InputFormatError(msg)
|
|
302
|
-
input_copy = inputs.copy()
|
|
303
|
-
if "messages" in inputs:
|
|
304
|
-
input_copy["input"] = input_copy.pop("messages")
|
|
305
|
-
elif len(inputs) == 1:
|
|
306
|
-
input_copy["input"] = next(iter(inputs.values()))
|
|
307
|
-
if "input" in input_copy:
|
|
308
|
-
raw_messages = input_copy["input"]
|
|
309
|
-
if isinstance(raw_messages, list) and all(
|
|
310
|
-
isinstance(i, dict) for i in raw_messages
|
|
311
|
-
):
|
|
312
|
-
raw_messages = [raw_messages]
|
|
313
|
-
if len(raw_messages) == 1:
|
|
314
|
-
input_copy["input"] = messages_from_dict(raw_messages[0])
|
|
315
|
-
else:
|
|
316
|
-
msg = (
|
|
317
|
-
"Batch messages not supported. Please provide a"
|
|
318
|
-
" single list of messages."
|
|
319
|
-
)
|
|
320
|
-
raise InputFormatError(msg)
|
|
321
|
-
return input_copy
|
|
322
|
-
msg = (
|
|
323
|
-
f"Chat Run expects single List[dict] or List[List[dict]] 'messages'"
|
|
324
|
-
f" input. Got {inputs}"
|
|
325
|
-
)
|
|
326
|
-
raise InputFormatError(msg)
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
## Shared data validation utilities
|
|
330
|
-
def _validate_example_inputs_for_language_model(
|
|
331
|
-
first_example: Example,
|
|
332
|
-
input_mapper: Optional[Callable[[dict], Any]],
|
|
333
|
-
) -> None:
|
|
334
|
-
if input_mapper:
|
|
335
|
-
prompt_input = input_mapper(first_example.inputs or {})
|
|
336
|
-
if not isinstance(prompt_input, str) and not (
|
|
337
|
-
isinstance(prompt_input, list)
|
|
338
|
-
and all(isinstance(msg, BaseMessage) for msg in prompt_input)
|
|
339
|
-
):
|
|
340
|
-
msg = (
|
|
341
|
-
"When using an input_mapper to prepare dataset example inputs"
|
|
342
|
-
" for an LLM or chat model, the output must a single string or"
|
|
343
|
-
" a list of chat messages."
|
|
344
|
-
f"\nGot: {prompt_input} of type {type(prompt_input)}."
|
|
345
|
-
)
|
|
346
|
-
raise InputFormatError(msg)
|
|
347
|
-
else:
|
|
348
|
-
try:
|
|
349
|
-
_get_prompt(first_example.inputs or {})
|
|
350
|
-
except InputFormatError:
|
|
351
|
-
try:
|
|
352
|
-
_get_messages(first_example.inputs or {})
|
|
353
|
-
except InputFormatError as err2:
|
|
354
|
-
msg = (
|
|
355
|
-
"Example inputs do not match language model input format. "
|
|
356
|
-
"Expected a dictionary with messages or a single prompt."
|
|
357
|
-
f" Got: {first_example.inputs}"
|
|
358
|
-
" Please update your dataset OR provide an input_mapper"
|
|
359
|
-
" to convert the example.inputs to a compatible format"
|
|
360
|
-
" for the llm or chat model you wish to evaluate."
|
|
361
|
-
)
|
|
362
|
-
raise InputFormatError(msg) from err2
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
def _validate_example_inputs_for_chain(
|
|
366
|
-
first_example: Example,
|
|
367
|
-
chain: Chain,
|
|
368
|
-
input_mapper: Optional[Callable[[dict], Any]],
|
|
369
|
-
) -> None:
|
|
370
|
-
"""Validate that the example inputs match the chain input keys."""
|
|
371
|
-
if input_mapper:
|
|
372
|
-
first_inputs = input_mapper(first_example.inputs or {})
|
|
373
|
-
missing_keys = set(chain.input_keys).difference(first_inputs)
|
|
374
|
-
if not isinstance(first_inputs, dict):
|
|
375
|
-
msg = (
|
|
376
|
-
"When using an input_mapper to prepare dataset example"
|
|
377
|
-
" inputs for a chain, the mapped value must be a dictionary."
|
|
378
|
-
f"\nGot: {first_inputs} of type {type(first_inputs)}."
|
|
379
|
-
)
|
|
380
|
-
raise InputFormatError(msg)
|
|
381
|
-
if missing_keys:
|
|
382
|
-
msg = (
|
|
383
|
-
"Missing keys after loading example using input_mapper."
|
|
384
|
-
f"\nExpected: {chain.input_keys}. Got: {first_inputs.keys()}"
|
|
385
|
-
)
|
|
386
|
-
raise InputFormatError(msg)
|
|
387
|
-
else:
|
|
388
|
-
first_inputs = first_example.inputs
|
|
389
|
-
missing_keys = set(chain.input_keys).difference(first_inputs)
|
|
390
|
-
if len(first_inputs) == 1 and len(chain.input_keys) == 1:
|
|
391
|
-
# We can pass this through the run method.
|
|
392
|
-
# Refrain from calling to validate.
|
|
393
|
-
pass
|
|
394
|
-
elif missing_keys:
|
|
395
|
-
msg = (
|
|
396
|
-
"Example inputs missing expected chain input keys."
|
|
397
|
-
" Please provide an input_mapper to convert the example.inputs"
|
|
398
|
-
" to a compatible format for the chain you wish to evaluate."
|
|
399
|
-
f"Expected: {chain.input_keys}. "
|
|
400
|
-
f"Got: {first_inputs.keys()}"
|
|
401
|
-
)
|
|
402
|
-
raise InputFormatError(msg)
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
def _validate_example_inputs(
|
|
406
|
-
example: Example,
|
|
407
|
-
llm_or_chain_factory: MCF,
|
|
408
|
-
input_mapper: Optional[Callable[[dict], Any]],
|
|
409
|
-
) -> None:
|
|
410
|
-
"""Validate that the example inputs are valid for the model."""
|
|
411
|
-
if isinstance(llm_or_chain_factory, BaseLanguageModel):
|
|
412
|
-
_validate_example_inputs_for_language_model(example, input_mapper)
|
|
413
|
-
else:
|
|
414
|
-
chain = llm_or_chain_factory()
|
|
415
|
-
if isinstance(chain, Chain):
|
|
416
|
-
# Otherwise it's a runnable
|
|
417
|
-
_validate_example_inputs_for_chain(example, chain, input_mapper)
|
|
418
|
-
elif isinstance(chain, Runnable):
|
|
419
|
-
logger.debug("Skipping input validation for %s", chain)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
## Shared Evaluator Setup Utilities
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def _setup_evaluation(
|
|
426
|
-
llm_or_chain_factory: MCF,
|
|
427
|
-
examples: list[Example],
|
|
428
|
-
evaluation: Optional[smith_eval.RunEvalConfig],
|
|
429
|
-
data_type: DataType,
|
|
430
|
-
) -> Optional[list[RunEvaluator]]:
|
|
431
|
-
"""Configure the evaluators to run on the results of the chain."""
|
|
432
|
-
if evaluation:
|
|
433
|
-
if isinstance(llm_or_chain_factory, BaseLanguageModel):
|
|
434
|
-
run_inputs, run_outputs = None, None
|
|
435
|
-
run_type = "llm"
|
|
436
|
-
else:
|
|
437
|
-
run_type = "chain"
|
|
438
|
-
chain = llm_or_chain_factory()
|
|
439
|
-
run_inputs = chain.input_keys if isinstance(chain, Chain) else None
|
|
440
|
-
run_outputs = chain.output_keys if isinstance(chain, Chain) else None
|
|
441
|
-
run_evaluators = _load_run_evaluators(
|
|
442
|
-
evaluation,
|
|
443
|
-
run_type,
|
|
444
|
-
data_type,
|
|
445
|
-
list(examples[0].outputs) if examples[0].outputs else None,
|
|
446
|
-
run_inputs,
|
|
447
|
-
run_outputs,
|
|
448
|
-
)
|
|
449
|
-
else:
|
|
450
|
-
# TODO: Create a default helpfulness evaluator
|
|
451
|
-
run_evaluators = None
|
|
452
|
-
return run_evaluators
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
def _determine_input_key(
|
|
456
|
-
config: smith_eval.RunEvalConfig,
|
|
457
|
-
run_inputs: Optional[list[str]],
|
|
458
|
-
) -> Optional[str]:
|
|
459
|
-
input_key = None
|
|
460
|
-
if config.input_key:
|
|
461
|
-
input_key = config.input_key
|
|
462
|
-
if run_inputs and input_key not in run_inputs:
|
|
463
|
-
logger.warning(
|
|
464
|
-
"Input key %s not in chain's specified input keys %s. "
|
|
465
|
-
"Evaluation behavior may be undefined.",
|
|
466
|
-
input_key,
|
|
467
|
-
run_inputs,
|
|
468
|
-
)
|
|
469
|
-
elif run_inputs and len(run_inputs) == 1:
|
|
470
|
-
input_key = run_inputs[0]
|
|
471
|
-
elif run_inputs is not None and len(run_inputs) > 1:
|
|
472
|
-
logger.warning(
|
|
473
|
-
"Chain expects multiple input keys: %s,"
|
|
474
|
-
" Evaluator is likely to fail. Evaluation behavior may be undefined."
|
|
475
|
-
" Specify an input_key in the RunEvalConfig to avoid this warning.",
|
|
476
|
-
run_inputs,
|
|
477
|
-
)
|
|
478
|
-
|
|
479
|
-
return input_key
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
def _determine_prediction_key(
|
|
483
|
-
config: smith_eval.RunEvalConfig,
|
|
484
|
-
run_outputs: Optional[list[str]],
|
|
485
|
-
) -> Optional[str]:
|
|
486
|
-
prediction_key = None
|
|
487
|
-
if config.prediction_key:
|
|
488
|
-
prediction_key = config.prediction_key
|
|
489
|
-
if run_outputs and prediction_key not in run_outputs:
|
|
490
|
-
logger.warning(
|
|
491
|
-
"Prediction key %s not in chain's specified output keys %s. "
|
|
492
|
-
"Evaluation behavior may be undefined.",
|
|
493
|
-
prediction_key,
|
|
494
|
-
run_outputs,
|
|
495
|
-
)
|
|
496
|
-
elif run_outputs and len(run_outputs) == 1:
|
|
497
|
-
prediction_key = run_outputs[0]
|
|
498
|
-
elif run_outputs is not None and len(run_outputs) > 1:
|
|
499
|
-
logger.warning(
|
|
500
|
-
"Chain expects multiple output keys: %s,"
|
|
501
|
-
" Evaluation behavior may be undefined. Specify a prediction_key"
|
|
502
|
-
" in the RunEvalConfig to avoid this warning.",
|
|
503
|
-
run_outputs,
|
|
504
|
-
)
|
|
505
|
-
return prediction_key
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
def _determine_reference_key(
|
|
509
|
-
config: smith_eval.RunEvalConfig,
|
|
510
|
-
example_outputs: Optional[list[str]],
|
|
511
|
-
) -> Optional[str]:
|
|
512
|
-
if config.reference_key:
|
|
513
|
-
reference_key = config.reference_key
|
|
514
|
-
if example_outputs and reference_key not in example_outputs:
|
|
515
|
-
msg = (
|
|
516
|
-
f"Reference key {reference_key} not in Dataset"
|
|
517
|
-
f" example outputs: {example_outputs}"
|
|
518
|
-
)
|
|
519
|
-
raise ValueError(msg)
|
|
520
|
-
elif example_outputs and len(example_outputs) == 1:
|
|
521
|
-
reference_key = next(iter(example_outputs))
|
|
522
|
-
else:
|
|
523
|
-
reference_key = None
|
|
524
|
-
return reference_key
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
def _construct_run_evaluator(
|
|
528
|
-
eval_config: Union[
|
|
529
|
-
smith_eval_config.SINGLE_EVAL_CONFIG_TYPE,
|
|
530
|
-
smith_eval_config.CUSTOM_EVALUATOR_TYPE,
|
|
531
|
-
],
|
|
532
|
-
eval_llm: Optional[BaseLanguageModel],
|
|
533
|
-
run_type: str,
|
|
534
|
-
data_type: DataType,
|
|
535
|
-
example_outputs: Optional[list[str]],
|
|
536
|
-
reference_key: Optional[str],
|
|
537
|
-
input_key: Optional[str],
|
|
538
|
-
prediction_key: Optional[str],
|
|
539
|
-
) -> RunEvaluator:
|
|
540
|
-
if isinstance(eval_config, RunEvaluator):
|
|
541
|
-
return eval_config
|
|
542
|
-
if isinstance(eval_config, (EvaluatorType, str)):
|
|
543
|
-
if not isinstance(eval_config, EvaluatorType):
|
|
544
|
-
eval_config = EvaluatorType(eval_config)
|
|
545
|
-
evaluator_ = load_evaluator(eval_config, llm=eval_llm)
|
|
546
|
-
eval_type_tag = eval_config.value
|
|
547
|
-
elif isinstance(eval_config, smith_eval_config.EvalConfig):
|
|
548
|
-
kwargs = {"llm": eval_llm, **eval_config.get_kwargs()}
|
|
549
|
-
evaluator_ = load_evaluator(eval_config.evaluator_type, **kwargs)
|
|
550
|
-
eval_type_tag = eval_config.evaluator_type.value
|
|
551
|
-
# Override keys if specified in the config
|
|
552
|
-
if isinstance(eval_config, smith_eval_config.SingleKeyEvalConfig):
|
|
553
|
-
input_key = eval_config.input_key or input_key
|
|
554
|
-
prediction_key = eval_config.prediction_key or prediction_key
|
|
555
|
-
reference_key = eval_config.reference_key or reference_key
|
|
556
|
-
elif callable(eval_config):
|
|
557
|
-
# Assume we can decorate
|
|
558
|
-
return run_evaluator_dec(eval_config)
|
|
559
|
-
else:
|
|
560
|
-
msg = f"Unknown evaluator type: {type(eval_config)}"
|
|
561
|
-
raise ValueError(msg) # noqa: TRY004
|
|
562
|
-
|
|
563
|
-
if isinstance(evaluator_, StringEvaluator):
|
|
564
|
-
if evaluator_.requires_reference and reference_key is None:
|
|
565
|
-
msg = (
|
|
566
|
-
f"Must specify reference_key in smith_eval.RunEvalConfig to use"
|
|
567
|
-
f" evaluator of type {eval_type_tag} with"
|
|
568
|
-
f" dataset with multiple output keys: {example_outputs}."
|
|
569
|
-
)
|
|
570
|
-
raise ValueError(msg)
|
|
571
|
-
run_evaluator = smith_eval.StringRunEvaluatorChain.from_run_and_data_type(
|
|
572
|
-
evaluator_,
|
|
573
|
-
run_type,
|
|
574
|
-
data_type,
|
|
575
|
-
input_key=input_key,
|
|
576
|
-
prediction_key=prediction_key,
|
|
577
|
-
reference_key=reference_key,
|
|
578
|
-
tags=[eval_type_tag],
|
|
579
|
-
)
|
|
580
|
-
elif isinstance(evaluator_, PairwiseStringEvaluator):
|
|
581
|
-
msg = (
|
|
582
|
-
f"Run evaluator for {eval_type_tag} is not implemented."
|
|
583
|
-
" PairwiseStringEvaluators compare the outputs of two different models"
|
|
584
|
-
" rather than the output of a single model."
|
|
585
|
-
" Did you mean to use a StringEvaluator instead?"
|
|
586
|
-
"\nSee: https://python.langchain.com/docs/guides/evaluation/string/"
|
|
587
|
-
)
|
|
588
|
-
raise NotImplementedError(msg)
|
|
589
|
-
|
|
590
|
-
else:
|
|
591
|
-
msg = f"Run evaluator for {eval_type_tag} is not implemented"
|
|
592
|
-
raise NotImplementedError(msg)
|
|
593
|
-
return run_evaluator
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
def _get_keys(
|
|
597
|
-
config: smith_eval.RunEvalConfig,
|
|
598
|
-
run_inputs: Optional[list[str]],
|
|
599
|
-
run_outputs: Optional[list[str]],
|
|
600
|
-
example_outputs: Optional[list[str]],
|
|
601
|
-
) -> tuple[Optional[str], Optional[str], Optional[str]]:
|
|
602
|
-
input_key = _determine_input_key(config, run_inputs)
|
|
603
|
-
prediction_key = _determine_prediction_key(config, run_outputs)
|
|
604
|
-
reference_key = _determine_reference_key(config, example_outputs)
|
|
605
|
-
return input_key, prediction_key, reference_key
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
def _load_run_evaluators(
|
|
609
|
-
config: smith_eval.RunEvalConfig,
|
|
610
|
-
run_type: str,
|
|
611
|
-
data_type: DataType,
|
|
612
|
-
example_outputs: Optional[list[str]],
|
|
613
|
-
run_inputs: Optional[list[str]],
|
|
614
|
-
run_outputs: Optional[list[str]],
|
|
615
|
-
) -> list[RunEvaluator]:
|
|
616
|
-
"""
|
|
617
|
-
Load run evaluators from a configuration.
|
|
618
|
-
|
|
619
|
-
Args:
|
|
620
|
-
config: Configuration for the run evaluators.
|
|
621
|
-
|
|
622
|
-
Returns:
|
|
623
|
-
A list of run evaluators.
|
|
624
|
-
"""
|
|
625
|
-
run_evaluators = []
|
|
626
|
-
input_key, prediction_key, reference_key = None, None, None
|
|
627
|
-
if config.evaluators or (
|
|
628
|
-
config.custom_evaluators
|
|
629
|
-
and any(isinstance(e, StringEvaluator) for e in config.custom_evaluators)
|
|
630
|
-
):
|
|
631
|
-
input_key, prediction_key, reference_key = _get_keys(
|
|
632
|
-
config,
|
|
633
|
-
run_inputs,
|
|
634
|
-
run_outputs,
|
|
635
|
-
example_outputs,
|
|
636
|
-
)
|
|
637
|
-
for eval_config in config.evaluators:
|
|
638
|
-
run_evaluator = _construct_run_evaluator(
|
|
639
|
-
eval_config,
|
|
640
|
-
config.eval_llm,
|
|
641
|
-
run_type,
|
|
642
|
-
data_type,
|
|
643
|
-
example_outputs,
|
|
644
|
-
reference_key,
|
|
645
|
-
input_key,
|
|
646
|
-
prediction_key,
|
|
647
|
-
)
|
|
648
|
-
run_evaluators.append(run_evaluator)
|
|
649
|
-
custom_evaluators = config.custom_evaluators or []
|
|
650
|
-
for custom_evaluator in custom_evaluators:
|
|
651
|
-
if isinstance(custom_evaluator, RunEvaluator):
|
|
652
|
-
run_evaluators.append(custom_evaluator)
|
|
653
|
-
elif isinstance(custom_evaluator, StringEvaluator):
|
|
654
|
-
run_evaluators.append(
|
|
655
|
-
smith_eval.StringRunEvaluatorChain.from_run_and_data_type(
|
|
656
|
-
custom_evaluator,
|
|
657
|
-
run_type,
|
|
658
|
-
data_type,
|
|
659
|
-
input_key=input_key,
|
|
660
|
-
prediction_key=prediction_key,
|
|
661
|
-
reference_key=reference_key,
|
|
662
|
-
),
|
|
663
|
-
)
|
|
664
|
-
elif callable(custom_evaluator):
|
|
665
|
-
run_evaluators.append(run_evaluator_dec(custom_evaluator))
|
|
666
|
-
else:
|
|
667
|
-
msg = (
|
|
668
|
-
f"Unsupported custom evaluator: {custom_evaluator}."
|
|
669
|
-
f" Expected RunEvaluator or StringEvaluator."
|
|
670
|
-
)
|
|
671
|
-
raise ValueError(msg) # noqa: TRY004
|
|
672
|
-
|
|
673
|
-
return run_evaluators
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
### Async Helpers
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
async def _arun_llm(
|
|
680
|
-
llm: BaseLanguageModel,
|
|
681
|
-
inputs: dict[str, Any],
|
|
682
|
-
*,
|
|
683
|
-
tags: Optional[list[str]] = None,
|
|
684
|
-
callbacks: Callbacks = None,
|
|
685
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
686
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
687
|
-
) -> Union[str, BaseMessage]:
|
|
688
|
-
"""Asynchronously run the language model.
|
|
689
|
-
|
|
690
|
-
Args:
|
|
691
|
-
llm: The language model to run.
|
|
692
|
-
inputs: The input dictionary.
|
|
693
|
-
tags: Optional tags to add to the run.
|
|
694
|
-
callbacks: Optional callbacks to use during the run.
|
|
695
|
-
input_mapper: Optional function to map inputs to the expected format.
|
|
696
|
-
|
|
697
|
-
Returns:
|
|
698
|
-
The LLMResult or ChatResult.
|
|
699
|
-
Raises:
|
|
700
|
-
ValueError: If the LLM type is unsupported.
|
|
701
|
-
InputFormatError: If the input format is invalid.
|
|
702
|
-
"""
|
|
703
|
-
if input_mapper is not None:
|
|
704
|
-
prompt_or_messages = input_mapper(inputs)
|
|
705
|
-
if isinstance(prompt_or_messages, str) or (
|
|
706
|
-
isinstance(prompt_or_messages, list)
|
|
707
|
-
and all(isinstance(msg, BaseMessage) for msg in prompt_or_messages)
|
|
708
|
-
):
|
|
709
|
-
return await llm.ainvoke(
|
|
710
|
-
prompt_or_messages,
|
|
711
|
-
config=RunnableConfig(
|
|
712
|
-
callbacks=callbacks,
|
|
713
|
-
tags=tags or [],
|
|
714
|
-
metadata=metadata or {},
|
|
715
|
-
),
|
|
716
|
-
)
|
|
717
|
-
msg = (
|
|
718
|
-
"Input mapper returned invalid format"
|
|
719
|
-
f" {prompt_or_messages}"
|
|
720
|
-
"\nExpected a single string or list of chat messages."
|
|
721
|
-
)
|
|
722
|
-
raise InputFormatError(msg)
|
|
723
|
-
|
|
724
|
-
try:
|
|
725
|
-
prompt = _get_prompt(inputs)
|
|
726
|
-
llm_output: Union[str, BaseMessage] = await llm.ainvoke(
|
|
727
|
-
prompt,
|
|
728
|
-
config=RunnableConfig(
|
|
729
|
-
callbacks=callbacks,
|
|
730
|
-
tags=tags or [],
|
|
731
|
-
metadata=metadata or {},
|
|
732
|
-
),
|
|
733
|
-
)
|
|
734
|
-
except InputFormatError:
|
|
735
|
-
llm_inputs = _get_messages(inputs)
|
|
736
|
-
llm_output = await llm.ainvoke(
|
|
737
|
-
**llm_inputs,
|
|
738
|
-
config=RunnableConfig(
|
|
739
|
-
callbacks=callbacks,
|
|
740
|
-
tags=tags or [],
|
|
741
|
-
metadata=metadata or {},
|
|
742
|
-
),
|
|
743
|
-
)
|
|
744
|
-
return llm_output
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
async def _arun_chain(
|
|
748
|
-
chain: Union[Chain, Runnable],
|
|
749
|
-
inputs: dict[str, Any],
|
|
750
|
-
callbacks: Callbacks,
|
|
751
|
-
*,
|
|
752
|
-
tags: Optional[list[str]] = None,
|
|
753
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
754
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
755
|
-
) -> Union[dict, str]:
|
|
756
|
-
"""Run a chain asynchronously on inputs."""
|
|
757
|
-
inputs_ = inputs if input_mapper is None else input_mapper(inputs)
|
|
758
|
-
if (
|
|
759
|
-
isinstance(chain, Chain)
|
|
760
|
-
and isinstance(inputs_, dict)
|
|
761
|
-
and len(inputs_) == 1
|
|
762
|
-
and chain.input_keys
|
|
763
|
-
):
|
|
764
|
-
val = next(iter(inputs_.values()))
|
|
765
|
-
output = await chain.ainvoke(
|
|
766
|
-
val,
|
|
767
|
-
config=RunnableConfig(
|
|
768
|
-
callbacks=callbacks,
|
|
769
|
-
tags=tags or [],
|
|
770
|
-
metadata=metadata or {},
|
|
771
|
-
),
|
|
772
|
-
)
|
|
773
|
-
else:
|
|
774
|
-
runnable_config = RunnableConfig(
|
|
775
|
-
tags=tags or [],
|
|
776
|
-
callbacks=callbacks,
|
|
777
|
-
metadata=metadata or {},
|
|
778
|
-
)
|
|
779
|
-
output = await chain.ainvoke(inputs_, config=runnable_config)
|
|
780
|
-
return output
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
async def _arun_llm_or_chain(
|
|
784
|
-
example: Example,
|
|
785
|
-
config: RunnableConfig,
|
|
786
|
-
*,
|
|
787
|
-
llm_or_chain_factory: MCF,
|
|
788
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
789
|
-
) -> Union[dict, str, LLMResult, ChatResult]:
|
|
790
|
-
"""Asynchronously run the Chain or language model.
|
|
791
|
-
|
|
792
|
-
Args:
|
|
793
|
-
example: The example to run.
|
|
794
|
-
llm_or_chain_factory: The Chain or language model constructor to run.
|
|
795
|
-
tags: Optional tags to add to the run.
|
|
796
|
-
callbacks: Optional callbacks to use during the run.
|
|
797
|
-
input_mapper: Optional function to map the input to the expected format.
|
|
798
|
-
|
|
799
|
-
Returns:
|
|
800
|
-
A list of outputs.
|
|
801
|
-
"""
|
|
802
|
-
chain_or_llm = (
|
|
803
|
-
"LLM" if isinstance(llm_or_chain_factory, BaseLanguageModel) else "Chain"
|
|
804
|
-
)
|
|
805
|
-
result = None
|
|
806
|
-
try:
|
|
807
|
-
if isinstance(llm_or_chain_factory, BaseLanguageModel):
|
|
808
|
-
output: Any = await _arun_llm(
|
|
809
|
-
llm_or_chain_factory,
|
|
810
|
-
example.inputs or {},
|
|
811
|
-
tags=config["tags"],
|
|
812
|
-
callbacks=config["callbacks"],
|
|
813
|
-
input_mapper=input_mapper,
|
|
814
|
-
metadata=config.get("metadata"),
|
|
815
|
-
)
|
|
816
|
-
else:
|
|
817
|
-
chain = llm_or_chain_factory()
|
|
818
|
-
output = await _arun_chain(
|
|
819
|
-
chain,
|
|
820
|
-
example.inputs or {},
|
|
821
|
-
tags=config["tags"],
|
|
822
|
-
callbacks=config["callbacks"],
|
|
823
|
-
input_mapper=input_mapper,
|
|
824
|
-
metadata=config.get("metadata"),
|
|
825
|
-
)
|
|
826
|
-
result = output
|
|
827
|
-
except Exception as e:
|
|
828
|
-
logger.warning(
|
|
829
|
-
"%s failed for example %s with inputs %s\n%s",
|
|
830
|
-
chain_or_llm,
|
|
831
|
-
example.id,
|
|
832
|
-
example.inputs,
|
|
833
|
-
e,
|
|
834
|
-
)
|
|
835
|
-
result = EvalError(Error=e)
|
|
836
|
-
return result
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
## Sync Utilities
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
def _run_llm(
|
|
843
|
-
llm: BaseLanguageModel,
|
|
844
|
-
inputs: dict[str, Any],
|
|
845
|
-
callbacks: Callbacks,
|
|
846
|
-
*,
|
|
847
|
-
tags: Optional[list[str]] = None,
|
|
848
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
849
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
850
|
-
) -> Union[str, BaseMessage]:
|
|
851
|
-
"""
|
|
852
|
-
Run the language model on the example.
|
|
853
|
-
|
|
854
|
-
Args:
|
|
855
|
-
llm: The language model to run.
|
|
856
|
-
inputs: The input dictionary.
|
|
857
|
-
callbacks: The callbacks to use during the run.
|
|
858
|
-
tags: Optional tags to add to the run.
|
|
859
|
-
input_mapper: function to map to the inputs dictionary from an Example
|
|
860
|
-
Returns:
|
|
861
|
-
The LLMResult or ChatResult.
|
|
862
|
-
Raises:
|
|
863
|
-
ValueError: If the LLM type is unsupported.
|
|
864
|
-
InputFormatError: If the input format is invalid.
|
|
865
|
-
"""
|
|
866
|
-
# Most of this is legacy code; we could probably remove a lot of it.
|
|
867
|
-
if input_mapper is not None:
|
|
868
|
-
prompt_or_messages = input_mapper(inputs)
|
|
869
|
-
if isinstance(prompt_or_messages, str) or (
|
|
870
|
-
isinstance(prompt_or_messages, list)
|
|
871
|
-
and all(isinstance(msg, BaseMessage) for msg in prompt_or_messages)
|
|
872
|
-
):
|
|
873
|
-
llm_output: Union[str, BaseMessage] = llm.invoke(
|
|
874
|
-
prompt_or_messages,
|
|
875
|
-
config=RunnableConfig(
|
|
876
|
-
callbacks=callbacks,
|
|
877
|
-
tags=tags or [],
|
|
878
|
-
metadata=metadata or {},
|
|
879
|
-
),
|
|
880
|
-
)
|
|
881
|
-
else:
|
|
882
|
-
msg = (
|
|
883
|
-
"Input mapper returned invalid format: "
|
|
884
|
-
f" {prompt_or_messages}"
|
|
885
|
-
"\nExpected a single string or list of chat messages."
|
|
886
|
-
)
|
|
887
|
-
raise InputFormatError(msg)
|
|
888
|
-
else:
|
|
889
|
-
try:
|
|
890
|
-
llm_prompts = _get_prompt(inputs)
|
|
891
|
-
llm_output = llm.invoke(
|
|
892
|
-
llm_prompts,
|
|
893
|
-
config=RunnableConfig(
|
|
894
|
-
callbacks=callbacks,
|
|
895
|
-
tags=tags or [],
|
|
896
|
-
metadata=metadata or {},
|
|
897
|
-
),
|
|
898
|
-
)
|
|
899
|
-
except InputFormatError:
|
|
900
|
-
llm_inputs = _get_messages(inputs)
|
|
901
|
-
llm_output = llm.invoke(
|
|
902
|
-
**llm_inputs,
|
|
903
|
-
config=RunnableConfig(callbacks=callbacks, metadata=metadata or {}),
|
|
904
|
-
)
|
|
905
|
-
return llm_output
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
def _run_chain(
|
|
909
|
-
chain: Union[Chain, Runnable],
|
|
910
|
-
inputs: dict[str, Any],
|
|
911
|
-
callbacks: Callbacks,
|
|
912
|
-
*,
|
|
913
|
-
tags: Optional[list[str]] = None,
|
|
914
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
915
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
916
|
-
) -> Union[dict, str]:
|
|
917
|
-
"""Run a chain on inputs."""
|
|
918
|
-
inputs_ = inputs if input_mapper is None else input_mapper(inputs)
|
|
919
|
-
if (
|
|
920
|
-
isinstance(chain, Chain)
|
|
921
|
-
and isinstance(inputs_, dict)
|
|
922
|
-
and len(inputs_) == 1
|
|
923
|
-
and chain.input_keys
|
|
924
|
-
):
|
|
925
|
-
val = next(iter(inputs_.values()))
|
|
926
|
-
output = chain.invoke(
|
|
927
|
-
val,
|
|
928
|
-
config=RunnableConfig(
|
|
929
|
-
callbacks=callbacks,
|
|
930
|
-
tags=tags or [],
|
|
931
|
-
metadata=metadata or {},
|
|
932
|
-
),
|
|
933
|
-
)
|
|
934
|
-
else:
|
|
935
|
-
runnable_config = RunnableConfig(
|
|
936
|
-
tags=tags or [],
|
|
937
|
-
callbacks=callbacks,
|
|
938
|
-
metadata=metadata or {},
|
|
939
|
-
)
|
|
940
|
-
output = chain.invoke(inputs_, config=runnable_config)
|
|
941
|
-
return output
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
def _run_llm_or_chain(
|
|
945
|
-
example: Example,
|
|
946
|
-
config: RunnableConfig,
|
|
947
|
-
*,
|
|
948
|
-
llm_or_chain_factory: MCF,
|
|
949
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
950
|
-
) -> Union[dict, str, LLMResult, ChatResult]:
|
|
951
|
-
"""
|
|
952
|
-
Run the Chain or language model synchronously.
|
|
953
|
-
|
|
954
|
-
Args:
|
|
955
|
-
example: The example to run.
|
|
956
|
-
llm_or_chain_factory: The Chain or language model constructor to run.
|
|
957
|
-
tags: Optional tags to add to the run.
|
|
958
|
-
callbacks: Optional callbacks to use during the run.
|
|
959
|
-
|
|
960
|
-
Returns:
|
|
961
|
-
Union[List[dict], List[str], List[LLMResult], List[ChatResult]]:
|
|
962
|
-
The outputs of the model or chain.
|
|
963
|
-
"""
|
|
964
|
-
chain_or_llm = (
|
|
965
|
-
"LLM" if isinstance(llm_or_chain_factory, BaseLanguageModel) else "Chain"
|
|
966
|
-
)
|
|
967
|
-
result = None
|
|
968
|
-
try:
|
|
969
|
-
if isinstance(llm_or_chain_factory, BaseLanguageModel):
|
|
970
|
-
output: Any = _run_llm(
|
|
971
|
-
llm_or_chain_factory,
|
|
972
|
-
example.inputs or {},
|
|
973
|
-
config["callbacks"],
|
|
974
|
-
tags=config["tags"],
|
|
975
|
-
input_mapper=input_mapper,
|
|
976
|
-
metadata=config.get("metadata"),
|
|
977
|
-
)
|
|
978
|
-
else:
|
|
979
|
-
chain = llm_or_chain_factory()
|
|
980
|
-
output = _run_chain(
|
|
981
|
-
chain,
|
|
982
|
-
example.inputs or {},
|
|
983
|
-
config["callbacks"],
|
|
984
|
-
tags=config["tags"],
|
|
985
|
-
input_mapper=input_mapper,
|
|
986
|
-
metadata=config.get("metadata"),
|
|
987
|
-
)
|
|
988
|
-
result = output
|
|
989
|
-
except Exception as e:
|
|
990
|
-
error_type = type(e).__name__
|
|
991
|
-
logger.warning(
|
|
992
|
-
"%s failed for example %s with inputs %s\nError Type: %s, Message: %s",
|
|
993
|
-
chain_or_llm,
|
|
994
|
-
example.id,
|
|
995
|
-
example.inputs,
|
|
996
|
-
error_type,
|
|
997
|
-
e,
|
|
998
|
-
)
|
|
999
|
-
result = EvalError(Error=e)
|
|
1000
|
-
return result
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
def _prepare_eval_run(
|
|
1004
|
-
client: Client,
|
|
1005
|
-
dataset_name: str,
|
|
1006
|
-
llm_or_chain_factory: MODEL_OR_CHAIN_FACTORY,
|
|
1007
|
-
project_name: str,
|
|
1008
|
-
project_metadata: Optional[dict[str, Any]] = None,
|
|
1009
|
-
tags: Optional[list[str]] = None,
|
|
1010
|
-
dataset_version: Optional[Union[str, datetime]] = None,
|
|
1011
|
-
) -> tuple[MCF, TracerSession, Dataset, list[Example]]:
|
|
1012
|
-
wrapped_model = _wrap_in_chain_factory(llm_or_chain_factory, dataset_name)
|
|
1013
|
-
dataset = client.read_dataset(dataset_name=dataset_name)
|
|
1014
|
-
|
|
1015
|
-
examples = list(client.list_examples(dataset_id=dataset.id, as_of=dataset_version))
|
|
1016
|
-
if not examples:
|
|
1017
|
-
msg = f"Dataset {dataset_name} has no example rows."
|
|
1018
|
-
raise ValueError(msg)
|
|
1019
|
-
modified_at = [ex.modified_at for ex in examples if ex.modified_at]
|
|
1020
|
-
# Should always be defined in practice when fetched,
|
|
1021
|
-
# but the typing permits None
|
|
1022
|
-
max_modified_at = max(modified_at) if modified_at else None
|
|
1023
|
-
inferred_version = max_modified_at.isoformat() if max_modified_at else None
|
|
1024
|
-
|
|
1025
|
-
try:
|
|
1026
|
-
project_metadata = project_metadata or {}
|
|
1027
|
-
git_info = get_git_info()
|
|
1028
|
-
if git_info:
|
|
1029
|
-
project_metadata = {
|
|
1030
|
-
**project_metadata,
|
|
1031
|
-
"git": git_info,
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
project_metadata["dataset_version"] = inferred_version
|
|
1035
|
-
project = client.create_project(
|
|
1036
|
-
project_name,
|
|
1037
|
-
reference_dataset_id=dataset.id,
|
|
1038
|
-
project_extra={"tags": tags} if tags else {},
|
|
1039
|
-
metadata=project_metadata,
|
|
1040
|
-
)
|
|
1041
|
-
except (HTTPError, ValueError, LangSmithError) as e:
|
|
1042
|
-
if "already exists " not in str(e):
|
|
1043
|
-
raise
|
|
1044
|
-
uid = uuid.uuid4()
|
|
1045
|
-
example_msg = f"""
|
|
1046
|
-
run_on_dataset(
|
|
1047
|
-
...
|
|
1048
|
-
project_name="{project_name} - {uid}", # Update since {project_name} already exists
|
|
1049
|
-
)
|
|
1050
|
-
"""
|
|
1051
|
-
msg = (
|
|
1052
|
-
f"Test project {project_name} already exists. Please use a different name:"
|
|
1053
|
-
f"\n\n{example_msg}"
|
|
1054
|
-
)
|
|
1055
|
-
raise ValueError(msg) from e
|
|
1056
|
-
comparison_url = dataset.url + f"/compare?selectedSessions={project.id}"
|
|
1057
|
-
print( # noqa: T201
|
|
1058
|
-
f"View the evaluation results for project '{project_name}'"
|
|
1059
|
-
f" at:\n{comparison_url}\n\n"
|
|
1060
|
-
f"View all tests for Dataset {dataset_name} at:\n{dataset.url}",
|
|
1061
|
-
flush=True,
|
|
1062
|
-
)
|
|
1063
|
-
return wrapped_model, project, dataset, examples
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
class _RowResult(TypedDict, total=False):
|
|
1067
|
-
"""A dictionary of the results for a single example row."""
|
|
1068
|
-
|
|
1069
|
-
feedback: Optional[list[EvaluationResult]]
|
|
1070
|
-
execution_time: Optional[float]
|
|
1071
|
-
run_id: Optional[str]
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
@dataclasses.dataclass
|
|
1075
|
-
class _DatasetRunContainer:
|
|
1076
|
-
"""A container to help manage the state of a eval run."""
|
|
1077
|
-
|
|
1078
|
-
client: Client
|
|
1079
|
-
project: TracerSession
|
|
1080
|
-
wrapped_model: MCF
|
|
1081
|
-
examples: list[Example]
|
|
1082
|
-
configs: list[RunnableConfig]
|
|
1083
|
-
batch_evaluators: Optional[list[smith_eval_config.BATCH_EVALUATOR_LIKE]] = None
|
|
1084
|
-
|
|
1085
|
-
def _merge_test_outputs(
|
|
1086
|
-
self,
|
|
1087
|
-
batch_results: list,
|
|
1088
|
-
all_eval_results: dict[str, _RowResult],
|
|
1089
|
-
) -> dict:
|
|
1090
|
-
results: dict = {}
|
|
1091
|
-
for example, output in zip(self.examples, batch_results):
|
|
1092
|
-
row_result = cast(_RowResult, all_eval_results.get(str(example.id), {}))
|
|
1093
|
-
results[str(example.id)] = {
|
|
1094
|
-
"input": example.inputs,
|
|
1095
|
-
"feedback": row_result.get("feedback", []),
|
|
1096
|
-
"execution_time": row_result.get("execution_time"),
|
|
1097
|
-
"run_id": row_result.get("run_id"),
|
|
1098
|
-
}
|
|
1099
|
-
if isinstance(output, EvalError):
|
|
1100
|
-
results[str(example.id)]["Error"] = output.Error
|
|
1101
|
-
else:
|
|
1102
|
-
results[str(example.id)]["output"] = output
|
|
1103
|
-
if example.outputs:
|
|
1104
|
-
results[str(example.id)]["reference"] = example.outputs
|
|
1105
|
-
return results
|
|
1106
|
-
|
|
1107
|
-
def _run_batch_evaluators(self, runs: dict[str, Run]) -> list[dict]:
|
|
1108
|
-
evaluators = self.batch_evaluators
|
|
1109
|
-
if not evaluators:
|
|
1110
|
-
return []
|
|
1111
|
-
runs_list = [runs[str(example.id)] for example in self.examples]
|
|
1112
|
-
aggregate_feedback = []
|
|
1113
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
1114
|
-
for evaluator in evaluators:
|
|
1115
|
-
try:
|
|
1116
|
-
result = evaluator(runs_list, self.examples)
|
|
1117
|
-
if isinstance(result, EvaluationResult):
|
|
1118
|
-
result = result.dict()
|
|
1119
|
-
aggregate_feedback.append(cast(dict, result))
|
|
1120
|
-
executor.submit(
|
|
1121
|
-
self.client.create_feedback,
|
|
1122
|
-
**result,
|
|
1123
|
-
run_id=None,
|
|
1124
|
-
project_id=self.project.id,
|
|
1125
|
-
)
|
|
1126
|
-
except Exception:
|
|
1127
|
-
logger.exception(
|
|
1128
|
-
"Error running batch evaluator %s", repr(evaluator)
|
|
1129
|
-
)
|
|
1130
|
-
return aggregate_feedback
|
|
1131
|
-
|
|
1132
|
-
def _collect_metrics(self) -> tuple[dict[str, _RowResult], dict[str, Run]]:
|
|
1133
|
-
all_eval_results: dict = {}
|
|
1134
|
-
all_runs: dict = {}
|
|
1135
|
-
for c in self.configs:
|
|
1136
|
-
for callback in cast(list, c["callbacks"]):
|
|
1137
|
-
if isinstance(callback, EvaluatorCallbackHandler):
|
|
1138
|
-
eval_results = callback.logged_eval_results
|
|
1139
|
-
for (_, example_id), v in eval_results.items():
|
|
1140
|
-
all_eval_results.setdefault(str(example_id), {}).update(
|
|
1141
|
-
{"feedback": v},
|
|
1142
|
-
)
|
|
1143
|
-
elif isinstance(callback, LangChainTracer):
|
|
1144
|
-
run = callback.latest_run
|
|
1145
|
-
execution_time = (
|
|
1146
|
-
(run.end_time - run.start_time).total_seconds()
|
|
1147
|
-
if run and run.end_time
|
|
1148
|
-
else None
|
|
1149
|
-
)
|
|
1150
|
-
run_id = str(run.id) if run else None
|
|
1151
|
-
all_eval_results.setdefault(str(callback.example_id), {}).update(
|
|
1152
|
-
{
|
|
1153
|
-
"execution_time": execution_time,
|
|
1154
|
-
"run_id": run_id,
|
|
1155
|
-
"run": run,
|
|
1156
|
-
},
|
|
1157
|
-
)
|
|
1158
|
-
all_runs[str(callback.example_id)] = run
|
|
1159
|
-
return cast(dict[str, _RowResult], all_eval_results), all_runs
|
|
1160
|
-
|
|
1161
|
-
def _collect_test_results(
|
|
1162
|
-
self,
|
|
1163
|
-
batch_results: list[Union[dict, str, LLMResult, ChatResult]],
|
|
1164
|
-
) -> TestResult:
|
|
1165
|
-
logger.info("Waiting for evaluators to complete.")
|
|
1166
|
-
wait_for_all_evaluators()
|
|
1167
|
-
all_eval_results, all_runs = self._collect_metrics()
|
|
1168
|
-
aggregate_feedback = None
|
|
1169
|
-
if self.batch_evaluators:
|
|
1170
|
-
logger.info("Running session evaluators.")
|
|
1171
|
-
aggregate_feedback = self._run_batch_evaluators(all_runs)
|
|
1172
|
-
results = self._merge_test_outputs(batch_results, all_eval_results)
|
|
1173
|
-
return TestResult(
|
|
1174
|
-
project_name=self.project.name,
|
|
1175
|
-
results=results,
|
|
1176
|
-
aggregate_metrics=aggregate_feedback,
|
|
1177
|
-
)
|
|
1178
|
-
|
|
1179
|
-
def finish(
|
|
1180
|
-
self,
|
|
1181
|
-
batch_results: list,
|
|
1182
|
-
verbose: bool = False, # noqa: FBT001,FBT002
|
|
1183
|
-
) -> TestResult:
|
|
1184
|
-
results = self._collect_test_results(batch_results)
|
|
1185
|
-
if verbose:
|
|
1186
|
-
try:
|
|
1187
|
-
agg_feedback = results.get_aggregate_feedback()
|
|
1188
|
-
_display_aggregate_results(agg_feedback)
|
|
1189
|
-
except Exception as e:
|
|
1190
|
-
logger.debug("Failed to print aggregate feedback: %s", e, exc_info=True)
|
|
1191
|
-
try:
|
|
1192
|
-
# Closing the project permits name changing and metric optimizations
|
|
1193
|
-
self.client.update_project(
|
|
1194
|
-
self.project.id,
|
|
1195
|
-
end_time=datetime.now(timezone.utc),
|
|
1196
|
-
)
|
|
1197
|
-
except Exception as e:
|
|
1198
|
-
logger.debug("Failed to close project: %s", e, exc_info=True)
|
|
1199
|
-
return results
|
|
1200
|
-
|
|
1201
|
-
@classmethod
|
|
1202
|
-
def prepare(
|
|
1203
|
-
cls,
|
|
1204
|
-
client: Client,
|
|
1205
|
-
dataset_name: str,
|
|
1206
|
-
llm_or_chain_factory: MODEL_OR_CHAIN_FACTORY,
|
|
1207
|
-
project_name: Optional[str],
|
|
1208
|
-
evaluation: Optional[smith_eval.RunEvalConfig] = None,
|
|
1209
|
-
tags: Optional[list[str]] = None,
|
|
1210
|
-
input_mapper: Optional[Callable[[dict], Any]] = None,
|
|
1211
|
-
concurrency_level: int = 5,
|
|
1212
|
-
project_metadata: Optional[dict[str, Any]] = None,
|
|
1213
|
-
revision_id: Optional[str] = None,
|
|
1214
|
-
dataset_version: Optional[Union[datetime, str]] = None,
|
|
1215
|
-
) -> _DatasetRunContainer:
|
|
1216
|
-
project_name = project_name or name_generation.random_name()
|
|
1217
|
-
if revision_id:
|
|
1218
|
-
if not project_metadata:
|
|
1219
|
-
project_metadata = {}
|
|
1220
|
-
project_metadata.update({"revision_id": revision_id})
|
|
1221
|
-
wrapped_model, project, dataset, examples = _prepare_eval_run(
|
|
1222
|
-
client,
|
|
1223
|
-
dataset_name,
|
|
1224
|
-
llm_or_chain_factory,
|
|
1225
|
-
project_name,
|
|
1226
|
-
project_metadata=project_metadata,
|
|
1227
|
-
tags=tags,
|
|
1228
|
-
dataset_version=dataset_version,
|
|
1229
|
-
)
|
|
1230
|
-
tags = tags or []
|
|
1231
|
-
for k, v in (project.metadata.get("git") or {}).items():
|
|
1232
|
-
tags.append(f"git:{k}={v}")
|
|
1233
|
-
run_metadata = {"dataset_version": project.metadata["dataset_version"]}
|
|
1234
|
-
if revision_id:
|
|
1235
|
-
run_metadata["revision_id"] = revision_id
|
|
1236
|
-
wrapped_model = _wrap_in_chain_factory(llm_or_chain_factory)
|
|
1237
|
-
run_evaluators = _setup_evaluation(
|
|
1238
|
-
wrapped_model,
|
|
1239
|
-
examples,
|
|
1240
|
-
evaluation,
|
|
1241
|
-
dataset.data_type or DataType.kv,
|
|
1242
|
-
)
|
|
1243
|
-
_validate_example_inputs(examples[0], wrapped_model, input_mapper)
|
|
1244
|
-
progress_bar = progress.ProgressBarCallback(len(examples))
|
|
1245
|
-
configs = [
|
|
1246
|
-
RunnableConfig(
|
|
1247
|
-
callbacks=[
|
|
1248
|
-
LangChainTracer(
|
|
1249
|
-
project_name=project.name,
|
|
1250
|
-
client=client,
|
|
1251
|
-
example_id=example.id,
|
|
1252
|
-
),
|
|
1253
|
-
EvaluatorCallbackHandler(
|
|
1254
|
-
evaluators=run_evaluators or [],
|
|
1255
|
-
client=client,
|
|
1256
|
-
example_id=example.id,
|
|
1257
|
-
max_concurrency=0,
|
|
1258
|
-
),
|
|
1259
|
-
progress_bar,
|
|
1260
|
-
],
|
|
1261
|
-
tags=tags,
|
|
1262
|
-
max_concurrency=concurrency_level,
|
|
1263
|
-
metadata=run_metadata,
|
|
1264
|
-
)
|
|
1265
|
-
for example in examples
|
|
1266
|
-
]
|
|
1267
|
-
return cls(
|
|
1268
|
-
client=client,
|
|
1269
|
-
project=project,
|
|
1270
|
-
wrapped_model=wrapped_model,
|
|
1271
|
-
examples=examples,
|
|
1272
|
-
configs=configs,
|
|
1273
|
-
batch_evaluators=evaluation.batch_evaluators if evaluation else None,
|
|
1274
|
-
)
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
def _is_jupyter_environment() -> bool:
|
|
1278
|
-
try:
|
|
1279
|
-
from IPython.core.getipython import get_ipython
|
|
1280
|
-
|
|
1281
|
-
res = get_ipython()
|
|
1282
|
-
return get_ipython() is not None and "zmqshell" in str(type(res))
|
|
1283
|
-
except ImportError:
|
|
1284
|
-
return False
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
def _display_aggregate_results(aggregate_results: pd.DataFrame) -> None:
|
|
1288
|
-
if _is_jupyter_environment():
|
|
1289
|
-
from IPython.display import HTML, display
|
|
1290
|
-
|
|
1291
|
-
display(HTML("<h3>Experiment Results:</h3>"))
|
|
1292
|
-
display(aggregate_results)
|
|
1293
|
-
else:
|
|
1294
|
-
formatted_string = aggregate_results.to_string(
|
|
1295
|
-
float_format=lambda x: f"{x:.2f}",
|
|
1296
|
-
justify="right",
|
|
1297
|
-
)
|
|
1298
|
-
print("\n Experiment Results:") # noqa: T201
|
|
1299
|
-
print(formatted_string) # noqa: T201
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
_INPUT_MAPPER_DEP_WARNING = (
|
|
1303
|
-
"The input_mapper argument is deprecated and "
|
|
1304
|
-
"will be removed in a future release. Please add a "
|
|
1305
|
-
" RunnableLambda to your chain to map inputs to the expected format"
|
|
1306
|
-
" instead. Example:\n"
|
|
1307
|
-
"def construct_chain():\n"
|
|
1308
|
-
" my_chain = ...\n"
|
|
1309
|
-
" input_mapper = {'other_key': 'MyOtherInput', 'my_input_key': x}\n"
|
|
1310
|
-
" return input_mapper | my_chain\n"
|
|
1311
|
-
"run_on_dataset(..., llm_or_chain_factory=construct_chain)\n"
|
|
1312
|
-
"(See https://api.python.langchain.com/en/latest/schema/"
|
|
1313
|
-
"langchain.schema.runnable.base.RunnableLambda.html)"
|
|
1314
|
-
)
|
|
1315
|
-
|
|
1316
|
-
## Public API
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
async def arun_on_dataset(
|
|
1320
|
-
client: Optional[Client],
|
|
1321
|
-
dataset_name: str,
|
|
1322
|
-
llm_or_chain_factory: MODEL_OR_CHAIN_FACTORY,
|
|
1323
|
-
*,
|
|
1324
|
-
evaluation: Optional[smith_eval.RunEvalConfig] = None,
|
|
1325
|
-
dataset_version: Optional[Union[datetime, str]] = None,
|
|
1326
|
-
concurrency_level: int = 5,
|
|
1327
|
-
project_name: Optional[str] = None,
|
|
1328
|
-
project_metadata: Optional[dict[str, Any]] = None,
|
|
1329
|
-
verbose: bool = False,
|
|
1330
|
-
revision_id: Optional[str] = None,
|
|
1331
|
-
**kwargs: Any,
|
|
1332
|
-
) -> dict[str, Any]:
|
|
1333
|
-
input_mapper = kwargs.pop("input_mapper", None)
|
|
1334
|
-
if input_mapper:
|
|
1335
|
-
warn_deprecated("0.0.305", message=_INPUT_MAPPER_DEP_WARNING, pending=True)
|
|
1336
|
-
if revision_id is None:
|
|
1337
|
-
revision_id = get_langchain_env_var_metadata().get("revision_id")
|
|
1338
|
-
tags = kwargs.pop("tags", None)
|
|
1339
|
-
if tags:
|
|
1340
|
-
warn_deprecated(
|
|
1341
|
-
"0.1.9",
|
|
1342
|
-
message="The tags argument is deprecated and will be"
|
|
1343
|
-
" removed in a future release. Please specify project_metadata instead.",
|
|
1344
|
-
pending=True,
|
|
1345
|
-
)
|
|
1346
|
-
|
|
1347
|
-
if kwargs:
|
|
1348
|
-
warn_deprecated(
|
|
1349
|
-
"0.0.305",
|
|
1350
|
-
message="The following arguments are deprecated and "
|
|
1351
|
-
"will be removed in a future release: "
|
|
1352
|
-
f"{kwargs.keys()}.",
|
|
1353
|
-
removal="0.0.305",
|
|
1354
|
-
)
|
|
1355
|
-
client = client or Client()
|
|
1356
|
-
container = _DatasetRunContainer.prepare(
|
|
1357
|
-
client,
|
|
1358
|
-
dataset_name,
|
|
1359
|
-
llm_or_chain_factory,
|
|
1360
|
-
project_name,
|
|
1361
|
-
evaluation,
|
|
1362
|
-
tags,
|
|
1363
|
-
input_mapper,
|
|
1364
|
-
concurrency_level,
|
|
1365
|
-
project_metadata=project_metadata,
|
|
1366
|
-
revision_id=revision_id,
|
|
1367
|
-
dataset_version=dataset_version,
|
|
1368
|
-
)
|
|
1369
|
-
batch_results = await runnable_utils.gather_with_concurrency(
|
|
1370
|
-
container.configs[0].get("max_concurrency"),
|
|
1371
|
-
*map(
|
|
1372
|
-
functools.partial(
|
|
1373
|
-
_arun_llm_or_chain,
|
|
1374
|
-
llm_or_chain_factory=container.wrapped_model,
|
|
1375
|
-
input_mapper=input_mapper,
|
|
1376
|
-
),
|
|
1377
|
-
container.examples,
|
|
1378
|
-
container.configs,
|
|
1379
|
-
),
|
|
1380
|
-
)
|
|
1381
|
-
return container.finish(batch_results, verbose=verbose)
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
def run_on_dataset(
|
|
1385
|
-
client: Optional[Client],
|
|
1386
|
-
dataset_name: str,
|
|
1387
|
-
llm_or_chain_factory: MODEL_OR_CHAIN_FACTORY,
|
|
1388
|
-
*,
|
|
1389
|
-
evaluation: Optional[smith_eval.RunEvalConfig] = None,
|
|
1390
|
-
dataset_version: Optional[Union[datetime, str]] = None,
|
|
1391
|
-
concurrency_level: int = 5,
|
|
1392
|
-
project_name: Optional[str] = None,
|
|
1393
|
-
project_metadata: Optional[dict[str, Any]] = None,
|
|
1394
|
-
verbose: bool = False,
|
|
1395
|
-
revision_id: Optional[str] = None,
|
|
1396
|
-
**kwargs: Any,
|
|
1397
|
-
) -> dict[str, Any]:
|
|
1398
|
-
input_mapper = kwargs.pop("input_mapper", None)
|
|
1399
|
-
if input_mapper:
|
|
1400
|
-
warn_deprecated("0.0.305", message=_INPUT_MAPPER_DEP_WARNING, pending=True)
|
|
1401
|
-
tags = kwargs.pop("tags", None)
|
|
1402
|
-
if tags:
|
|
1403
|
-
warn_deprecated(
|
|
1404
|
-
"0.1.9",
|
|
1405
|
-
message="The tags argument is deprecated and will be"
|
|
1406
|
-
" removed in a future release. Please specify project_metadata instead.",
|
|
1407
|
-
pending=True,
|
|
1408
|
-
)
|
|
1409
|
-
if revision_id is None:
|
|
1410
|
-
revision_id = get_langchain_env_var_metadata().get("revision_id")
|
|
1411
|
-
|
|
1412
|
-
if kwargs:
|
|
1413
|
-
warn_deprecated(
|
|
1414
|
-
"0.0.305",
|
|
1415
|
-
message="The following arguments are deprecated and "
|
|
1416
|
-
"will be removed in a future release: "
|
|
1417
|
-
f"{kwargs.keys()}.",
|
|
1418
|
-
removal="0.0.305",
|
|
1419
|
-
)
|
|
1420
|
-
client = client or Client()
|
|
1421
|
-
container = _DatasetRunContainer.prepare(
|
|
1422
|
-
client,
|
|
1423
|
-
dataset_name,
|
|
1424
|
-
llm_or_chain_factory,
|
|
1425
|
-
project_name,
|
|
1426
|
-
evaluation,
|
|
1427
|
-
tags,
|
|
1428
|
-
input_mapper,
|
|
1429
|
-
concurrency_level,
|
|
1430
|
-
project_metadata=project_metadata,
|
|
1431
|
-
revision_id=revision_id,
|
|
1432
|
-
dataset_version=dataset_version,
|
|
1433
|
-
)
|
|
1434
|
-
if concurrency_level == 0:
|
|
1435
|
-
batch_results = [
|
|
1436
|
-
_run_llm_or_chain(
|
|
1437
|
-
example,
|
|
1438
|
-
config,
|
|
1439
|
-
llm_or_chain_factory=container.wrapped_model,
|
|
1440
|
-
input_mapper=input_mapper,
|
|
1441
|
-
)
|
|
1442
|
-
for example, config in zip(container.examples, container.configs)
|
|
1443
|
-
]
|
|
1444
|
-
else:
|
|
1445
|
-
with runnable_config.get_executor_for_config(container.configs[0]) as executor:
|
|
1446
|
-
batch_results = list(
|
|
1447
|
-
executor.map(
|
|
1448
|
-
functools.partial(
|
|
1449
|
-
_run_llm_or_chain,
|
|
1450
|
-
llm_or_chain_factory=container.wrapped_model,
|
|
1451
|
-
input_mapper=input_mapper,
|
|
1452
|
-
),
|
|
1453
|
-
container.examples,
|
|
1454
|
-
container.configs,
|
|
1455
|
-
),
|
|
1456
|
-
)
|
|
1457
|
-
|
|
1458
|
-
return container.finish(batch_results, verbose=verbose)
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
_RUN_ON_DATASET_DOCSTRING = """
|
|
1462
|
-
Run the Chain or language model on a dataset and store traces
|
|
1463
|
-
to the specified project name.
|
|
1464
|
-
|
|
1465
|
-
Args:
|
|
1466
|
-
dataset_name: Name of the dataset to run the chain on.
|
|
1467
|
-
llm_or_chain_factory: Language model or Chain constructor to run
|
|
1468
|
-
over the dataset. The Chain constructor is used to permit
|
|
1469
|
-
independent calls on each example without carrying over state.
|
|
1470
|
-
evaluation: Configuration for evaluators to run on the
|
|
1471
|
-
results of the chain
|
|
1472
|
-
concurrency_level: The number of async tasks to run concurrently.
|
|
1473
|
-
project_name: Name of the project to store the traces in.
|
|
1474
|
-
Defaults to {dataset_name}-{chain class name}-{datetime}.
|
|
1475
|
-
project_metadata: Optional metadata to add to the project.
|
|
1476
|
-
Useful for storing information the test variant.
|
|
1477
|
-
(prompt version, model version, etc.)
|
|
1478
|
-
client: LangSmith client to use to access the dataset and to
|
|
1479
|
-
log feedback and run traces.
|
|
1480
|
-
verbose: Whether to print progress.
|
|
1481
|
-
tags: Tags to add to each run in the project.
|
|
1482
|
-
revision_id: Optional revision identifier to assign this test run to
|
|
1483
|
-
track the performance of different versions of your system.
|
|
1484
|
-
Returns:
|
|
1485
|
-
A dictionary containing the run's project name and the resulting model outputs.
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
For the (usually faster) async version of this function, see :func:`arun_on_dataset`.
|
|
1489
|
-
|
|
1490
|
-
Examples
|
|
1491
|
-
--------
|
|
1492
|
-
|
|
1493
|
-
.. code-block:: python
|
|
1494
|
-
|
|
1495
|
-
from langsmith import Client
|
|
1496
|
-
from langchain_openai import ChatOpenAI
|
|
1497
|
-
from langchain.chains import LLMChain
|
|
1498
|
-
from langchain.smith import smith_eval.RunEvalConfig, run_on_dataset
|
|
1499
|
-
|
|
1500
|
-
# Chains may have memory. Passing in a constructor function lets the
|
|
1501
|
-
# evaluation framework avoid cross-contamination between runs.
|
|
1502
|
-
def construct_chain():
|
|
1503
|
-
llm = ChatOpenAI(temperature=0)
|
|
1504
|
-
chain = LLMChain.from_string(
|
|
1505
|
-
llm,
|
|
1506
|
-
"What's the answer to {your_input_key}"
|
|
1507
|
-
)
|
|
1508
|
-
return chain
|
|
1509
|
-
|
|
1510
|
-
# Load off-the-shelf evaluators via config or the EvaluatorType (string or enum)
|
|
1511
|
-
evaluation_config = smith_eval.RunEvalConfig(
|
|
1512
|
-
evaluators=[
|
|
1513
|
-
"qa", # "Correctness" against a reference answer
|
|
1514
|
-
"embedding_distance",
|
|
1515
|
-
smith_eval.RunEvalConfig.Criteria("helpfulness"),
|
|
1516
|
-
smith_eval.RunEvalConfig.Criteria({
|
|
1517
|
-
"fifth-grader-score": "Do you have to be smarter than a fifth grader to answer this question?"
|
|
1518
|
-
}),
|
|
1519
|
-
]
|
|
1520
|
-
)
|
|
1521
|
-
|
|
1522
|
-
client = Client()
|
|
1523
|
-
run_on_dataset(
|
|
1524
|
-
client,
|
|
1525
|
-
dataset_name="<my_dataset_name>",
|
|
1526
|
-
llm_or_chain_factory=construct_chain,
|
|
1527
|
-
evaluation=evaluation_config,
|
|
1528
|
-
)
|
|
1529
|
-
|
|
1530
|
-
You can also create custom evaluators by subclassing the
|
|
1531
|
-
:class:`StringEvaluator <langchain.evaluation.schema.StringEvaluator>`
|
|
1532
|
-
or LangSmith's `RunEvaluator` classes.
|
|
1533
|
-
|
|
1534
|
-
.. code-block:: python
|
|
1535
|
-
|
|
1536
|
-
from typing import Optional
|
|
1537
|
-
from langchain.evaluation import StringEvaluator
|
|
1538
|
-
|
|
1539
|
-
class MyStringEvaluator(StringEvaluator):
|
|
1540
|
-
|
|
1541
|
-
@property
|
|
1542
|
-
def requires_input(self) -> bool:
|
|
1543
|
-
return False
|
|
1544
|
-
|
|
1545
|
-
@property
|
|
1546
|
-
def requires_reference(self) -> bool:
|
|
1547
|
-
return True
|
|
1548
|
-
|
|
1549
|
-
@property
|
|
1550
|
-
def evaluation_name(self) -> str:
|
|
1551
|
-
return "exact_match"
|
|
1552
|
-
|
|
1553
|
-
def _evaluate_strings(self, prediction, reference=None, input=None, **kwargs) -> dict:
|
|
1554
|
-
return {"score": prediction == reference}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
evaluation_config = smith_eval.RunEvalConfig(
|
|
1558
|
-
custom_evaluators = [MyStringEvaluator()],
|
|
1559
|
-
)
|
|
1560
|
-
|
|
1561
|
-
run_on_dataset(
|
|
1562
|
-
client,
|
|
1563
|
-
dataset_name="<my_dataset_name>",
|
|
1564
|
-
llm_or_chain_factory=construct_chain,
|
|
1565
|
-
evaluation=evaluation_config,
|
|
1566
|
-
)
|
|
1567
|
-
""" # noqa: E501
|
|
1568
|
-
run_on_dataset.__doc__ = _RUN_ON_DATASET_DOCSTRING
|
|
1569
|
-
arun_on_dataset.__doc__ = _RUN_ON_DATASET_DOCSTRING.replace(
|
|
1570
|
-
"run_on_dataset(",
|
|
1571
|
-
"await arun_on_dataset(",
|
|
1572
|
-
)
|