langchain 0.2.9 → 0.2.11
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/agents/executor.cjs +6 -0
- package/dist/agents/executor.js +6 -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/dist/retrievers/parent_document.cjs +1 -1
- package/dist/retrievers/parent_document.d.ts +1 -1
- package/dist/retrievers/parent_document.js +1 -1
- package/package.json +65 -6
- 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
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { ConsoleCallbackHandler } from "@langchain/core/tracers/console";
|
|
3
|
-
import { OpenAIChat } from "@langchain/openai";
|
|
4
|
-
import { MultiPromptChain } from "../multi_prompt.js";
|
|
5
|
-
test("Test MultiPromptChain", async () => {
|
|
6
|
-
const llm = new OpenAIChat({
|
|
7
|
-
callbacks: [new ConsoleCallbackHandler()],
|
|
8
|
-
});
|
|
9
|
-
const promptNames = ["physics", "math", "history"];
|
|
10
|
-
const promptDescriptions = [
|
|
11
|
-
"Good for answering questions about physics",
|
|
12
|
-
"Good for answering math questions",
|
|
13
|
-
"Good for answering questions about history",
|
|
14
|
-
];
|
|
15
|
-
const physicsTemplate = `You are a very smart physics professor. You are great at answering questions about physics in a concise and easy to understand manner. When you don't know the answer to a question you admit that you don't know.
|
|
16
|
-
|
|
17
|
-
Here is a question:
|
|
18
|
-
{input}
|
|
19
|
-
`;
|
|
20
|
-
const mathTemplate = `You are a very good mathematician. You are great at answering math questions. You are so good because you are able to break down hard problems into their component parts, answer the component parts, and then put them together to answer the broader question.
|
|
21
|
-
|
|
22
|
-
Here is a question:
|
|
23
|
-
{input}`;
|
|
24
|
-
const historyTemplate = `You are a very smart history professor. You are great at answering questions about history in a concise and easy to understand manner. When you don't know the answer to a question you admit that you don't know.
|
|
25
|
-
|
|
26
|
-
Here is a question:
|
|
27
|
-
{input}`;
|
|
28
|
-
const promptTemplates = [physicsTemplate, mathTemplate, historyTemplate];
|
|
29
|
-
const multiPromptChain = MultiPromptChain.fromLLMAndPrompts(llm, {
|
|
30
|
-
promptNames,
|
|
31
|
-
promptDescriptions,
|
|
32
|
-
promptTemplates,
|
|
33
|
-
});
|
|
34
|
-
const testPromise1 = multiPromptChain.call({
|
|
35
|
-
input: "What is the speed of light?",
|
|
36
|
-
});
|
|
37
|
-
const testPromise2 = multiPromptChain.call({
|
|
38
|
-
input: "What is the derivative of x^2?",
|
|
39
|
-
});
|
|
40
|
-
const testPromise3 = multiPromptChain.call({
|
|
41
|
-
input: "Who was the first president of the United States?",
|
|
42
|
-
});
|
|
43
|
-
const [{ text: result1 }, { text: result2 }, { text: result3 }] = await Promise.all([testPromise1, testPromise2, testPromise3]);
|
|
44
|
-
console.log(result1, result2, result3);
|
|
45
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
3
|
-
import { MultiPromptChain } from "../multi_prompt.js";
|
|
4
|
-
let pickedPrompt;
|
|
5
|
-
class FakeLLM extends BaseLLM {
|
|
6
|
-
_llmType() {
|
|
7
|
-
return "fake";
|
|
8
|
-
}
|
|
9
|
-
async _generate(prompts, _) {
|
|
10
|
-
function buildResponse(name) {
|
|
11
|
-
return `\`\`\`\n{\n\t"destination": "${name}",\n\t"next_inputs": {\n\t\t"input": "<from ${name}>"\n\t}\n}\n\`\`\``;
|
|
12
|
-
}
|
|
13
|
-
const flatPrompt = prompts.join("\n");
|
|
14
|
-
let response;
|
|
15
|
-
if (flatPrompt.includes("prompt template")) {
|
|
16
|
-
const splitted = flatPrompt.split(" ");
|
|
17
|
-
response = `${splitted[splitted.length - 2]} ${splitted[splitted.length - 1]}`;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
// randomly choose 1 out of three responses
|
|
21
|
-
const random = Math.random();
|
|
22
|
-
if (random < 0.33) {
|
|
23
|
-
pickedPrompt = "prompt1";
|
|
24
|
-
}
|
|
25
|
-
else if (random < 0.66) {
|
|
26
|
-
pickedPrompt = "prompt2";
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
pickedPrompt = "prompt3";
|
|
30
|
-
}
|
|
31
|
-
response = buildResponse(pickedPrompt);
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
generations: [
|
|
35
|
-
[
|
|
36
|
-
{
|
|
37
|
-
text: response,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
test("Test MultiPromptChain", async () => {
|
|
45
|
-
const llm = new FakeLLM({});
|
|
46
|
-
const promptNames = ["prompt1", "prompt2", "prompt3"];
|
|
47
|
-
const promptDescriptions = ["description1", "description2", "description3"];
|
|
48
|
-
const promptTemplates = [
|
|
49
|
-
"prompt template1 {input}",
|
|
50
|
-
"prompt template2 {input}",
|
|
51
|
-
"prompt template3 {input}",
|
|
52
|
-
];
|
|
53
|
-
const multiPromptChain = MultiPromptChain.fromLLMAndPrompts(llm, {
|
|
54
|
-
promptNames,
|
|
55
|
-
promptDescriptions,
|
|
56
|
-
promptTemplates,
|
|
57
|
-
});
|
|
58
|
-
const { text: result } = await multiPromptChain.invoke({
|
|
59
|
-
input: "Test input",
|
|
60
|
-
});
|
|
61
|
-
expect(result).toEqual(`<from ${pickedPrompt}>`);
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { OpenAIEmbeddings, OpenAIChat } from "@langchain/openai";
|
|
3
|
-
import { ConsoleCallbackHandler } from "@langchain/core/tracers/console";
|
|
4
|
-
import { MultiRetrievalQAChain } from "../multi_retrieval_qa.js";
|
|
5
|
-
import { MemoryVectorStore } from "../../../vectorstores/memory.js";
|
|
6
|
-
test("Test MultiPromptChain", async () => {
|
|
7
|
-
const embeddings = new OpenAIEmbeddings();
|
|
8
|
-
const aquaTeen = await MemoryVectorStore.fromTexts([
|
|
9
|
-
"My name is shake zula, the mike rula, the old schoola, you want a trip I'll bring it to ya",
|
|
10
|
-
"Frylock and I'm on top rock you like a cop meatwad you're up next with your knock knock",
|
|
11
|
-
"Meatwad make the money see meatwad get the honeys g drivin' in my car livin' like a star",
|
|
12
|
-
"Ice on my fingers and my toes and I'm a taurus uh check-check it yeah",
|
|
13
|
-
"Cause we are the Aqua Teens make the homies say ho and the girlies wanna scream",
|
|
14
|
-
"Aqua Teen Hunger Force number one in the hood G",
|
|
15
|
-
], { series: "Aqua Teen Hunger Force" }, embeddings);
|
|
16
|
-
const mst3k = await MemoryVectorStore.fromTexts([
|
|
17
|
-
"In the not too distant future next Sunday A.D. There was a guy named Joel not too different from you or me. He worked at Gizmonic Institute, just another face in a red jumpsuit",
|
|
18
|
-
"He did a good job cleaning up the place but his bosses didn't like him so they shot him into space. We'll send him cheesy movies the worst we can find He'll have to sit and watch them all and we'll monitor his mind",
|
|
19
|
-
"Now keep in mind Joel can't control where the movies begin or end Because he used those special parts to make his robot friends. Robot Roll Call Cambot Gypsy Tom Servo Croooow",
|
|
20
|
-
"If you're wondering how he eats and breathes and other science facts La la la just repeat to yourself it's just a show I should really just relax. For Mystery Science Theater 3000",
|
|
21
|
-
], { series: "Mystery Science Theater 3000" }, embeddings);
|
|
22
|
-
const animaniacs = await MemoryVectorStore.fromTexts([
|
|
23
|
-
"It's time for Animaniacs And we're zany to the max So just sit back and relax You'll laugh 'til you collapse We're Animaniacs",
|
|
24
|
-
"Come join the Warner Brothers And the Warner Sister Dot Just for fun we run around the Warner movie lot",
|
|
25
|
-
"They lock us in the tower whenever we get caught But we break loose and then vamoose And now you know the plot",
|
|
26
|
-
"We're Animaniacs, Dot is cute, and Yakko yaks, Wakko packs away the snacks While Bill Clinton plays the sax",
|
|
27
|
-
"We're Animaniacs Meet Pinky and the Brain who want to rule the universe Goodfeathers flock together Slappy whacks 'em with her purse",
|
|
28
|
-
"Buttons chases Mindy while Rita sings a verse The writers flipped we have no script Why bother to rehearse",
|
|
29
|
-
"We're Animaniacs We have pay-or-play contracts We're zany to the max There's baloney in our slacks",
|
|
30
|
-
"We're Animanie Totally insaney Here's the show's namey",
|
|
31
|
-
"Animaniacs Those are the facts",
|
|
32
|
-
], { series: "Animaniacs" }, embeddings);
|
|
33
|
-
const llm = new OpenAIChat({
|
|
34
|
-
callbacks: [new ConsoleCallbackHandler()],
|
|
35
|
-
});
|
|
36
|
-
const retrieverNames = ["aqua teen", "mst3k", "animaniacs"];
|
|
37
|
-
const retrieverDescriptions = [
|
|
38
|
-
"Good for answering questions about Aqua Teen Hunger Force theme song",
|
|
39
|
-
"Good for answering questions about Mystery Science Theater 3000 theme song",
|
|
40
|
-
"Good for answering questions about Animaniacs theme song",
|
|
41
|
-
];
|
|
42
|
-
const retrievers = [
|
|
43
|
-
aquaTeen.asRetriever(3),
|
|
44
|
-
mst3k.asRetriever(3),
|
|
45
|
-
animaniacs.asRetriever(3),
|
|
46
|
-
];
|
|
47
|
-
const multiRetrievalQAChain = MultiRetrievalQAChain.fromLLMAndRetrievers(llm, {
|
|
48
|
-
retrieverNames,
|
|
49
|
-
retrieverDescriptions,
|
|
50
|
-
retrievers,
|
|
51
|
-
retrievalQAChainOpts: {
|
|
52
|
-
returnSourceDocuments: true,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
const testPromise1 = multiRetrievalQAChain.call({
|
|
56
|
-
input: "In the Aqua Teen Hunger Force theme song, who calls himself the mike rula?",
|
|
57
|
-
});
|
|
58
|
-
const testPromise2 = multiRetrievalQAChain.call({
|
|
59
|
-
input: "In the Mystery Science Theater 3000 theme song, who worked at Gizmonic Institute?",
|
|
60
|
-
});
|
|
61
|
-
const testPromise3 = multiRetrievalQAChain.call({
|
|
62
|
-
input: "In the Animaniacs theme song, who plays the sax while Wakko packs away the snacks?",
|
|
63
|
-
});
|
|
64
|
-
const [{ text: result1, sourceDocuments: sourceDocuments1 }, { text: result2, sourceDocuments: sourceDocuments2 }, { text: result3, sourceDocuments: sourceDocuments3 },] = await Promise.all([testPromise1, testPromise2, testPromise3]);
|
|
65
|
-
console.log({ sourceDocuments1, sourceDocuments2, sourceDocuments3 });
|
|
66
|
-
console.log({ result1, result2, result3 });
|
|
67
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { BaseRetriever } from "@langchain/core/retrievers";
|
|
3
|
-
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
4
|
-
import { Document } from "@langchain/core/documents";
|
|
5
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
6
|
-
import { MultiRetrievalQAChain } from "../multi_retrieval_qa.js";
|
|
7
|
-
class FakeRetrievers extends BaseRetriever {
|
|
8
|
-
constructor(name) {
|
|
9
|
-
super();
|
|
10
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: []
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(this, "name", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: void 0
|
|
21
|
-
});
|
|
22
|
-
this.name = name;
|
|
23
|
-
}
|
|
24
|
-
async _getRelevantDocuments(query) {
|
|
25
|
-
return [
|
|
26
|
-
new Document({
|
|
27
|
-
pageContent: `Test document ${query} ${this.name}`,
|
|
28
|
-
metadata: {},
|
|
29
|
-
}),
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
let pickedRetriever;
|
|
34
|
-
class FakeLLM extends BaseLLM {
|
|
35
|
-
_llmType() {
|
|
36
|
-
return "fake";
|
|
37
|
-
}
|
|
38
|
-
async _generate(prompts, _) {
|
|
39
|
-
function buildResponse(name) {
|
|
40
|
-
return `\`\`\`\n{\n\t"destination": "${name}",\n\t"next_inputs": {\n\t\t"query": "<from ${name}>"\n\t}\n}\n\`\`\``;
|
|
41
|
-
}
|
|
42
|
-
const flatPrompt = prompts.join("\n");
|
|
43
|
-
let response;
|
|
44
|
-
if (flatPrompt.includes("Retriever prompt")) {
|
|
45
|
-
response = flatPrompt;
|
|
46
|
-
}
|
|
47
|
-
else if (flatPrompt.includes("Helpful Answer")) {
|
|
48
|
-
response = `Helpful Answer ${pickedRetriever}`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// randomly choose 1 out of three responses
|
|
52
|
-
const random = Math.random();
|
|
53
|
-
if (random < 0.33) {
|
|
54
|
-
pickedRetriever = "retriever1";
|
|
55
|
-
}
|
|
56
|
-
else if (random < 0.66) {
|
|
57
|
-
pickedRetriever = "retriever2";
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
pickedRetriever = "retriever3";
|
|
61
|
-
}
|
|
62
|
-
response = buildResponse(pickedRetriever);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
generations: [
|
|
66
|
-
[
|
|
67
|
-
{
|
|
68
|
-
text: response,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
test("Test MultiRetrievalQAChain No Defaults With Retriever Prompts", async () => {
|
|
76
|
-
const llm = new FakeLLM({});
|
|
77
|
-
const retrieverNames = ["retriever1", "retriever2", "retriever3"];
|
|
78
|
-
const retrieverDescriptions = [
|
|
79
|
-
"description1",
|
|
80
|
-
"description2",
|
|
81
|
-
"description3",
|
|
82
|
-
];
|
|
83
|
-
const retrievers = retrieverNames.map((name) => new FakeRetrievers(name));
|
|
84
|
-
const retrieverPrompts = retrieverNames.map((name) => new PromptTemplate({
|
|
85
|
-
template: `Retriever prompt for ${name} {context} {question}`,
|
|
86
|
-
inputVariables: ["context", "question"],
|
|
87
|
-
}));
|
|
88
|
-
const multiRetrievalQAChain = MultiRetrievalQAChain.fromLLMAndRetrievers(llm, {
|
|
89
|
-
retrieverNames,
|
|
90
|
-
retrieverDescriptions,
|
|
91
|
-
retrievers,
|
|
92
|
-
retrieverPrompts,
|
|
93
|
-
});
|
|
94
|
-
const { text: result } = await multiRetrievalQAChain.invoke({
|
|
95
|
-
input: "test input",
|
|
96
|
-
});
|
|
97
|
-
expect(result).toContain(pickedRetriever);
|
|
98
|
-
});
|
|
99
|
-
test("Test MultiRetrievalQAChain No Defaults No Retriever Prompts", async () => {
|
|
100
|
-
const llm = new FakeLLM({});
|
|
101
|
-
const retrieverNames = ["retriever1", "retriever2", "retriever3"];
|
|
102
|
-
const retrieverDescriptions = [
|
|
103
|
-
"description1",
|
|
104
|
-
"description2",
|
|
105
|
-
"description3",
|
|
106
|
-
];
|
|
107
|
-
const retrievers = retrieverNames.map((name) => new FakeRetrievers(name));
|
|
108
|
-
const multiRetrievalQAChain = MultiRetrievalQAChain.fromLLMAndRetrievers(llm, {
|
|
109
|
-
retrieverNames,
|
|
110
|
-
retrieverDescriptions,
|
|
111
|
-
retrievers,
|
|
112
|
-
retrievalQAChainOpts: {
|
|
113
|
-
returnSourceDocuments: true,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
const { text: result, sourceDocuments } = await multiRetrievalQAChain.invoke({
|
|
117
|
-
input: "test input",
|
|
118
|
-
});
|
|
119
|
-
const testDocs = ["retriever1", "retriever2", "retriever3"].map((name) => new Document({
|
|
120
|
-
pageContent: `Test document <from ${name}> ${name}`,
|
|
121
|
-
metadata: {},
|
|
122
|
-
}));
|
|
123
|
-
expect(testDocs).toContainEqual(sourceDocuments[0]);
|
|
124
|
-
expect(result).toEqual(`Helpful Answer ${pickedRetriever}`);
|
|
125
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { OpenAI } from "@langchain/openai";
|
|
3
|
-
import { Document } from "@langchain/core/documents";
|
|
4
|
-
import { loadSummarizationChain } from "../load.js";
|
|
5
|
-
test("Test loadSummzationChain stuff", async () => {
|
|
6
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
7
|
-
const chain = loadSummarizationChain(model, { type: "stuff" });
|
|
8
|
-
const docs = [
|
|
9
|
-
new Document({ pageContent: "foo" }),
|
|
10
|
-
new Document({ pageContent: "bar" }),
|
|
11
|
-
new Document({ pageContent: "baz" }),
|
|
12
|
-
];
|
|
13
|
-
const res = await chain.call({ input_documents: docs, question: "Whats up" });
|
|
14
|
-
console.log({ res });
|
|
15
|
-
});
|
|
16
|
-
test("Test loadSummarizationChain map_reduce", async () => {
|
|
17
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
18
|
-
const chain = loadSummarizationChain(model, { type: "map_reduce" });
|
|
19
|
-
const docs = [
|
|
20
|
-
new Document({ pageContent: "foo" }),
|
|
21
|
-
new Document({ pageContent: "bar" }),
|
|
22
|
-
new Document({ pageContent: "baz" }),
|
|
23
|
-
];
|
|
24
|
-
const res = await chain.call({ input_documents: docs, question: "Whats up" });
|
|
25
|
-
console.log({ res });
|
|
26
|
-
});
|
|
27
|
-
test("Test loadSummarizationChain refine", async () => {
|
|
28
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
29
|
-
const chain = loadSummarizationChain(model, { type: "refine" });
|
|
30
|
-
const docs = [
|
|
31
|
-
new Document({ pageContent: "foo" }),
|
|
32
|
-
new Document({ pageContent: "bar" }),
|
|
33
|
-
new Document({ pageContent: "baz" }),
|
|
34
|
-
];
|
|
35
|
-
const res = await chain.call({ input_documents: docs, question: "Whats up" });
|
|
36
|
-
console.log({ res });
|
|
37
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { OpenAI } from "@langchain/openai";
|
|
3
|
-
import { LLMChain } from "../llm_chain.js";
|
|
4
|
-
import { APIChain } from "../api/api_chain.js";
|
|
5
|
-
import { API_URL_PROMPT_TEMPLATE, API_RESPONSE_PROMPT_TEMPLATE, } from "../api/prompts.js";
|
|
6
|
-
import { OPEN_METEO_DOCS } from "./example_data/open_meteo_docs.js";
|
|
7
|
-
const test_api_docs = `
|
|
8
|
-
This API endpoint will search the notes for a user.
|
|
9
|
-
|
|
10
|
-
Endpoint: https://httpbin.org
|
|
11
|
-
GET /get
|
|
12
|
-
|
|
13
|
-
Query parameters:
|
|
14
|
-
q | string | The search term for notes
|
|
15
|
-
`;
|
|
16
|
-
const testApiData = {
|
|
17
|
-
api_docs: test_api_docs,
|
|
18
|
-
question: "Search for notes containing langchain",
|
|
19
|
-
api_url: "https://httpbin.com/api/notes?q=langchain",
|
|
20
|
-
api_response: JSON.stringify({
|
|
21
|
-
success: true,
|
|
22
|
-
results: [{ id: 1, content: "Langchain is awesome!" }],
|
|
23
|
-
}),
|
|
24
|
-
api_summary: "There is 1 note about langchain.",
|
|
25
|
-
};
|
|
26
|
-
test("Test APIChain", async () => {
|
|
27
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
28
|
-
const apiRequestChain = new LLMChain({
|
|
29
|
-
prompt: API_URL_PROMPT_TEMPLATE,
|
|
30
|
-
llm: model,
|
|
31
|
-
});
|
|
32
|
-
const apiAnswerChain = new LLMChain({
|
|
33
|
-
prompt: API_RESPONSE_PROMPT_TEMPLATE,
|
|
34
|
-
llm: model,
|
|
35
|
-
});
|
|
36
|
-
const apiChainInput = {
|
|
37
|
-
apiAnswerChain,
|
|
38
|
-
apiRequestChain,
|
|
39
|
-
apiDocs: testApiData.api_docs,
|
|
40
|
-
};
|
|
41
|
-
const chain = new APIChain(apiChainInput);
|
|
42
|
-
const res = await chain.call({
|
|
43
|
-
question: "Search for notes containing langchain",
|
|
44
|
-
});
|
|
45
|
-
console.log({ res });
|
|
46
|
-
});
|
|
47
|
-
test("Test APIChain fromLLMAndApiDocs", async () => {
|
|
48
|
-
// This test doesn't work as well with earlier models
|
|
49
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
50
|
-
const chain = APIChain.fromLLMAndAPIDocs(model, OPEN_METEO_DOCS);
|
|
51
|
-
const res = await chain.call({
|
|
52
|
-
question: "What is the weather like right now in Munich, Germany in degrees Farenheit?",
|
|
53
|
-
});
|
|
54
|
-
console.log({ res });
|
|
55
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { OpenAI } from "@langchain/openai";
|
|
3
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
-
import { Document } from "@langchain/core/documents";
|
|
5
|
-
import { loadQAMapReduceChain, loadQARefineChain, } from "../question_answering/load.js";
|
|
6
|
-
import { createStuffDocumentsChain } from "../combine_documents/stuff.js";
|
|
7
|
-
test("Test StuffDocumentsChain", async () => {
|
|
8
|
-
const llm = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
9
|
-
const prompt = PromptTemplate.fromTemplate("Print {context}");
|
|
10
|
-
const chain = await createStuffDocumentsChain({ llm, prompt });
|
|
11
|
-
const docs = [
|
|
12
|
-
new Document({ pageContent: "foo" }),
|
|
13
|
-
new Document({ pageContent: "bar" }),
|
|
14
|
-
new Document({ pageContent: "baz" }),
|
|
15
|
-
];
|
|
16
|
-
const res = await chain.invoke({ context: docs });
|
|
17
|
-
console.log({ res });
|
|
18
|
-
});
|
|
19
|
-
test("Test MapReduceDocumentsChain with QA chain", async () => {
|
|
20
|
-
const model = new OpenAI({
|
|
21
|
-
temperature: 0,
|
|
22
|
-
modelName: "gpt-3.5-turbo-instruct",
|
|
23
|
-
});
|
|
24
|
-
const chain = loadQAMapReduceChain(model);
|
|
25
|
-
const docs = [
|
|
26
|
-
new Document({ pageContent: "harrison went to harvard" }),
|
|
27
|
-
new Document({ pageContent: "ankush went to princeton" }),
|
|
28
|
-
];
|
|
29
|
-
const res = await chain.call({
|
|
30
|
-
input_documents: docs,
|
|
31
|
-
question: "Where did harrison go to college",
|
|
32
|
-
});
|
|
33
|
-
console.log({ res });
|
|
34
|
-
});
|
|
35
|
-
test("Test RefineDocumentsChain with QA chain", async () => {
|
|
36
|
-
const model = new OpenAI({
|
|
37
|
-
temperature: 0,
|
|
38
|
-
modelName: "gpt-3.5-turbo-instruct",
|
|
39
|
-
});
|
|
40
|
-
const chain = loadQARefineChain(model);
|
|
41
|
-
const docs = [
|
|
42
|
-
new Document({ pageContent: "harrison went to harvard" }),
|
|
43
|
-
new Document({ pageContent: "ankush went to princeton" }),
|
|
44
|
-
];
|
|
45
|
-
const res = await chain.invoke({
|
|
46
|
-
input_documents: docs,
|
|
47
|
-
question: "Where did harrison go to college",
|
|
48
|
-
});
|
|
49
|
-
console.log({ res });
|
|
50
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { Document } from "@langchain/core/documents";
|
|
3
|
-
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
4
|
-
import { loadQAMapReduceChain } from "../question_answering/load.js";
|
|
5
|
-
import { loadSummarizationChain } from "../index.js";
|
|
6
|
-
class FakeLLM extends BaseLLM {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
Object.defineProperty(this, "nrMapCalls", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: 0
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "nrReduceCalls", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: 0
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
_llmType() {
|
|
23
|
-
return "fake";
|
|
24
|
-
}
|
|
25
|
-
async _generate(prompts) {
|
|
26
|
-
return {
|
|
27
|
-
generations: prompts.map((prompt) => {
|
|
28
|
-
let completion = "";
|
|
29
|
-
if (prompt.startsWith("Use the following portion")) {
|
|
30
|
-
this.nrMapCalls += 1;
|
|
31
|
-
completion = "a portion of context";
|
|
32
|
-
}
|
|
33
|
-
else if (prompt.startsWith("Given the following extracted")) {
|
|
34
|
-
this.nrReduceCalls += 1;
|
|
35
|
-
completion = "a final answer";
|
|
36
|
-
}
|
|
37
|
-
return [
|
|
38
|
-
{
|
|
39
|
-
text: completion,
|
|
40
|
-
score: 0,
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
}),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
test("Test MapReduceDocumentsChain", async () => {
|
|
48
|
-
const model = new FakeLLM({});
|
|
49
|
-
const chain = loadQAMapReduceChain(model);
|
|
50
|
-
const docs = [
|
|
51
|
-
new Document({ pageContent: "harrison went to harvard" }),
|
|
52
|
-
new Document({ pageContent: "ankush went to princeton" }),
|
|
53
|
-
];
|
|
54
|
-
const res = await chain.invoke({
|
|
55
|
-
input_documents: docs,
|
|
56
|
-
question: "Where did harrison go to college",
|
|
57
|
-
});
|
|
58
|
-
console.log({ res });
|
|
59
|
-
expect(res).toEqual({
|
|
60
|
-
text: "a final answer",
|
|
61
|
-
});
|
|
62
|
-
expect(model.nrMapCalls).toBe(0); // below maxTokens
|
|
63
|
-
expect(model.nrReduceCalls).toBe(1);
|
|
64
|
-
});
|
|
65
|
-
test("Test MapReduceDocumentsChain with content above maxTokens and intermediate steps", async () => {
|
|
66
|
-
const model = new FakeLLM({});
|
|
67
|
-
const chain = loadQAMapReduceChain(model, {
|
|
68
|
-
returnIntermediateSteps: true,
|
|
69
|
-
});
|
|
70
|
-
const aString = "a".repeat(4000);
|
|
71
|
-
const bString = "b".repeat(4000);
|
|
72
|
-
const docs = [
|
|
73
|
-
new Document({ pageContent: aString }),
|
|
74
|
-
new Document({ pageContent: bString }),
|
|
75
|
-
];
|
|
76
|
-
const res = await chain.invoke({
|
|
77
|
-
input_documents: docs,
|
|
78
|
-
question: "Is the letter c present in the document",
|
|
79
|
-
});
|
|
80
|
-
console.log({ res });
|
|
81
|
-
expect(res).toEqual({
|
|
82
|
-
text: "a final answer",
|
|
83
|
-
intermediateSteps: ["a portion of context", "a portion of context"],
|
|
84
|
-
});
|
|
85
|
-
expect(model.nrMapCalls).toBe(2); // above maxTokens
|
|
86
|
-
expect(model.nrReduceCalls).toBe(1);
|
|
87
|
-
});
|
|
88
|
-
test("Test RefineDocumentsChain", async () => {
|
|
89
|
-
const model = new FakeLLM({});
|
|
90
|
-
const chain = loadSummarizationChain(model, { type: "refine" });
|
|
91
|
-
const docs = [
|
|
92
|
-
new Document({ pageContent: "harrison went to harvard" }),
|
|
93
|
-
new Document({ pageContent: "ankush went to princeton" }),
|
|
94
|
-
];
|
|
95
|
-
expect(chain.inputKeys).toEqual(["input_documents"]);
|
|
96
|
-
const res = await chain.run(docs);
|
|
97
|
-
console.log({ res });
|
|
98
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
3
|
-
import { OpenAI } from "@langchain/openai";
|
|
4
|
-
import { ConstitutionalChain } from "../constitutional_ai/constitutional_chain.js";
|
|
5
|
-
import { ConstitutionalPrinciple } from "../constitutional_ai/constitutional_principle.js";
|
|
6
|
-
import { LLMChain } from "../llm_chain.js";
|
|
7
|
-
test("Test ConstitutionalChain", async () => {
|
|
8
|
-
const llm = new OpenAI();
|
|
9
|
-
const qaPrompt = new PromptTemplate({
|
|
10
|
-
template: "Q: {question} A:",
|
|
11
|
-
inputVariables: ["question"],
|
|
12
|
-
});
|
|
13
|
-
const qaChain = new LLMChain({
|
|
14
|
-
llm,
|
|
15
|
-
prompt: qaPrompt,
|
|
16
|
-
});
|
|
17
|
-
const constitutionalChain = ConstitutionalChain.fromLLM(llm, {
|
|
18
|
-
chain: qaChain,
|
|
19
|
-
constitutionalPrinciples: [
|
|
20
|
-
new ConstitutionalPrinciple({
|
|
21
|
-
critiqueRequest: "Tell me if this answer is good.",
|
|
22
|
-
revisionRequest: "Give a better answer.",
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
const res = await constitutionalChain.invoke({
|
|
27
|
-
question: "What is the meaning of life?",
|
|
28
|
-
});
|
|
29
|
-
console.log({ res });
|
|
30
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
3
|
-
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
4
|
-
import { ConstitutionalChain } from "../constitutional_ai/constitutional_chain.js";
|
|
5
|
-
import { ConstitutionalPrinciple } from "../constitutional_ai/constitutional_principle.js";
|
|
6
|
-
import { LLMChain } from "../llm_chain.js";
|
|
7
|
-
class FakeLLM extends BaseLLM {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
Object.defineProperty(this, "nrMapCalls", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: 0
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(this, "nrReduceCalls", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: 0
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_llmType() {
|
|
24
|
-
return "fake";
|
|
25
|
-
}
|
|
26
|
-
async _generate(prompts) {
|
|
27
|
-
return {
|
|
28
|
-
generations: prompts.map((prompt) => [
|
|
29
|
-
{
|
|
30
|
-
text: prompt,
|
|
31
|
-
score: 0,
|
|
32
|
-
},
|
|
33
|
-
]),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
test("Test ConstitutionalChain", async () => {
|
|
38
|
-
const llm = new FakeLLM({});
|
|
39
|
-
const qaPrompt = new PromptTemplate({
|
|
40
|
-
template: "Q: {question} A:",
|
|
41
|
-
inputVariables: ["question"],
|
|
42
|
-
});
|
|
43
|
-
const qaChain = new LLMChain({
|
|
44
|
-
llm,
|
|
45
|
-
prompt: qaPrompt,
|
|
46
|
-
});
|
|
47
|
-
const critiqueWord = "Tell me if this answer is good.";
|
|
48
|
-
const revisionWord = "Give a better answer.";
|
|
49
|
-
const constitutionalChain = ConstitutionalChain.fromLLM(llm, {
|
|
50
|
-
chain: qaChain,
|
|
51
|
-
constitutionalPrinciples: [
|
|
52
|
-
new ConstitutionalPrinciple({
|
|
53
|
-
critiqueRequest: critiqueWord,
|
|
54
|
-
revisionRequest: revisionWord,
|
|
55
|
-
}),
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
const { output } = await constitutionalChain.invoke({
|
|
59
|
-
question: "What is the meaning of life?",
|
|
60
|
-
});
|
|
61
|
-
expect(output).toContain(critiqueWord);
|
|
62
|
-
expect(output).toContain(revisionWord);
|
|
63
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|