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,150 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@jest/globals";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { OpenAI, ChatOpenAI } from "@langchain/openai";
|
|
4
|
-
import { ChatPromptTemplate, PromptTemplate, SystemMessagePromptTemplate, } from "@langchain/core/prompts";
|
|
5
|
-
import { LLMChain } from "../../chains/index.js";
|
|
6
|
-
import { StructuredOutputParser } from "../structured.js";
|
|
7
|
-
test("StructuredOutputParser deals special chars in prompt with llm model", async () => {
|
|
8
|
-
const model = new OpenAI({
|
|
9
|
-
temperature: 0,
|
|
10
|
-
});
|
|
11
|
-
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
12
|
-
question1: "a very on-topic question",
|
|
13
|
-
question2: "a super weird question",
|
|
14
|
-
question3: "an on-topic, but slightly creative",
|
|
15
|
-
});
|
|
16
|
-
const prompt = new PromptTemplate({
|
|
17
|
-
template: "context:\n{context}\n---{format_instructions}",
|
|
18
|
-
inputVariables: ["context"],
|
|
19
|
-
partialVariables: {
|
|
20
|
-
format_instructions: parser.getFormatInstructions(),
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
const chain = new LLMChain({
|
|
24
|
-
llm: model,
|
|
25
|
-
prompt,
|
|
26
|
-
outputParser: parser,
|
|
27
|
-
outputKey: "questions",
|
|
28
|
-
});
|
|
29
|
-
const result = await chain.call({
|
|
30
|
-
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
31
|
-
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
32
|
-
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
33
|
-
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
34
|
-
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
35
|
-
});
|
|
36
|
-
console.log("response", result);
|
|
37
|
-
expect(result.questions).toHaveProperty("question1");
|
|
38
|
-
expect(result.questions).toHaveProperty("question2");
|
|
39
|
-
expect(result.questions).toHaveProperty("question3");
|
|
40
|
-
});
|
|
41
|
-
test("StructuredOutputParser deals special chars in prompt with chat model", async () => {
|
|
42
|
-
const model = new ChatOpenAI({
|
|
43
|
-
temperature: 0,
|
|
44
|
-
});
|
|
45
|
-
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
46
|
-
question1: "a very on-topic question",
|
|
47
|
-
question2: "a super weird question",
|
|
48
|
-
question3: "an on-topic, but slightly creative",
|
|
49
|
-
});
|
|
50
|
-
const prompt = new ChatPromptTemplate({
|
|
51
|
-
promptMessages: [
|
|
52
|
-
SystemMessagePromptTemplate.fromTemplate("context:\n{context}\n---"),
|
|
53
|
-
SystemMessagePromptTemplate.fromTemplate(`{format_instructions}`),
|
|
54
|
-
],
|
|
55
|
-
inputVariables: ["context"],
|
|
56
|
-
partialVariables: {
|
|
57
|
-
format_instructions: parser.getFormatInstructions(),
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
const chain = new LLMChain({
|
|
61
|
-
llm: model,
|
|
62
|
-
prompt,
|
|
63
|
-
outputParser: parser,
|
|
64
|
-
outputKey: "questions",
|
|
65
|
-
});
|
|
66
|
-
const result = await chain.call({
|
|
67
|
-
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
68
|
-
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
69
|
-
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
70
|
-
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
71
|
-
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
72
|
-
});
|
|
73
|
-
console.log("response", result);
|
|
74
|
-
expect(result.questions).toHaveProperty("question1");
|
|
75
|
-
expect(result.questions).toHaveProperty("question2");
|
|
76
|
-
expect(result.questions).toHaveProperty("question3");
|
|
77
|
-
});
|
|
78
|
-
test("StructuredOutputParser deals special chars in prompt with chat model 2", async () => {
|
|
79
|
-
const model = new ChatOpenAI({
|
|
80
|
-
temperature: 0,
|
|
81
|
-
});
|
|
82
|
-
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
83
|
-
question1: "a very on-topic question",
|
|
84
|
-
question2: "a super weird question",
|
|
85
|
-
question3: "an on-topic, but slightly creative",
|
|
86
|
-
});
|
|
87
|
-
const prompt = new ChatPromptTemplate({
|
|
88
|
-
promptMessages: [
|
|
89
|
-
SystemMessagePromptTemplate.fromTemplate("context:\n{context}\n---"),
|
|
90
|
-
SystemMessagePromptTemplate.fromTemplate(`{format_instructions}`),
|
|
91
|
-
],
|
|
92
|
-
inputVariables: ["context"],
|
|
93
|
-
partialVariables: {
|
|
94
|
-
format_instructions: parser.getFormatInstructions(),
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
const chain = new LLMChain({
|
|
98
|
-
llm: model,
|
|
99
|
-
prompt,
|
|
100
|
-
outputKey: "questions",
|
|
101
|
-
});
|
|
102
|
-
const result = await chain.call({
|
|
103
|
-
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
104
|
-
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
105
|
-
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
106
|
-
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
107
|
-
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
108
|
-
});
|
|
109
|
-
console.log("response", result);
|
|
110
|
-
const parsed = await parser.parse(result.questions);
|
|
111
|
-
expect(parsed).toHaveProperty("question1");
|
|
112
|
-
expect(parsed).toHaveProperty("question2");
|
|
113
|
-
expect(parsed).toHaveProperty("question3");
|
|
114
|
-
});
|
|
115
|
-
test("StructuredOutputParser handles a longer and more complex schema", async () => {
|
|
116
|
-
const parser = StructuredOutputParser.fromZodSchema(z.object({
|
|
117
|
-
name: z.string().describe("Human name"),
|
|
118
|
-
surname: z.string().describe("Human surname"),
|
|
119
|
-
age: z.number().describe("Human age"),
|
|
120
|
-
appearance: z.string().describe("Human appearance description"),
|
|
121
|
-
shortBio: z.string().describe("Short bio secription"),
|
|
122
|
-
university: z.string().optional().describe("University name if attended"),
|
|
123
|
-
gender: z.string().describe("Gender of the human"),
|
|
124
|
-
interests: z
|
|
125
|
-
.array(z.string())
|
|
126
|
-
.describe("json array of strings human interests"),
|
|
127
|
-
}));
|
|
128
|
-
const formatInstructions = parser.getFormatInstructions();
|
|
129
|
-
const prompt = new PromptTemplate({
|
|
130
|
-
template: "Generate details of a hypothetical person.\n{format_instructions}\nPerson description: {inputText}",
|
|
131
|
-
inputVariables: ["inputText"],
|
|
132
|
-
partialVariables: { format_instructions: formatInstructions },
|
|
133
|
-
});
|
|
134
|
-
const model = new OpenAI({ temperature: 0.5, modelName: "gpt-3.5-turbo" });
|
|
135
|
-
const input = await prompt.format({
|
|
136
|
-
inputText: "A man, living in Poland.",
|
|
137
|
-
});
|
|
138
|
-
const response = await model.invoke(input);
|
|
139
|
-
console.log("response", response);
|
|
140
|
-
const parsed = await parser.parse(response);
|
|
141
|
-
expect(parsed).toHaveProperty("name");
|
|
142
|
-
expect(parsed).toHaveProperty("surname");
|
|
143
|
-
expect(parsed).toHaveProperty("age");
|
|
144
|
-
expect(parsed).toHaveProperty("appearance");
|
|
145
|
-
expect(parsed).toHaveProperty("shortBio");
|
|
146
|
-
expect(parsed).toHaveProperty("age");
|
|
147
|
-
expect(parsed).toHaveProperty("gender");
|
|
148
|
-
expect(parsed).toHaveProperty("interests");
|
|
149
|
-
expect(parsed.interests.length).toBeGreaterThan(0);
|
|
150
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@jest/globals";
|
|
2
|
-
import { LengthBasedExampleSelector, SemanticSimilarityExampleSelector, } from "@langchain/core/example_selectors";
|
|
3
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
-
import { FakeEmbeddings } from "@langchain/core/utils/testing";
|
|
5
|
-
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
6
|
-
test("Test using LengthBasedExampleSelector", async () => {
|
|
7
|
-
const prompt = new PromptTemplate({
|
|
8
|
-
template: "{foo} {bar}",
|
|
9
|
-
inputVariables: ["foo"],
|
|
10
|
-
partialVariables: { bar: "baz" },
|
|
11
|
-
});
|
|
12
|
-
const selector = await LengthBasedExampleSelector.fromExamples([{ foo: "one one one" }], {
|
|
13
|
-
examplePrompt: prompt,
|
|
14
|
-
maxLength: 10,
|
|
15
|
-
});
|
|
16
|
-
await selector.addExample({ foo: "one two three" });
|
|
17
|
-
await selector.addExample({ foo: "four five six" });
|
|
18
|
-
await selector.addExample({ foo: "seven eight nine" });
|
|
19
|
-
await selector.addExample({ foo: "ten eleven twelve" });
|
|
20
|
-
const chosen = await selector.selectExamples({ foo: "hello", bar: "world" });
|
|
21
|
-
expect(chosen).toStrictEqual([
|
|
22
|
-
{ foo: "one one one" },
|
|
23
|
-
{ foo: "one two three" },
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
26
|
-
test("Test using SemanticSimilarityExampleSelector", async () => {
|
|
27
|
-
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
28
|
-
);
|
|
29
|
-
const selector = new SemanticSimilarityExampleSelector({
|
|
30
|
-
vectorStore,
|
|
31
|
-
});
|
|
32
|
-
const chosen = await selector.selectExamples({ id: 1 });
|
|
33
|
-
expect(chosen).toEqual([{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }]);
|
|
34
|
-
});
|
|
35
|
-
test("Test using SemanticSimilarityExampleSelector with metadata filtering", async () => {
|
|
36
|
-
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
37
|
-
);
|
|
38
|
-
const selector = new SemanticSimilarityExampleSelector({
|
|
39
|
-
vectorStore,
|
|
40
|
-
filter: (doc) => doc.metadata.id === 2,
|
|
41
|
-
});
|
|
42
|
-
const chosen = await selector.selectExamples({ id: 1 });
|
|
43
|
-
expect(chosen).toEqual([{ id: 2 }]);
|
|
44
|
-
});
|
|
45
|
-
test("Test using SemanticSimilarityExampleSelector with a passed in retriever", async () => {
|
|
46
|
-
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
47
|
-
);
|
|
48
|
-
const selector = new SemanticSimilarityExampleSelector({
|
|
49
|
-
vectorStoreRetriever: vectorStore.asRetriever({ k: 5 }),
|
|
50
|
-
});
|
|
51
|
-
const chosen = await selector.selectExamples({ id: 1 });
|
|
52
|
-
expect(chosen).toEqual([
|
|
53
|
-
{ id: 2 },
|
|
54
|
-
{ id: 1 },
|
|
55
|
-
{ id: 3 },
|
|
56
|
-
{ id: 4 },
|
|
57
|
-
{ id: 5 },
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { Document } from "@langchain/core/documents";
|
|
3
|
-
import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";
|
|
4
|
-
import { SelfQueryRetriever } from "../index.js";
|
|
5
|
-
import { FunctionalTranslator } from "../functional.js";
|
|
6
|
-
import { MemoryVectorStore } from "../../../vectorstores/memory.js";
|
|
7
|
-
test("Memory Vector Store Self Query Retriever Test", async () => {
|
|
8
|
-
const docs = [
|
|
9
|
-
new Document({
|
|
10
|
-
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
11
|
-
metadata: { year: 1993, rating: 7.7, genre: "science fiction" },
|
|
12
|
-
}),
|
|
13
|
-
new Document({
|
|
14
|
-
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
15
|
-
metadata: { year: 2010, director: "Christopher Nolan", rating: 8.2 },
|
|
16
|
-
}),
|
|
17
|
-
new Document({
|
|
18
|
-
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
19
|
-
metadata: { year: 2006, director: "Satoshi Kon", rating: 8.6 },
|
|
20
|
-
}),
|
|
21
|
-
new Document({
|
|
22
|
-
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
23
|
-
metadata: { year: 2019, director: "Greta Gerwig", rating: 8.3 },
|
|
24
|
-
}),
|
|
25
|
-
new Document({
|
|
26
|
-
pageContent: "Toys come alive and have a blast doing so",
|
|
27
|
-
metadata: { year: 1995, genre: "animated" },
|
|
28
|
-
}),
|
|
29
|
-
new Document({
|
|
30
|
-
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
31
|
-
metadata: {
|
|
32
|
-
year: 1979,
|
|
33
|
-
director: "Andrei Tarkovsky",
|
|
34
|
-
genre: "science fiction",
|
|
35
|
-
rating: 9.9,
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
];
|
|
39
|
-
const attributeInfo = [
|
|
40
|
-
{
|
|
41
|
-
name: "genre",
|
|
42
|
-
description: "The genre of the movie",
|
|
43
|
-
type: "string or array of strings",
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "year",
|
|
47
|
-
description: "The year the movie was released",
|
|
48
|
-
type: "number",
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "director",
|
|
52
|
-
description: "The director of the movie",
|
|
53
|
-
type: "string",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "rating",
|
|
57
|
-
description: "The rating of the movie (1-10)",
|
|
58
|
-
type: "number",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "length",
|
|
62
|
-
description: "The length of the movie in minutes",
|
|
63
|
-
type: "number",
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
const embeddings = new OpenAIEmbeddings();
|
|
67
|
-
const llm = new OpenAI({
|
|
68
|
-
modelName: "gpt-3.5-turbo",
|
|
69
|
-
});
|
|
70
|
-
const documentContents = "Brief summary of a movie";
|
|
71
|
-
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
72
|
-
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
73
|
-
llm,
|
|
74
|
-
vectorStore,
|
|
75
|
-
documentContents,
|
|
76
|
-
attributeInfo,
|
|
77
|
-
structuredQueryTranslator: new FunctionalTranslator(),
|
|
78
|
-
});
|
|
79
|
-
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
80
|
-
console.log(query1);
|
|
81
|
-
expect(query1.length).toEqual(0);
|
|
82
|
-
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
83
|
-
console.log(query2);
|
|
84
|
-
expect(query2.length).toEqual(2);
|
|
85
|
-
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
86
|
-
console.log(query3);
|
|
87
|
-
expect(query3.length).toEqual(1);
|
|
88
|
-
});
|
|
89
|
-
test("Memory Vector Store Self Query Retriever Test With Default Filter Or Merge Operator", async () => {
|
|
90
|
-
const docs = [
|
|
91
|
-
new Document({
|
|
92
|
-
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
93
|
-
metadata: {
|
|
94
|
-
year: 1993,
|
|
95
|
-
rating: 7.7,
|
|
96
|
-
genre: "science fiction",
|
|
97
|
-
type: "movie",
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
new Document({
|
|
101
|
-
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
102
|
-
metadata: {
|
|
103
|
-
year: 2010,
|
|
104
|
-
director: "Christopher Nolan",
|
|
105
|
-
rating: 8.2,
|
|
106
|
-
type: "movie",
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
new Document({
|
|
110
|
-
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
111
|
-
metadata: {
|
|
112
|
-
year: 2006,
|
|
113
|
-
director: "Satoshi Kon",
|
|
114
|
-
rating: 8.6,
|
|
115
|
-
type: "movie",
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
new Document({
|
|
119
|
-
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
120
|
-
metadata: {
|
|
121
|
-
year: 2019,
|
|
122
|
-
director: "Greta Gerwig",
|
|
123
|
-
rating: 8.3,
|
|
124
|
-
type: "movie",
|
|
125
|
-
},
|
|
126
|
-
}),
|
|
127
|
-
new Document({
|
|
128
|
-
pageContent: "Toys come alive and have a blast doing so",
|
|
129
|
-
metadata: { year: 1995, genre: "animated", type: "movie" },
|
|
130
|
-
}),
|
|
131
|
-
new Document({
|
|
132
|
-
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
133
|
-
metadata: {
|
|
134
|
-
year: 1979,
|
|
135
|
-
director: "Andrei Tarkovsky",
|
|
136
|
-
genre: "science fiction",
|
|
137
|
-
rating: 9.9,
|
|
138
|
-
type: "movie",
|
|
139
|
-
},
|
|
140
|
-
}),
|
|
141
|
-
new Document({
|
|
142
|
-
pageContent: "10x the previous gecs",
|
|
143
|
-
metadata: {
|
|
144
|
-
year: 2023,
|
|
145
|
-
title: "10000 gecs",
|
|
146
|
-
artist: "100 gecs",
|
|
147
|
-
rating: 9.9,
|
|
148
|
-
type: "album",
|
|
149
|
-
},
|
|
150
|
-
}),
|
|
151
|
-
];
|
|
152
|
-
const attributeInfo = [
|
|
153
|
-
{
|
|
154
|
-
name: "genre",
|
|
155
|
-
description: "The genre of the movie",
|
|
156
|
-
type: "string or array of strings",
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "year",
|
|
160
|
-
description: "The year the movie was released",
|
|
161
|
-
type: "number",
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
name: "director",
|
|
165
|
-
description: "The director of the movie",
|
|
166
|
-
type: "string",
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: "rating",
|
|
170
|
-
description: "The rating of the movie (1-10)",
|
|
171
|
-
type: "number",
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
name: "length",
|
|
175
|
-
description: "The length of the movie in minutes",
|
|
176
|
-
type: "number",
|
|
177
|
-
},
|
|
178
|
-
];
|
|
179
|
-
const embeddings = new OpenAIEmbeddings();
|
|
180
|
-
const llm = new OpenAI({
|
|
181
|
-
modelName: "gpt-3.5-turbo",
|
|
182
|
-
});
|
|
183
|
-
const documentContents = "Brief summary of a movie";
|
|
184
|
-
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
185
|
-
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
186
|
-
llm,
|
|
187
|
-
vectorStore,
|
|
188
|
-
documentContents,
|
|
189
|
-
attributeInfo,
|
|
190
|
-
structuredQueryTranslator: new FunctionalTranslator(),
|
|
191
|
-
searchParams: {
|
|
192
|
-
filter: (doc) => doc.metadata && doc.metadata.type === "movie",
|
|
193
|
-
mergeFiltersOperator: "or",
|
|
194
|
-
k: docs.length,
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
198
|
-
console.log(query1);
|
|
199
|
-
expect(query1.length).toEqual(6);
|
|
200
|
-
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
201
|
-
console.log(query2);
|
|
202
|
-
expect(query2.length).toEqual(7);
|
|
203
|
-
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
204
|
-
console.log(query3);
|
|
205
|
-
expect(query3.length).toEqual(6);
|
|
206
|
-
const query4 = await selfQueryRetriever.getRelevantDocuments("Awawawa au au au wawawawa hello?");
|
|
207
|
-
console.log(query4);
|
|
208
|
-
expect(query4.length).toEqual(6); // this one should return documents since default filter takes over
|
|
209
|
-
});
|
|
210
|
-
test("Memory Vector Store Self Query Retriever Test With Default Filter And Merge Operator", async () => {
|
|
211
|
-
const docs = [
|
|
212
|
-
new Document({
|
|
213
|
-
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
214
|
-
metadata: {
|
|
215
|
-
year: 1993,
|
|
216
|
-
rating: 7.7,
|
|
217
|
-
genre: "science fiction",
|
|
218
|
-
type: "movie",
|
|
219
|
-
},
|
|
220
|
-
}),
|
|
221
|
-
new Document({
|
|
222
|
-
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
223
|
-
metadata: {
|
|
224
|
-
year: 2010,
|
|
225
|
-
director: "Christopher Nolan",
|
|
226
|
-
rating: 8.2,
|
|
227
|
-
type: "movie",
|
|
228
|
-
},
|
|
229
|
-
}),
|
|
230
|
-
new Document({
|
|
231
|
-
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
232
|
-
metadata: {
|
|
233
|
-
year: 2006,
|
|
234
|
-
director: "Satoshi Kon",
|
|
235
|
-
rating: 8.6,
|
|
236
|
-
type: "movie",
|
|
237
|
-
},
|
|
238
|
-
}),
|
|
239
|
-
new Document({
|
|
240
|
-
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
241
|
-
metadata: {
|
|
242
|
-
year: 2019,
|
|
243
|
-
director: "Greta Gerwig",
|
|
244
|
-
rating: 8.3,
|
|
245
|
-
type: "movie",
|
|
246
|
-
},
|
|
247
|
-
}),
|
|
248
|
-
new Document({
|
|
249
|
-
pageContent: "Toys come alive and have a blast doing so",
|
|
250
|
-
metadata: { year: 1995, genre: "animated", type: "movie" },
|
|
251
|
-
}),
|
|
252
|
-
new Document({
|
|
253
|
-
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
254
|
-
metadata: {
|
|
255
|
-
year: 1979,
|
|
256
|
-
director: "Andrei Tarkovsky",
|
|
257
|
-
genre: "science fiction",
|
|
258
|
-
rating: 9.9,
|
|
259
|
-
type: "movie",
|
|
260
|
-
},
|
|
261
|
-
}),
|
|
262
|
-
new Document({
|
|
263
|
-
pageContent: "10x the previous gecs",
|
|
264
|
-
metadata: {
|
|
265
|
-
year: 2023,
|
|
266
|
-
title: "10000 gecs",
|
|
267
|
-
artist: "100 gecs",
|
|
268
|
-
rating: 9.9,
|
|
269
|
-
type: "album",
|
|
270
|
-
},
|
|
271
|
-
}),
|
|
272
|
-
];
|
|
273
|
-
const attributeInfo = [
|
|
274
|
-
{
|
|
275
|
-
name: "genre",
|
|
276
|
-
description: "The genre of the movie",
|
|
277
|
-
type: "string or array of strings",
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
name: "year",
|
|
281
|
-
description: "The year the movie was released",
|
|
282
|
-
type: "number",
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
name: "director",
|
|
286
|
-
description: "The director of the movie",
|
|
287
|
-
type: "string",
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
name: "rating",
|
|
291
|
-
description: "The rating of the movie (1-10)",
|
|
292
|
-
type: "number",
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
name: "length",
|
|
296
|
-
description: "The length of the movie in minutes",
|
|
297
|
-
type: "number",
|
|
298
|
-
},
|
|
299
|
-
];
|
|
300
|
-
const embeddings = new OpenAIEmbeddings();
|
|
301
|
-
const llm = new OpenAI({
|
|
302
|
-
modelName: "gpt-3.5-turbo",
|
|
303
|
-
});
|
|
304
|
-
const documentContents = "Brief summary of a movie";
|
|
305
|
-
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
306
|
-
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
307
|
-
llm,
|
|
308
|
-
vectorStore,
|
|
309
|
-
documentContents,
|
|
310
|
-
attributeInfo,
|
|
311
|
-
structuredQueryTranslator: new FunctionalTranslator(),
|
|
312
|
-
searchParams: {
|
|
313
|
-
filter: (doc) => doc.metadata && doc.metadata.type === "movie",
|
|
314
|
-
mergeFiltersOperator: "and",
|
|
315
|
-
k: docs.length,
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
319
|
-
console.log(query1);
|
|
320
|
-
expect(query1.length).toEqual(0);
|
|
321
|
-
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
322
|
-
console.log(query2);
|
|
323
|
-
expect(query2.length).toEqual(2);
|
|
324
|
-
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
325
|
-
console.log(query3);
|
|
326
|
-
expect(query3.length).toEqual(1);
|
|
327
|
-
const query4 = await selfQueryRetriever.getRelevantDocuments("Awawawa au au au wawawawa hello?");
|
|
328
|
-
console.log(query4);
|
|
329
|
-
expect(query4.length).toEqual(0); // this one should return documents since default filter takes over
|
|
330
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { OpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
|
3
|
-
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
-
import { LLMChain } from "../../chains/llm_chain.js";
|
|
5
|
-
import { StuffDocumentsChain } from "../../chains/combine_docs_chain.js";
|
|
6
|
-
import { ConversationalRetrievalQAChain } from "../../chains/conversational_retrieval_chain.js";
|
|
7
|
-
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
8
|
-
import { ContextualCompressionRetriever } from "../contextual_compression.js";
|
|
9
|
-
import { LLMChainExtractor } from "../document_compressors/chain_extract.js";
|
|
10
|
-
test("Test LLMChainExtractor", async () => {
|
|
11
|
-
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
12
|
-
const prompt = PromptTemplate.fromTemplate("Print {question}, and ignore {chat_history}");
|
|
13
|
-
const baseCompressor = LLMChainExtractor.fromLLM(model);
|
|
14
|
-
expect(baseCompressor).toBeDefined();
|
|
15
|
-
const retriever = new ContextualCompressionRetriever({
|
|
16
|
-
baseCompressor,
|
|
17
|
-
baseRetriever: await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new OpenAIEmbeddings()).then((vectorStore) => vectorStore.asRetriever()),
|
|
18
|
-
});
|
|
19
|
-
const llmChain = new LLMChain({ prompt, llm: model });
|
|
20
|
-
const combineDocsChain = new StuffDocumentsChain({
|
|
21
|
-
llmChain,
|
|
22
|
-
documentVariableName: "foo",
|
|
23
|
-
});
|
|
24
|
-
const chain = new ConversationalRetrievalQAChain({
|
|
25
|
-
retriever,
|
|
26
|
-
combineDocumentsChain: combineDocsChain,
|
|
27
|
-
questionGeneratorChain: llmChain,
|
|
28
|
-
});
|
|
29
|
-
const res = await chain.call({ question: "foo", chat_history: "bar" });
|
|
30
|
-
expect(res.text.length).toBeGreaterThan(0);
|
|
31
|
-
console.log({ res });
|
|
32
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@jest/globals";
|
|
2
|
-
import { CohereEmbeddings } from "@langchain/cohere";
|
|
3
|
-
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
4
|
-
import { EnsembleRetriever } from "../ensemble.js";
|
|
5
|
-
test("Should work with a question input", async () => {
|
|
6
|
-
const vectorstore = await MemoryVectorStore.fromTexts([
|
|
7
|
-
"Buildings are made out of brick",
|
|
8
|
-
"Buildings are made out of wood",
|
|
9
|
-
"Buildings are made out of stone",
|
|
10
|
-
"Cars are made out of metal",
|
|
11
|
-
"Cars are made out of plastic",
|
|
12
|
-
"mitochondria is the powerhouse of the cell",
|
|
13
|
-
"mitochondria is made of lipids",
|
|
14
|
-
], [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }], new CohereEmbeddings({ model: "embed-english-v3.0" }));
|
|
15
|
-
const retriever = new EnsembleRetriever({
|
|
16
|
-
retrievers: [vectorstore.asRetriever()],
|
|
17
|
-
});
|
|
18
|
-
const query = "What are mitochondria made of?";
|
|
19
|
-
const retrievedDocs = await retriever.invoke(query);
|
|
20
|
-
expect(retrievedDocs[0].pageContent).toContain("mitochondria");
|
|
21
|
-
});
|
|
22
|
-
test("Should work with multiple retriever", async () => {
|
|
23
|
-
const vectorstore = await MemoryVectorStore.fromTexts([
|
|
24
|
-
"Buildings are made out of brick",
|
|
25
|
-
"Buildings are made out of wood",
|
|
26
|
-
"Buildings are made out of stone",
|
|
27
|
-
"Cars are made out of metal",
|
|
28
|
-
"Cars are made out of plastic",
|
|
29
|
-
"mitochondria is the powerhouse of the cell",
|
|
30
|
-
"mitochondria is made of lipids",
|
|
31
|
-
], [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }], new CohereEmbeddings({ model: "embed-english-v3.0" }));
|
|
32
|
-
const vectorstore2 = await MemoryVectorStore.fromTexts([
|
|
33
|
-
"Buildings are made out of brick",
|
|
34
|
-
"Buildings are made out of wood",
|
|
35
|
-
"Buildings are made out of stone",
|
|
36
|
-
"Cars are made out of metal",
|
|
37
|
-
"Cars are made out of plastic",
|
|
38
|
-
"mitochondria is the powerhouse of the cell",
|
|
39
|
-
"mitochondria is made of lipids",
|
|
40
|
-
], [{ id: 6 }, { id: 7 }, { id: 8 }, { id: 9 }, { id: 10 }], new CohereEmbeddings({ model: "embed-english-v3.0" }));
|
|
41
|
-
const retriever = new EnsembleRetriever({
|
|
42
|
-
retrievers: [vectorstore.asRetriever(), vectorstore2.asRetriever()],
|
|
43
|
-
});
|
|
44
|
-
const query = "cars";
|
|
45
|
-
const retrievedDocs = await retriever.invoke(query);
|
|
46
|
-
expect(retrievedDocs.filter((item) => item.pageContent.includes("Cars")).length).toBe(2);
|
|
47
|
-
});
|
|
48
|
-
test("Should work with weights", async () => {
|
|
49
|
-
const vectorstore = await MemoryVectorStore.fromTexts([
|
|
50
|
-
"Buildings are made out of brick",
|
|
51
|
-
"Buildings are made out of wood",
|
|
52
|
-
"Buildings are made out of stone",
|
|
53
|
-
"Cars are made out of metal",
|
|
54
|
-
"Cars are made out of plastic",
|
|
55
|
-
"mitochondria is the powerhouse of the cell",
|
|
56
|
-
"mitochondria is made of lipids",
|
|
57
|
-
], [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }], new CohereEmbeddings({ model: "embed-english-v3.0" }));
|
|
58
|
-
const vectorstore2 = await MemoryVectorStore.fromTexts([
|
|
59
|
-
"Buildings are made out of brick",
|
|
60
|
-
"Buildings are made out of wood",
|
|
61
|
-
"Buildings are made out of stone",
|
|
62
|
-
"Cars are made out of metal",
|
|
63
|
-
"Cars are made out of plastic",
|
|
64
|
-
"mitochondria is the powerhouse of the cell",
|
|
65
|
-
"mitochondria is made of lipids",
|
|
66
|
-
], [{ id: 6 }, { id: 7 }, { id: 8 }, { id: 9 }, { id: 10 }], new CohereEmbeddings({ model: "embed-english-v3.0" }));
|
|
67
|
-
const retriever = new EnsembleRetriever({
|
|
68
|
-
retrievers: [vectorstore.asRetriever(), vectorstore2.asRetriever()],
|
|
69
|
-
weights: [0.5, 0.9],
|
|
70
|
-
});
|
|
71
|
-
const query = "cars";
|
|
72
|
-
const retrievedDocs = await retriever.invoke(query);
|
|
73
|
-
expect(retrievedDocs.filter((item) => item.pageContent.includes("Cars")).length).toBe(2);
|
|
74
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|