langchain 0.2.10 → 0.2.12
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.
- package/chat_models/universal.cjs +1 -0
- package/chat_models/universal.d.cts +1 -0
- package/chat_models/universal.d.ts +1 -0
- package/chat_models/universal.js +1 -0
- package/dist/chat_models/universal.cjs +600 -0
- package/dist/chat_models/universal.d.ts +115 -0
- package/dist/chat_models/universal.js +595 -0
- package/dist/document_loaders/web/assemblyai.cjs +9 -1
- package/dist/document_loaders/web/assemblyai.js +9 -1
- package/dist/experimental/chrome_ai/app/dist/bundle.cjs +1250 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +1 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.js +1249 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/package.json +99 -43
- package/dist/agents/tests/agent.int.test.d.ts +0 -1
- package/dist/agents/tests/agent.int.test.js +0 -309
- package/dist/agents/tests/chat_convo_output_parser.test.d.ts +0 -1
- package/dist/agents/tests/chat_convo_output_parser.test.js +0 -91
- package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +0 -2
- package/dist/agents/tests/create_openai_functions_agent.int.test.js +0 -71
- package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_openai_tools_agent.int.test.js +0 -75
- package/dist/agents/tests/create_react_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_react_agent.int.test.js +0 -32
- package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_structured_chat_agent.int.test.js +0 -32
- package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_tool_calling_agent.int.test.js +0 -122
- package/dist/agents/tests/create_xml_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_xml_agent.int.test.js +0 -32
- package/dist/agents/tests/json.test.d.ts +0 -1
- package/dist/agents/tests/json.test.js +0 -74
- package/dist/agents/tests/react.test.d.ts +0 -1
- package/dist/agents/tests/react.test.js +0 -44
- package/dist/agents/tests/runnable.int.test.d.ts +0 -1
- package/dist/agents/tests/runnable.int.test.js +0 -104
- package/dist/agents/tests/sql.test.d.ts +0 -1
- package/dist/agents/tests/sql.test.js +0 -133
- package/dist/agents/tests/structured_chat_output_parser.test.d.ts +0 -1
- package/dist/agents/tests/structured_chat_output_parser.test.js +0 -35
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +0 -1
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +0 -44
- package/dist/agents/tests/structured_output_runnables.int.test.d.ts +0 -1
- package/dist/agents/tests/structured_output_runnables.int.test.js +0 -112
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +0 -1
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +0 -41
- package/dist/cache/tests/file_system.int.test.d.ts +0 -1
- package/dist/cache/tests/file_system.int.test.js +0 -32
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +0 -139
- package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/extraction.int.test.js +0 -33
- package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/openapi.int.test.js +0 -130
- package/dist/chains/openai_functions/tests/openapi.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/openapi.test.js +0 -172
- package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/structured_output.int.test.js +0 -40
- package/dist/chains/openai_functions/tests/structured_output.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/structured_output.test.js +0 -102
- package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/tagging.int.test.js +0 -21
- package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +0 -1
- package/dist/chains/query_constructor/tests/query_chain.int.test.js +0 -93
- package/dist/chains/query_constructor/tests/query_parser.test.d.ts +0 -1
- package/dist/chains/query_constructor/tests/query_parser.test.js +0 -28
- package/dist/chains/question_answering/tests/load.int.test.d.ts +0 -1
- package/dist/chains/question_answering/tests/load.int.test.js +0 -39
- package/dist/chains/router/tests/multi_prompt.int.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_prompt.int.test.js +0 -45
- package/dist/chains/router/tests/multi_prompt.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_prompt.test.js +0 -62
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +0 -67
- package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_retrieval_qa.test.js +0 -125
- package/dist/chains/summarization/tests/load.int.test.d.ts +0 -1
- package/dist/chains/summarization/tests/load.int.test.js +0 -37
- package/dist/chains/tests/api_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/api_chain.int.test.js +0 -55
- package/dist/chains/tests/combine_docs_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/combine_docs_chain.int.test.js +0 -50
- package/dist/chains/tests/combine_docs_chain.test.d.ts +0 -1
- package/dist/chains/tests/combine_docs_chain.test.js +0 -98
- package/dist/chains/tests/constitutional_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/constitutional_chain.int.test.js +0 -30
- package/dist/chains/tests/constitutional_chain.test.d.ts +0 -1
- package/dist/chains/tests/constitutional_chain.test.js +0 -63
- package/dist/chains/tests/conversation_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/conversation_chain.int.test.js +0 -9
- package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/conversational_retrieval_chain.int.test.js +0 -243
- package/dist/chains/tests/example_data/open_meteo_docs.d.ts +0 -1
- package/dist/chains/tests/example_data/open_meteo_docs.js +0 -29
- package/dist/chains/tests/history_aware_retriever.int.test.d.ts +0 -1
- package/dist/chains/tests/history_aware_retriever.int.test.js +0 -41
- package/dist/chains/tests/history_aware_retriever.test.d.ts +0 -1
- package/dist/chains/tests/history_aware_retriever.test.js +0 -27
- package/dist/chains/tests/llm_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/llm_chain.int.test.js +0 -119
- package/dist/chains/tests/openai_moderation.int.test.d.ts +0 -1
- package/dist/chains/tests/openai_moderation.int.test.js +0 -30
- package/dist/chains/tests/retrieval_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/retrieval_chain.int.test.js +0 -69
- package/dist/chains/tests/retrieval_chain.test.d.ts +0 -1
- package/dist/chains/tests/retrieval_chain.test.js +0 -36
- package/dist/chains/tests/sequential_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/sequential_chain.int.test.js +0 -88
- package/dist/chains/tests/sequential_chain.test.d.ts +0 -1
- package/dist/chains/tests/sequential_chain.test.js +0 -295
- package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/simple_sequential_chain.int.test.js +0 -81
- package/dist/chains/tests/simple_sequential_chain.test.d.ts +0 -1
- package/dist/chains/tests/simple_sequential_chain.test.js +0 -128
- package/dist/chains/tests/sql_db_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/sql_db_chain.int.test.js +0 -125
- package/dist/chains/tests/transform.test.d.ts +0 -1
- package/dist/chains/tests/transform.test.js +0 -12
- package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/vector_db_qa_chain.int.test.js +0 -45
- package/dist/document_loaders/tests/assemblyai.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/assemblyai.int.test.js +0 -111
- package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/chatgpt-blob.test.js +0 -30
- package/dist/document_loaders/tests/chatgpt.test.d.ts +0 -1
- package/dist/document_loaders/tests/chatgpt.test.js +0 -29
- package/dist/document_loaders/tests/cheerio.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/cheerio.int.test.js +0 -21
- package/dist/document_loaders/tests/college_confidential.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/college_confidential.int.test.js +0 -6
- package/dist/document_loaders/tests/confluence.test.d.ts +0 -1
- package/dist/document_loaders/tests/confluence.test.js +0 -52
- package/dist/document_loaders/tests/couchbase.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/couchbase.int.test.js +0 -28
- package/dist/document_loaders/tests/csv-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/csv-blob.test.js +0 -53
- package/dist/document_loaders/tests/csv.test.d.ts +0 -1
- package/dist/document_loaders/tests/csv.test.js +0 -41
- package/dist/document_loaders/tests/directory.test.d.ts +0 -1
- package/dist/document_loaders/tests/directory.test.js +0 -38
- package/dist/document_loaders/tests/docx.test.d.ts +0 -1
- package/dist/document_loaders/tests/docx.test.js +0 -11
- package/dist/document_loaders/tests/epub.test.d.ts +0 -1
- package/dist/document_loaders/tests/epub.test.js +0 -18
- package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +0 -5
- package/dist/document_loaders/tests/example_data/github_api_responses.js +0 -91
- package/dist/document_loaders/tests/figma.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/figma.int.test.js +0 -13
- package/dist/document_loaders/tests/firecrawl.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/firecrawl.int.test.js +0 -30
- package/dist/document_loaders/tests/gitbook.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/gitbook.int.test.js +0 -14
- package/dist/document_loaders/tests/github.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/github.int.test.js +0 -86
- package/dist/document_loaders/tests/github.test.d.ts +0 -1
- package/dist/document_loaders/tests/github.test.js +0 -51
- package/dist/document_loaders/tests/hn.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/hn.int.test.js +0 -6
- package/dist/document_loaders/tests/imsdb.test.d.ts +0 -1
- package/dist/document_loaders/tests/imsdb.test.js +0 -6
- package/dist/document_loaders/tests/json-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/json-blob.test.js +0 -91
- package/dist/document_loaders/tests/json.test.d.ts +0 -1
- package/dist/document_loaders/tests/json.test.js +0 -69
- package/dist/document_loaders/tests/jsonl-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/jsonl-blob.test.js +0 -46
- package/dist/document_loaders/tests/jsonl.test.d.ts +0 -1
- package/dist/document_loaders/tests/jsonl.test.js +0 -15
- package/dist/document_loaders/tests/multi_file.test.d.ts +0 -1
- package/dist/document_loaders/tests/multi_file.test.js +0 -49
- package/dist/document_loaders/tests/notion.test.d.ts +0 -1
- package/dist/document_loaders/tests/notion.test.js +0 -11
- package/dist/document_loaders/tests/notionapi.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/notionapi.int.test.js +0 -80
- package/dist/document_loaders/tests/notionapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/notionapi.test.js +0 -84
- package/dist/document_loaders/tests/notiondb.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/notiondb.int.test.js +0 -13
- package/dist/document_loaders/tests/obsidian.test.d.ts +0 -1
- package/dist/document_loaders/tests/obsidian.test.js +0 -119
- package/dist/document_loaders/tests/pdf-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/pdf-blob.test.js +0 -44
- package/dist/document_loaders/tests/pdf.test.d.ts +0 -1
- package/dist/document_loaders/tests/pdf.test.js +0 -25
- package/dist/document_loaders/tests/playwright_web.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/playwright_web.int.test.js +0 -27
- package/dist/document_loaders/tests/pptx.test.d.ts +0 -1
- package/dist/document_loaders/tests/pptx.test.js +0 -17
- package/dist/document_loaders/tests/puppeteer.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/puppeteer.int.test.js +0 -47
- package/dist/document_loaders/tests/recursive_url.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/recursive_url.int.test.js +0 -64
- package/dist/document_loaders/tests/s3.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/s3.int.test.js +0 -48
- package/dist/document_loaders/tests/searchapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/searchapi.test.js +0 -29
- package/dist/document_loaders/tests/serpapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/serpapi.test.js +0 -21
- package/dist/document_loaders/tests/sitemap.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sitemap.int.test.js +0 -28
- package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sonix_audio.int.test.js +0 -55
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +0 -38
- package/dist/document_loaders/tests/srt-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/srt-blob.test.js +0 -18
- package/dist/document_loaders/tests/srt.test.d.ts +0 -1
- package/dist/document_loaders/tests/srt.test.js +0 -16
- package/dist/document_loaders/tests/text-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/text-blob.test.js +0 -14
- package/dist/document_loaders/tests/text.test.d.ts +0 -1
- package/dist/document_loaders/tests/text.test.js +0 -22
- package/dist/document_loaders/tests/unstructured.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/unstructured.int.test.js +0 -58
- package/dist/document_loaders/tests/webpdf.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/webpdf.int.test.js +0 -90
- package/dist/document_transformers/tests/openai_functions.int.test.d.ts +0 -1
- package/dist/document_transformers/tests/openai_functions.int.test.js +0 -40
- package/dist/embeddings/tests/cache.test.d.ts +0 -1
- package/dist/embeddings/tests/cache.test.js +0 -24
- package/dist/embeddings/tests/fake.test.d.ts +0 -1
- package/dist/embeddings/tests/fake.test.js +0 -34
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +0 -33
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +0 -46
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +0 -108
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +0 -26
- package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/qa/tests/eval_chain.int.test.js +0 -27
- package/dist/experimental/autogpt/tests/output_parser.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/output_parser.test.js +0 -8
- package/dist/experimental/autogpt/tests/prompt.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/prompt.test.js +0 -69
- package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/prompt_generator.test.js +0 -91
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +0 -1
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +0 -26
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +0 -1
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +0 -304
- package/dist/experimental/masking/tests/masking-extended.test.d.ts +0 -1
- package/dist/experimental/masking/tests/masking-extended.test.js +0 -58
- package/dist/experimental/masking/tests/masking.test.d.ts +0 -1
- package/dist/experimental/masking/tests/masking.test.js +0 -388
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +0 -1
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +0 -203
- package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +0 -1
- package/dist/experimental/openai_files/tests/openai_file.int.test.js +0 -87
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +0 -1
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +0 -54
- package/dist/experimental/prompts/tests/handlebars.test.d.ts +0 -1
- package/dist/experimental/prompts/tests/handlebars.test.js +0 -24
- package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +0 -1
- package/dist/experimental/tools/tests/pyinterpreter.int.test.js +0 -22
- package/dist/load/tests/cross_language.test.d.ts +0 -1
- package/dist/load/tests/cross_language.test.js +0 -83
- package/dist/load/tests/load.int.test.d.ts +0 -1
- package/dist/load/tests/load.int.test.js +0 -9
- package/dist/load/tests/load.test.d.ts +0 -1
- package/dist/load/tests/load.test.js +0 -412
- package/dist/memory/tests/buffer_memory.test.d.ts +0 -1
- package/dist/memory/tests/buffer_memory.test.js +0 -34
- package/dist/memory/tests/buffer_token_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/buffer_token_memory.int.test.js +0 -47
- package/dist/memory/tests/buffer_window_memory.test.d.ts +0 -1
- package/dist/memory/tests/buffer_window_memory.test.js +0 -42
- package/dist/memory/tests/combined_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/combined_memory.int.test.js +0 -74
- package/dist/memory/tests/entity_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/entity_memory.int.test.js +0 -79
- package/dist/memory/tests/entity_memory.test.d.ts +0 -1
- package/dist/memory/tests/entity_memory.test.js +0 -48
- package/dist/memory/tests/summary.int.test.d.ts +0 -1
- package/dist/memory/tests/summary.int.test.js +0 -50
- package/dist/memory/tests/summary_buffer.int.test.d.ts +0 -1
- package/dist/memory/tests/summary_buffer.int.test.js +0 -55
- package/dist/memory/tests/vector_store_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/vector_store_memory.int.test.js +0 -55
- package/dist/output_parsers/tests/combining.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/combining.int.test.js +0 -26
- package/dist/output_parsers/tests/combining.test.d.ts +0 -1
- package/dist/output_parsers/tests/combining.test.js +0 -54
- package/dist/output_parsers/tests/datetime.test.d.ts +0 -1
- package/dist/output_parsers/tests/datetime.test.js +0 -14
- package/dist/output_parsers/tests/expression.test.d.ts +0 -1
- package/dist/output_parsers/tests/expression.test.js +0 -339
- package/dist/output_parsers/tests/http_response.test.d.ts +0 -1
- package/dist/output_parsers/tests/http_response.test.js +0 -39
- package/dist/output_parsers/tests/list.test.d.ts +0 -1
- package/dist/output_parsers/tests/list.test.js +0 -27
- package/dist/output_parsers/tests/openai_functions.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/openai_functions.int.test.js +0 -89
- package/dist/output_parsers/tests/openai_tools.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/openai_tools.int.test.js +0 -36
- package/dist/output_parsers/tests/structured.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/structured.int.test.js +0 -150
- package/dist/prompts/tests/selectors.test.d.ts +0 -1
- package/dist/prompts/tests/selectors.test.js +0 -59
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +0 -1
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +0 -330
- package/dist/retrievers/tests/chain_extract.int.test.d.ts +0 -1
- package/dist/retrievers/tests/chain_extract.int.test.js +0 -32
- package/dist/retrievers/tests/ensemble_retriever.int.test.d.ts +0 -1
- package/dist/retrievers/tests/ensemble_retriever.int.test.js +0 -74
- package/dist/retrievers/tests/hyde.int.test.d.ts +0 -1
- package/dist/retrievers/tests/hyde.int.test.js +0 -44
- package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +0 -1
- package/dist/retrievers/tests/matryoshka_retriever.int.test.js +0 -113
- package/dist/retrievers/tests/multi_query.int.test.d.ts +0 -1
- package/dist/retrievers/tests/multi_query.int.test.js +0 -45
- package/dist/retrievers/tests/parent_document.int.test.d.ts +0 -1
- package/dist/retrievers/tests/parent_document.int.test.js +0 -122
- package/dist/retrievers/tests/score_threshold.int.test.d.ts +0 -1
- package/dist/retrievers/tests/score_threshold.int.test.js +0 -83
- package/dist/retrievers/tests/time_weighted.test.d.ts +0 -1
- package/dist/retrievers/tests/time_weighted.test.js +0 -320
- package/dist/retrievers/tests/vectorstores.test.d.ts +0 -1
- package/dist/retrievers/tests/vectorstores.test.js +0 -50
- package/dist/smith/tests/run_on_dataset.int.test.d.ts +0 -1
- package/dist/smith/tests/run_on_dataset.int.test.js +0 -257
- package/dist/smith/tests/runner_utils.int.test.d.ts +0 -9
- package/dist/smith/tests/runner_utils.int.test.js +0 -234
- package/dist/storage/tests/file_system.test.d.ts +0 -1
- package/dist/storage/tests/file_system.test.js +0 -81
- package/dist/tools/tests/chain.test.d.ts +0 -1
- package/dist/tools/tests/chain.test.js +0 -136
- package/dist/tools/tests/webbrowser.int.test.d.ts +0 -1
- package/dist/tools/tests/webbrowser.int.test.js +0 -80
- package/dist/tools/tests/webbrowser.test.d.ts +0 -1
- package/dist/tools/tests/webbrowser.test.js +0 -21
- package/dist/util/tests/async_caller.int.test.d.ts +0 -1
- package/dist/util/tests/async_caller.int.test.js +0 -34
- package/dist/util/tests/azure.test.d.ts +0 -1
- package/dist/util/tests/azure.test.js +0 -42
- package/dist/util/tests/openai-stream.test.d.ts +0 -1
- package/dist/util/tests/openai-stream.test.js +0 -135
- package/dist/util/tests/set.test.d.ts +0 -1
- package/dist/util/tests/set.test.js +0 -36
- package/dist/util/tests/sql_utils.test.d.ts +0 -1
- package/dist/util/tests/sql_utils.test.js +0 -50
- package/dist/vectorstores/tests/memory.test.d.ts +0 -1
- package/dist/vectorstores/tests/memory.test.js +0 -78
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
|
|
2
|
+
import { RunnableBinding, ensureConfig, } from "@langchain/core/runnables";
|
|
3
|
+
import { AsyncGeneratorWithSetup, IterableReadableStream, } from "@langchain/core/utils/stream";
|
|
4
|
+
const _SUPPORTED_PROVIDERS = [
|
|
5
|
+
"openai",
|
|
6
|
+
"anthropic",
|
|
7
|
+
"azure_openai",
|
|
8
|
+
"cohere",
|
|
9
|
+
"google-vertexai",
|
|
10
|
+
"google-genai",
|
|
11
|
+
"ollama",
|
|
12
|
+
"together",
|
|
13
|
+
"fireworks",
|
|
14
|
+
"mistralai",
|
|
15
|
+
"groq",
|
|
16
|
+
"bedrock",
|
|
17
|
+
];
|
|
18
|
+
async function _initChatModelHelper(model, modelProvider,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
params = {}) {
|
|
21
|
+
const modelProviderCopy = modelProvider || _inferModelProvider(model);
|
|
22
|
+
if (!modelProviderCopy) {
|
|
23
|
+
throw new Error(`Unable to infer model provider for { model: ${model} }, please specify modelProvider directly.`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
switch (modelProviderCopy) {
|
|
27
|
+
case "openai": {
|
|
28
|
+
const { ChatOpenAI } = await import("@langchain/openai");
|
|
29
|
+
return new ChatOpenAI({ model, ...params });
|
|
30
|
+
}
|
|
31
|
+
case "anthropic": {
|
|
32
|
+
const { ChatAnthropic } = await import("@langchain/anthropic");
|
|
33
|
+
return new ChatAnthropic({ model, ...params });
|
|
34
|
+
}
|
|
35
|
+
case "azure_openai": {
|
|
36
|
+
const { AzureChatOpenAI } = await import("@langchain/openai");
|
|
37
|
+
return new AzureChatOpenAI({ model, ...params });
|
|
38
|
+
}
|
|
39
|
+
case "cohere": {
|
|
40
|
+
const { ChatCohere } = await import("@langchain/cohere");
|
|
41
|
+
return new ChatCohere({ model, ...params });
|
|
42
|
+
}
|
|
43
|
+
case "google-vertexai": {
|
|
44
|
+
const { ChatVertexAI } = await import("@langchain/google-vertexai");
|
|
45
|
+
return new ChatVertexAI({ model, ...params });
|
|
46
|
+
}
|
|
47
|
+
case "google-genai": {
|
|
48
|
+
const { ChatGoogleGenerativeAI } = await import("@langchain/google-genai");
|
|
49
|
+
return new ChatGoogleGenerativeAI({ model, ...params });
|
|
50
|
+
}
|
|
51
|
+
case "ollama": {
|
|
52
|
+
const { ChatOllama } = await import("@langchain/ollama");
|
|
53
|
+
return new ChatOllama({ model, ...params });
|
|
54
|
+
}
|
|
55
|
+
case "mistralai": {
|
|
56
|
+
const { ChatMistralAI } = await import("@langchain/mistralai");
|
|
57
|
+
return new ChatMistralAI({ model, ...params });
|
|
58
|
+
}
|
|
59
|
+
case "groq": {
|
|
60
|
+
const { ChatGroq } = await import("@langchain/groq");
|
|
61
|
+
return new ChatGroq({ model, ...params });
|
|
62
|
+
}
|
|
63
|
+
case "bedrock": {
|
|
64
|
+
const { ChatBedrockConverse } = await import("@langchain/aws");
|
|
65
|
+
return new ChatBedrockConverse({ model, ...params });
|
|
66
|
+
}
|
|
67
|
+
case "fireworks": {
|
|
68
|
+
const { ChatFireworks } = await import(
|
|
69
|
+
// We can not 'expect-error' because if you explicitly build `@langchain/community`
|
|
70
|
+
// this import will be able to be resolved, thus there will be no error. However
|
|
71
|
+
// this will never be the case in CI.
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore - Can not install as a proper dependency due to circular dependency
|
|
74
|
+
"@langchain/community/chat_models/fireworks");
|
|
75
|
+
return new ChatFireworks({ model, ...params });
|
|
76
|
+
}
|
|
77
|
+
case "together": {
|
|
78
|
+
const { ChatTogetherAI } = await import(
|
|
79
|
+
// We can not 'expect-error' because if you explicitly build `@langchain/community`
|
|
80
|
+
// this import will be able to be resolved, thus there will be no error. However
|
|
81
|
+
// this will never be the case in CI.
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
83
|
+
// @ts-ignore - Can not install as a proper dependency due to circular dependency
|
|
84
|
+
"@langchain/community/chat_models/togetherai");
|
|
85
|
+
return new ChatTogetherAI({ model, ...params });
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
const supported = _SUPPORTED_PROVIDERS.join(", ");
|
|
89
|
+
throw new Error(`Unsupported { modelProvider: ${modelProviderCopy} }.\n\nSupported model providers are: ${supported}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
if ("code" in e && e.code.includes("ERR_MODULE_NOT_FOUND")) {
|
|
96
|
+
const attemptedPackage = new Error(e).message
|
|
97
|
+
.split("Error: Cannot find package '")[1]
|
|
98
|
+
.split("'")[0];
|
|
99
|
+
throw new Error(`Unable to import ${attemptedPackage}. Please install with ` +
|
|
100
|
+
`\`npm install ${attemptedPackage}\` or \`yarn add ${attemptedPackage}\``);
|
|
101
|
+
}
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Attempts to infer the model provider based on the given model name.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} modelName - The name of the model to infer the provider for.
|
|
109
|
+
* @returns {string | undefined} The inferred model provider name, or undefined if unable to infer.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* _inferModelProvider("gpt-4"); // returns "openai"
|
|
113
|
+
* _inferModelProvider("claude-2"); // returns "anthropic"
|
|
114
|
+
* _inferModelProvider("unknown-model"); // returns undefined
|
|
115
|
+
*/
|
|
116
|
+
export function _inferModelProvider(modelName) {
|
|
117
|
+
if (modelName.startsWith("gpt-3") || modelName.startsWith("gpt-4")) {
|
|
118
|
+
return "openai";
|
|
119
|
+
}
|
|
120
|
+
else if (modelName.startsWith("claude")) {
|
|
121
|
+
return "anthropic";
|
|
122
|
+
}
|
|
123
|
+
else if (modelName.startsWith("command")) {
|
|
124
|
+
return "cohere";
|
|
125
|
+
}
|
|
126
|
+
else if (modelName.startsWith("accounts/fireworks")) {
|
|
127
|
+
return "fireworks";
|
|
128
|
+
}
|
|
129
|
+
else if (modelName.startsWith("gemini")) {
|
|
130
|
+
return "google-vertexai";
|
|
131
|
+
}
|
|
132
|
+
else if (modelName.startsWith("amazon.")) {
|
|
133
|
+
return "bedrock";
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
class _ConfigurableModel extends BaseChatModel {
|
|
140
|
+
_llmType() {
|
|
141
|
+
return "chat_model";
|
|
142
|
+
}
|
|
143
|
+
constructor(fields) {
|
|
144
|
+
super(fields);
|
|
145
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: true,
|
|
148
|
+
writable: true,
|
|
149
|
+
value: ["langchain", "chat_models"]
|
|
150
|
+
});
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
152
|
+
Object.defineProperty(this, "_defaultConfig", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: true,
|
|
155
|
+
writable: true,
|
|
156
|
+
value: {}
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* @default "any"
|
|
160
|
+
*/
|
|
161
|
+
Object.defineProperty(this, "_configurableFields", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
configurable: true,
|
|
164
|
+
writable: true,
|
|
165
|
+
value: "any"
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* @default ""
|
|
169
|
+
*/
|
|
170
|
+
Object.defineProperty(this, "_configPrefix", {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
configurable: true,
|
|
173
|
+
writable: true,
|
|
174
|
+
value: void 0
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* Methods which should be called after the model is initialized.
|
|
178
|
+
* The key will be the method name, and the value will be the arguments.
|
|
179
|
+
*/
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
|
+
Object.defineProperty(this, "_queuedMethodOperations", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
configurable: true,
|
|
184
|
+
writable: true,
|
|
185
|
+
value: {}
|
|
186
|
+
});
|
|
187
|
+
// Extract the input types from the `BaseModel` class.
|
|
188
|
+
Object.defineProperty(this, "withStructuredOutput", {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
configurable: true,
|
|
191
|
+
writable: true,
|
|
192
|
+
value: (schema, ...args) => {
|
|
193
|
+
this._queuedMethodOperations.withStructuredOutput = [schema, ...args];
|
|
194
|
+
return new _ConfigurableModel({
|
|
195
|
+
defaultConfig: this._defaultConfig,
|
|
196
|
+
configurableFields: this._configurableFields,
|
|
197
|
+
configPrefix: this._configPrefix,
|
|
198
|
+
queuedMethodOperations: this._queuedMethodOperations,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
this._defaultConfig = fields.defaultConfig ?? {};
|
|
203
|
+
if (fields.configurableFields === "any") {
|
|
204
|
+
this._configurableFields = "any";
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
this._configurableFields = fields.configurableFields ?? "any";
|
|
208
|
+
}
|
|
209
|
+
if (fields.configPrefix) {
|
|
210
|
+
this._configPrefix = fields.configPrefix.endsWith("_")
|
|
211
|
+
? fields.configPrefix
|
|
212
|
+
: `${fields.configPrefix}_`;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this._configPrefix = "";
|
|
216
|
+
}
|
|
217
|
+
this._queuedMethodOperations =
|
|
218
|
+
fields.queuedMethodOperations ?? this._queuedMethodOperations;
|
|
219
|
+
}
|
|
220
|
+
async _model(config) {
|
|
221
|
+
const params = { ...this._defaultConfig, ...this._modelParams(config) };
|
|
222
|
+
let initializedModel = await _initChatModelHelper(params.model, params.modelProvider, params);
|
|
223
|
+
// Apply queued method operations
|
|
224
|
+
const queuedMethodOperationsEntries = Object.entries(this._queuedMethodOperations);
|
|
225
|
+
if (queuedMethodOperationsEntries.length > 0) {
|
|
226
|
+
for (const [method, args] of queuedMethodOperationsEntries) {
|
|
227
|
+
if (method in initializedModel &&
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
+
typeof initializedModel[method] === "function") {
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
231
|
+
initializedModel = await initializedModel[method](...args);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return initializedModel;
|
|
236
|
+
}
|
|
237
|
+
async _generate(messages, options, runManager) {
|
|
238
|
+
const model = await this._model(options);
|
|
239
|
+
return model._generate(messages, options ?? {}, runManager);
|
|
240
|
+
}
|
|
241
|
+
bindTools(tools,
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
|
+
params) {
|
|
244
|
+
this._queuedMethodOperations.bindTools = [tools, params];
|
|
245
|
+
return new _ConfigurableModel({
|
|
246
|
+
defaultConfig: this._defaultConfig,
|
|
247
|
+
configurableFields: this._configurableFields,
|
|
248
|
+
configPrefix: this._configPrefix,
|
|
249
|
+
queuedMethodOperations: this._queuedMethodOperations,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
_modelParams(config) {
|
|
254
|
+
const configurable = config?.configurable ?? {};
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
256
|
+
let modelParams = {};
|
|
257
|
+
for (const [key, value] of Object.entries(configurable)) {
|
|
258
|
+
if (key.startsWith(this._configPrefix)) {
|
|
259
|
+
const strippedKey = this._removePrefix(key, this._configPrefix);
|
|
260
|
+
modelParams[strippedKey] = value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (this._configurableFields !== "any") {
|
|
264
|
+
modelParams = Object.fromEntries(Object.entries(modelParams).filter(([key]) => this._configurableFields.includes(key)));
|
|
265
|
+
}
|
|
266
|
+
return modelParams;
|
|
267
|
+
}
|
|
268
|
+
_removePrefix(str, prefix) {
|
|
269
|
+
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Bind config to a Runnable, returning a new Runnable.
|
|
273
|
+
* @param {RunnableConfig | undefined} [config] - The config to bind.
|
|
274
|
+
* @returns {RunnableBinding<RunInput, RunOutput, CallOptions>} A new RunnableBinding with the bound config.
|
|
275
|
+
*/
|
|
276
|
+
withConfig(config) {
|
|
277
|
+
const mergedConfig = { ...(config || {}) };
|
|
278
|
+
const modelParams = this._modelParams(mergedConfig);
|
|
279
|
+
const remainingConfig = Object.fromEntries(Object.entries(mergedConfig).filter(([k]) => k !== "configurable"));
|
|
280
|
+
remainingConfig.configurable = Object.fromEntries(Object.entries(mergedConfig.configurable || {}).filter(([k]) => this._configPrefix &&
|
|
281
|
+
!Object.keys(modelParams).includes(this._removePrefix(k, this._configPrefix))));
|
|
282
|
+
const newConfigurableModel = new _ConfigurableModel({
|
|
283
|
+
defaultConfig: { ...this._defaultConfig, ...modelParams },
|
|
284
|
+
configurableFields: Array.isArray(this._configurableFields)
|
|
285
|
+
? [...this._configurableFields]
|
|
286
|
+
: this._configurableFields,
|
|
287
|
+
configPrefix: this._configPrefix,
|
|
288
|
+
});
|
|
289
|
+
return new RunnableBinding({
|
|
290
|
+
config: mergedConfig,
|
|
291
|
+
bound: newConfigurableModel,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
async invoke(input, options) {
|
|
295
|
+
const model = await this._model(options);
|
|
296
|
+
const config = ensureConfig(options);
|
|
297
|
+
return model.invoke(input, config);
|
|
298
|
+
}
|
|
299
|
+
async stream(input, options) {
|
|
300
|
+
const model = await this._model(options);
|
|
301
|
+
const wrappedGenerator = new AsyncGeneratorWithSetup({
|
|
302
|
+
generator: await model.stream(input, options),
|
|
303
|
+
config: options,
|
|
304
|
+
});
|
|
305
|
+
await wrappedGenerator.setup;
|
|
306
|
+
return IterableReadableStream.fromAsyncGenerator(wrappedGenerator);
|
|
307
|
+
}
|
|
308
|
+
async batch(inputs, options, batchOptions) {
|
|
309
|
+
// We can super this since the base runnable implementation of
|
|
310
|
+
// `.batch` will call `.invoke` on each input.
|
|
311
|
+
return super.batch(inputs, options, batchOptions);
|
|
312
|
+
}
|
|
313
|
+
async *transform(generator, options) {
|
|
314
|
+
const model = await this._model(options);
|
|
315
|
+
const config = ensureConfig(options);
|
|
316
|
+
yield* model.transform(generator, config);
|
|
317
|
+
}
|
|
318
|
+
async *streamLog(input, options, streamOptions) {
|
|
319
|
+
const model = await this._model(options);
|
|
320
|
+
const config = ensureConfig(options);
|
|
321
|
+
yield* model.streamLog(input, config, {
|
|
322
|
+
...streamOptions,
|
|
323
|
+
_schemaFormat: "original",
|
|
324
|
+
includeNames: streamOptions?.includeNames,
|
|
325
|
+
includeTypes: streamOptions?.includeTypes,
|
|
326
|
+
includeTags: streamOptions?.includeTags,
|
|
327
|
+
excludeNames: streamOptions?.excludeNames,
|
|
328
|
+
excludeTypes: streamOptions?.excludeTypes,
|
|
329
|
+
excludeTags: streamOptions?.excludeTags,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
streamEvents(input, options, streamOptions) {
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
334
|
+
const outerThis = this;
|
|
335
|
+
async function* wrappedGenerator() {
|
|
336
|
+
const model = await outerThis._model(options);
|
|
337
|
+
const config = ensureConfig(options);
|
|
338
|
+
const eventStream = model.streamEvents(input, config, streamOptions);
|
|
339
|
+
for await (const chunk of eventStream) {
|
|
340
|
+
yield chunk;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return IterableReadableStream.fromAsyncGenerator(wrappedGenerator());
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// ################################# FOR CONTRIBUTORS #################################
|
|
347
|
+
//
|
|
348
|
+
// If adding support for a new provider, please append the provider
|
|
349
|
+
// name to the supported list in the docstring below.
|
|
350
|
+
//
|
|
351
|
+
// ####################################################################################
|
|
352
|
+
/**
|
|
353
|
+
* Initialize a ChatModel from the model name and provider.
|
|
354
|
+
* Must have the integration package corresponding to the model provider installed.
|
|
355
|
+
*
|
|
356
|
+
* @template {extends BaseLanguageModelInput = BaseLanguageModelInput} RunInput - The input type for the model.
|
|
357
|
+
* @template {extends ConfigurableChatModelCallOptions = ConfigurableChatModelCallOptions} CallOptions - Call options for the model.
|
|
358
|
+
*
|
|
359
|
+
* @param {string | ChatModelProvider} [model] - The name of the model, e.g. "gpt-4", "claude-3-opus-20240229".
|
|
360
|
+
* @param {Object} [fields] - Additional configuration options.
|
|
361
|
+
* @param {string} [fields.modelProvider] - The model provider. Supported values include:
|
|
362
|
+
* - openai (@langchain/openai)
|
|
363
|
+
* - anthropic (@langchain/anthropic)
|
|
364
|
+
* - azure_openai (@langchain/openai)
|
|
365
|
+
* - google-vertexai (@langchain/google-vertexai)
|
|
366
|
+
* - google-genai (@langchain/google-genai)
|
|
367
|
+
* - bedrock (@langchain/aws)
|
|
368
|
+
* - cohere (@langchain/cohere)
|
|
369
|
+
* - fireworks (@langchain/community/chat_models/fireworks)
|
|
370
|
+
* - together (@langchain/community/chat_models/togetherai)
|
|
371
|
+
* - mistralai (@langchain/mistralai)
|
|
372
|
+
* - groq (@langchain/groq)
|
|
373
|
+
* - ollama (@langchain/ollama)
|
|
374
|
+
* @param {string[] | "any"} [fields.configurableFields] - Which model parameters are configurable:
|
|
375
|
+
* - undefined: No configurable fields.
|
|
376
|
+
* - "any": All fields are configurable. (See Security Note in description)
|
|
377
|
+
* - string[]: Specified fields are configurable.
|
|
378
|
+
* @param {string} [fields.configPrefix] - Prefix for configurable fields at runtime.
|
|
379
|
+
* @param {Record<string, any>} [fields.params] - Additional keyword args to pass to the ChatModel constructor.
|
|
380
|
+
* @returns {Promise<_ConfigurableModel<RunInput, CallOptions>>} A class which extends BaseChatModel.
|
|
381
|
+
* @throws {Error} If modelProvider cannot be inferred or isn't supported.
|
|
382
|
+
* @throws {Error} If the model provider integration package is not installed.
|
|
383
|
+
*
|
|
384
|
+
* @example Initialize non-configurable models
|
|
385
|
+
* ```typescript
|
|
386
|
+
* import { initChatModel } from "langchain/chat_models/universal";
|
|
387
|
+
*
|
|
388
|
+
* const gpt4 = await initChatModel("gpt-4", {
|
|
389
|
+
* modelProvider: "openai",
|
|
390
|
+
* temperature: 0.25,
|
|
391
|
+
* });
|
|
392
|
+
* const gpt4Result = await gpt4.invoke("what's your name");
|
|
393
|
+
*
|
|
394
|
+
* const claude = await initChatModel("claude-3-opus-20240229", {
|
|
395
|
+
* modelProvider: "anthropic",
|
|
396
|
+
* temperature: 0.25,
|
|
397
|
+
* });
|
|
398
|
+
* const claudeResult = await claude.invoke("what's your name");
|
|
399
|
+
*
|
|
400
|
+
* const gemini = await initChatModel("gemini-1.5-pro", {
|
|
401
|
+
* modelProvider: "google-vertexai",
|
|
402
|
+
* temperature: 0.25,
|
|
403
|
+
* });
|
|
404
|
+
* const geminiResult = await gemini.invoke("what's your name");
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* @example Create a partially configurable model with no default model
|
|
408
|
+
* ```typescript
|
|
409
|
+
* import { initChatModel } from "langchain/chat_models/universal";
|
|
410
|
+
*
|
|
411
|
+
* const configurableModel = await initChatModel(undefined, {
|
|
412
|
+
* temperature: 0,
|
|
413
|
+
* configurableFields: ["model", "apiKey"],
|
|
414
|
+
* });
|
|
415
|
+
*
|
|
416
|
+
* const gpt4Result = await configurableModel.invoke("what's your name", {
|
|
417
|
+
* configurable: {
|
|
418
|
+
* model: "gpt-4",
|
|
419
|
+
* },
|
|
420
|
+
* });
|
|
421
|
+
*
|
|
422
|
+
* const claudeResult = await configurableModel.invoke("what's your name", {
|
|
423
|
+
* configurable: {
|
|
424
|
+
* model: "claude-3-5-sonnet-20240620",
|
|
425
|
+
* },
|
|
426
|
+
* });
|
|
427
|
+
* ```
|
|
428
|
+
*
|
|
429
|
+
* @example Create a fully configurable model with a default model and a config prefix
|
|
430
|
+
* ```typescript
|
|
431
|
+
* import { initChatModel } from "langchain/chat_models/universal";
|
|
432
|
+
*
|
|
433
|
+
* const configurableModelWithDefault = await initChatModel("gpt-4", {
|
|
434
|
+
* modelProvider: "openai",
|
|
435
|
+
* configurableFields: "any",
|
|
436
|
+
* configPrefix: "foo",
|
|
437
|
+
* temperature: 0,
|
|
438
|
+
* });
|
|
439
|
+
*
|
|
440
|
+
* const openaiResult = await configurableModelWithDefault.invoke(
|
|
441
|
+
* "what's your name",
|
|
442
|
+
* {
|
|
443
|
+
* configurable: {
|
|
444
|
+
* foo_apiKey: process.env.OPENAI_API_KEY,
|
|
445
|
+
* },
|
|
446
|
+
* }
|
|
447
|
+
* );
|
|
448
|
+
*
|
|
449
|
+
* const claudeResult = await configurableModelWithDefault.invoke(
|
|
450
|
+
* "what's your name",
|
|
451
|
+
* {
|
|
452
|
+
* configurable: {
|
|
453
|
+
* foo_model: "claude-3-5-sonnet-20240620",
|
|
454
|
+
* foo_modelProvider: "anthropic",
|
|
455
|
+
* foo_temperature: 0.6,
|
|
456
|
+
* foo_apiKey: process.env.ANTHROPIC_API_KEY,
|
|
457
|
+
* },
|
|
458
|
+
* }
|
|
459
|
+
* );
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @example Bind tools to a configurable model:
|
|
463
|
+
* ```typescript
|
|
464
|
+
* import { initChatModel } from "langchain/chat_models/universal";
|
|
465
|
+
* import { z } from "zod";
|
|
466
|
+
* import { tool } from "@langchain/core/tools";
|
|
467
|
+
*
|
|
468
|
+
* const getWeatherTool = tool(
|
|
469
|
+
* (input) => {
|
|
470
|
+
* // Do something with the input
|
|
471
|
+
* return JSON.stringify(input);
|
|
472
|
+
* },
|
|
473
|
+
* {
|
|
474
|
+
* schema: z
|
|
475
|
+
* .object({
|
|
476
|
+
* location: z
|
|
477
|
+
* .string()
|
|
478
|
+
* .describe("The city and state, e.g. San Francisco, CA"),
|
|
479
|
+
* })
|
|
480
|
+
* .describe("Get the current weather in a given location"),
|
|
481
|
+
* name: "GetWeather",
|
|
482
|
+
* description: "Get the current weather in a given location",
|
|
483
|
+
* }
|
|
484
|
+
* );
|
|
485
|
+
*
|
|
486
|
+
* const getPopulationTool = tool(
|
|
487
|
+
* (input) => {
|
|
488
|
+
* // Do something with the input
|
|
489
|
+
* return JSON.stringify(input);
|
|
490
|
+
* },
|
|
491
|
+
* {
|
|
492
|
+
* schema: z
|
|
493
|
+
* .object({
|
|
494
|
+
* location: z
|
|
495
|
+
* .string()
|
|
496
|
+
* .describe("The city and state, e.g. San Francisco, CA"),
|
|
497
|
+
* })
|
|
498
|
+
* .describe("Get the current population in a given location"),
|
|
499
|
+
* name: "GetPopulation",
|
|
500
|
+
* description: "Get the current population in a given location",
|
|
501
|
+
* }
|
|
502
|
+
* );
|
|
503
|
+
*
|
|
504
|
+
* const configurableModel = await initChatModel("gpt-4", {
|
|
505
|
+
* configurableFields: ["model", "modelProvider", "apiKey"],
|
|
506
|
+
* temperature: 0,
|
|
507
|
+
* });
|
|
508
|
+
*
|
|
509
|
+
* const configurableModelWithTools = configurableModel.bind({
|
|
510
|
+
* tools: [getWeatherTool, getPopulationTool],
|
|
511
|
+
* });
|
|
512
|
+
*
|
|
513
|
+
* const configurableToolResult = await configurableModelWithTools.invoke(
|
|
514
|
+
* "Which city is hotter today and which is bigger: LA or NY?",
|
|
515
|
+
* {
|
|
516
|
+
* configurable: {
|
|
517
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
518
|
+
* },
|
|
519
|
+
* }
|
|
520
|
+
* );
|
|
521
|
+
*
|
|
522
|
+
* const configurableToolResult2 = await configurableModelWithTools.invoke(
|
|
523
|
+
* "Which city is hotter today and which is bigger: LA or NY?",
|
|
524
|
+
* {
|
|
525
|
+
* configurable: {
|
|
526
|
+
* model: "claude-3-5-sonnet-20240620",
|
|
527
|
+
* apiKey: process.env.ANTHROPIC_API_KEY,
|
|
528
|
+
* },
|
|
529
|
+
* }
|
|
530
|
+
* );
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
533
|
+
* @description
|
|
534
|
+
* This function initializes a ChatModel based on the provided model name and provider.
|
|
535
|
+
* It supports various model providers and allows for runtime configuration of model parameters.
|
|
536
|
+
*
|
|
537
|
+
* Security Note: Setting `configurableFields` to "any" means fields like api_key, base_url, etc.
|
|
538
|
+
* can be altered at runtime, potentially redirecting model requests to a different service/user.
|
|
539
|
+
* Make sure that if you're accepting untrusted configurations, you enumerate the
|
|
540
|
+
* `configurableFields` explicitly.
|
|
541
|
+
*
|
|
542
|
+
* The function will attempt to infer the model provider from the model name if not specified.
|
|
543
|
+
* Certain model name prefixes are associated with specific providers:
|
|
544
|
+
* - gpt-3... or gpt-4... -> openai
|
|
545
|
+
* - claude... -> anthropic
|
|
546
|
+
* - amazon.... -> bedrock
|
|
547
|
+
* - gemini... -> google-vertexai
|
|
548
|
+
* - command... -> cohere
|
|
549
|
+
* - accounts/fireworks... -> fireworks
|
|
550
|
+
*
|
|
551
|
+
* @since 0.2.11
|
|
552
|
+
* @version 0.2.11
|
|
553
|
+
*/
|
|
554
|
+
export async function initChatModel(model,
|
|
555
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
556
|
+
fields) {
|
|
557
|
+
const { configurableFields, configPrefix, modelProvider, ...params } = {
|
|
558
|
+
configPrefix: "",
|
|
559
|
+
...(fields ?? {}),
|
|
560
|
+
};
|
|
561
|
+
let configurableFieldsCopy = configurableFields;
|
|
562
|
+
if (!model && !configurableFieldsCopy) {
|
|
563
|
+
configurableFieldsCopy = ["model", "modelProvider"];
|
|
564
|
+
}
|
|
565
|
+
if (configPrefix && !configurableFieldsCopy) {
|
|
566
|
+
console.warn(`{ configPrefix: ${configPrefix} } has been set but no fields are configurable. Set ` +
|
|
567
|
+
`{ configurableFields: [...] } to specify the model params that are ` +
|
|
568
|
+
`configurable.`);
|
|
569
|
+
}
|
|
570
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
571
|
+
const paramsCopy = { ...params };
|
|
572
|
+
if (!configurableFieldsCopy) {
|
|
573
|
+
return new _ConfigurableModel({
|
|
574
|
+
defaultConfig: {
|
|
575
|
+
...paramsCopy,
|
|
576
|
+
model,
|
|
577
|
+
modelProvider,
|
|
578
|
+
},
|
|
579
|
+
configPrefix,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
if (model) {
|
|
584
|
+
paramsCopy.model = model;
|
|
585
|
+
}
|
|
586
|
+
if (modelProvider) {
|
|
587
|
+
paramsCopy.modelProvider = modelProvider;
|
|
588
|
+
}
|
|
589
|
+
return new _ConfigurableModel({
|
|
590
|
+
defaultConfig: paramsCopy,
|
|
591
|
+
configPrefix,
|
|
592
|
+
configurableFields: configurableFieldsCopy,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
@@ -10,6 +10,11 @@ const entrypoint_deprecation_js_1 = require("../../util/entrypoint_deprecation.c
|
|
|
10
10
|
oldEntrypointName: "document_loaders/web/assemblyai",
|
|
11
11
|
newPackageName: "@langchain/community",
|
|
12
12
|
});
|
|
13
|
+
const defaultOptions = {
|
|
14
|
+
userAgent: {
|
|
15
|
+
integration: { name: "LangChainJS", version: "1.0.1" },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
13
18
|
/**
|
|
14
19
|
* @deprecated
|
|
15
20
|
* Base class for AssemblyAI loaders.
|
|
@@ -38,7 +43,10 @@ class AssemblyAILoader extends base_js_1.BaseDocumentLoader {
|
|
|
38
43
|
if (!options.apiKey) {
|
|
39
44
|
throw new Error("No AssemblyAI API key provided");
|
|
40
45
|
}
|
|
41
|
-
this.client = new assemblyai_1.AssemblyAI(
|
|
46
|
+
this.client = new assemblyai_1.AssemblyAI({
|
|
47
|
+
...defaultOptions,
|
|
48
|
+
...options,
|
|
49
|
+
});
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
@@ -7,6 +7,11 @@ import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation
|
|
|
7
7
|
oldEntrypointName: "document_loaders/web/assemblyai",
|
|
8
8
|
newPackageName: "@langchain/community",
|
|
9
9
|
});
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
userAgent: {
|
|
12
|
+
integration: { name: "LangChainJS", version: "1.0.1" },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
10
15
|
/**
|
|
11
16
|
* @deprecated
|
|
12
17
|
* Base class for AssemblyAI loaders.
|
|
@@ -35,7 +40,10 @@ class AssemblyAILoader extends BaseDocumentLoader {
|
|
|
35
40
|
if (!options.apiKey) {
|
|
36
41
|
throw new Error("No AssemblyAI API key provided");
|
|
37
42
|
}
|
|
38
|
-
this.client = new AssemblyAI(
|
|
43
|
+
this.client = new AssemblyAI({
|
|
44
|
+
...defaultOptions,
|
|
45
|
+
...options,
|
|
46
|
+
});
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
/**
|