langchain 0.2.2 → 0.2.3-rc.0
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/dist/agents/tests/agent.int.test.d.ts +1 -0
- package/dist/agents/tests/agent.int.test.js +309 -0
- package/dist/agents/tests/chat_convo_output_parser.test.d.ts +1 -0
- package/dist/agents/tests/chat_convo_output_parser.test.js +91 -0
- package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +2 -0
- package/dist/agents/tests/create_openai_functions_agent.int.test.js +71 -0
- package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_openai_tools_agent.int.test.js +75 -0
- package/dist/agents/tests/create_react_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_react_agent.int.test.js +32 -0
- package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_structured_chat_agent.int.test.js +32 -0
- package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_tool_calling_agent.int.test.js +71 -0
- package/dist/agents/tests/create_xml_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_xml_agent.int.test.js +32 -0
- package/dist/agents/tests/json.test.d.ts +1 -0
- package/dist/agents/tests/json.test.js +74 -0
- package/dist/agents/tests/react.test.d.ts +1 -0
- package/dist/agents/tests/react.test.js +44 -0
- package/dist/agents/tests/runnable.int.test.d.ts +1 -0
- package/dist/agents/tests/runnable.int.test.js +104 -0
- package/dist/agents/tests/sql.test.d.ts +1 -0
- package/dist/agents/tests/sql.test.js +133 -0
- package/dist/agents/tests/structured_chat_output_parser.test.d.ts +1 -0
- package/dist/agents/tests/structured_chat_output_parser.test.js +35 -0
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +1 -0
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +44 -0
- package/dist/agents/tests/structured_output_runnables.int.test.d.ts +1 -0
- package/dist/agents/tests/structured_output_runnables.int.test.js +112 -0
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +1 -0
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +41 -0
- package/dist/cache/tests/file_system.int.test.d.ts +1 -0
- package/dist/cache/tests/file_system.int.test.js +32 -0
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +139 -0
- package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/extraction.int.test.js +33 -0
- package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/openapi.int.test.js +130 -0
- package/dist/chains/openai_functions/tests/openapi.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/openapi.test.js +172 -0
- package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/structured_output.int.test.js +40 -0
- package/dist/chains/openai_functions/tests/structured_output.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/structured_output.test.js +102 -0
- package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/tagging.int.test.js +21 -0
- package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +1 -0
- package/dist/chains/query_constructor/tests/query_chain.int.test.js +93 -0
- package/dist/chains/query_constructor/tests/query_parser.test.d.ts +1 -0
- package/dist/chains/query_constructor/tests/query_parser.test.js +28 -0
- package/dist/chains/question_answering/tests/load.int.test.d.ts +1 -0
- package/dist/chains/question_answering/tests/load.int.test.js +39 -0
- package/dist/chains/router/tests/multi_prompt.int.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_prompt.int.test.js +45 -0
- package/dist/chains/router/tests/multi_prompt.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_prompt.test.js +62 -0
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +67 -0
- package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_retrieval_qa.test.js +125 -0
- package/dist/chains/summarization/tests/load.int.test.d.ts +1 -0
- package/dist/chains/summarization/tests/load.int.test.js +37 -0
- package/dist/chains/tests/api_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/api_chain.int.test.js +55 -0
- package/dist/chains/tests/combine_docs_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/combine_docs_chain.int.test.js +50 -0
- package/dist/chains/tests/combine_docs_chain.test.d.ts +1 -0
- package/dist/chains/tests/combine_docs_chain.test.js +98 -0
- package/dist/chains/tests/constitutional_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/constitutional_chain.int.test.js +30 -0
- package/dist/chains/tests/constitutional_chain.test.d.ts +1 -0
- package/dist/chains/tests/constitutional_chain.test.js +63 -0
- package/dist/chains/tests/conversation_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/conversation_chain.int.test.js +9 -0
- package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/conversational_retrieval_chain.int.test.js +243 -0
- package/dist/chains/tests/example_data/open_meteo_docs.d.ts +1 -0
- package/dist/chains/tests/example_data/open_meteo_docs.js +29 -0
- package/dist/chains/tests/history_aware_retriever.int.test.d.ts +1 -0
- package/dist/chains/tests/history_aware_retriever.int.test.js +41 -0
- package/dist/chains/tests/history_aware_retriever.test.d.ts +1 -0
- package/dist/chains/tests/history_aware_retriever.test.js +27 -0
- package/dist/chains/tests/llm_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/llm_chain.int.test.js +119 -0
- package/dist/chains/tests/openai_moderation.int.test.d.ts +1 -0
- package/dist/chains/tests/openai_moderation.int.test.js +30 -0
- package/dist/chains/tests/retrieval_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/retrieval_chain.int.test.js +69 -0
- package/dist/chains/tests/retrieval_chain.test.d.ts +1 -0
- package/dist/chains/tests/retrieval_chain.test.js +36 -0
- package/dist/chains/tests/sequential_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/sequential_chain.int.test.js +88 -0
- package/dist/chains/tests/sequential_chain.test.d.ts +1 -0
- package/dist/chains/tests/sequential_chain.test.js +295 -0
- package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/simple_sequential_chain.int.test.js +81 -0
- package/dist/chains/tests/simple_sequential_chain.test.d.ts +1 -0
- package/dist/chains/tests/simple_sequential_chain.test.js +128 -0
- package/dist/chains/tests/sql_db_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/sql_db_chain.int.test.js +125 -0
- package/dist/chains/tests/transform.test.d.ts +1 -0
- package/dist/chains/tests/transform.test.js +12 -0
- package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/vector_db_qa_chain.int.test.js +45 -0
- package/dist/document_loaders/tests/assemblyai.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/assemblyai.int.test.js +111 -0
- package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/chatgpt-blob.test.js +30 -0
- package/dist/document_loaders/tests/chatgpt.test.d.ts +1 -0
- package/dist/document_loaders/tests/chatgpt.test.js +29 -0
- package/dist/document_loaders/tests/cheerio.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/cheerio.int.test.js +21 -0
- package/dist/document_loaders/tests/college_confidential.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/college_confidential.int.test.js +6 -0
- package/dist/document_loaders/tests/confluence.test.d.ts +1 -0
- package/dist/document_loaders/tests/confluence.test.js +52 -0
- package/dist/document_loaders/tests/couchbase.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/couchbase.int.test.js +28 -0
- package/dist/document_loaders/tests/csv-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/csv-blob.test.js +51 -0
- package/dist/document_loaders/tests/csv.test.d.ts +1 -0
- package/dist/document_loaders/tests/csv.test.js +41 -0
- package/dist/document_loaders/tests/directory.test.d.ts +1 -0
- package/dist/document_loaders/tests/directory.test.js +38 -0
- package/dist/document_loaders/tests/docx.test.d.ts +1 -0
- package/dist/document_loaders/tests/docx.test.js +11 -0
- package/dist/document_loaders/tests/epub.test.d.ts +1 -0
- package/dist/document_loaders/tests/epub.test.js +18 -0
- package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +5 -0
- package/dist/document_loaders/tests/example_data/github_api_responses.js +91 -0
- package/dist/document_loaders/tests/figma.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/figma.int.test.js +13 -0
- package/dist/document_loaders/tests/firecrawl.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/firecrawl.int.test.js +30 -0
- package/dist/document_loaders/tests/gitbook.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/gitbook.int.test.js +14 -0
- package/dist/document_loaders/tests/github.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/github.int.test.js +86 -0
- package/dist/document_loaders/tests/github.test.d.ts +1 -0
- package/dist/document_loaders/tests/github.test.js +51 -0
- package/dist/document_loaders/tests/hn.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/hn.int.test.js +6 -0
- package/dist/document_loaders/tests/imsdb.test.d.ts +1 -0
- package/dist/document_loaders/tests/imsdb.test.js +6 -0
- package/dist/document_loaders/tests/json-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/json-blob.test.js +87 -0
- package/dist/document_loaders/tests/json.test.d.ts +1 -0
- package/dist/document_loaders/tests/json.test.js +69 -0
- package/dist/document_loaders/tests/jsonl-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/jsonl-blob.test.js +44 -0
- package/dist/document_loaders/tests/jsonl.test.d.ts +1 -0
- package/dist/document_loaders/tests/jsonl.test.js +15 -0
- package/dist/document_loaders/tests/notion.test.d.ts +1 -0
- package/dist/document_loaders/tests/notion.test.js +11 -0
- package/dist/document_loaders/tests/notionapi.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/notionapi.int.test.js +80 -0
- package/dist/document_loaders/tests/notionapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/notionapi.test.js +84 -0
- package/dist/document_loaders/tests/notiondb.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/notiondb.int.test.js +13 -0
- package/dist/document_loaders/tests/obsidian.test.d.ts +1 -0
- package/dist/document_loaders/tests/obsidian.test.js +119 -0
- package/dist/document_loaders/tests/pdf-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/pdf-blob.test.js +44 -0
- package/dist/document_loaders/tests/pdf.test.d.ts +1 -0
- package/dist/document_loaders/tests/pdf.test.js +25 -0
- package/dist/document_loaders/tests/playwright_web.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/playwright_web.int.test.js +27 -0
- package/dist/document_loaders/tests/pptx.test.d.ts +1 -0
- package/dist/document_loaders/tests/pptx.test.js +17 -0
- package/dist/document_loaders/tests/puppeteer.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/puppeteer.int.test.js +47 -0
- package/dist/document_loaders/tests/recursive_url.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/recursive_url.int.test.js +64 -0
- package/dist/document_loaders/tests/s3.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/s3.int.test.js +48 -0
- package/dist/document_loaders/tests/searchapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/searchapi.test.js +29 -0
- package/dist/document_loaders/tests/serpapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/serpapi.test.js +21 -0
- package/dist/document_loaders/tests/sitemap.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sitemap.int.test.js +28 -0
- package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sonix_audio.int.test.js +55 -0
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +38 -0
- package/dist/document_loaders/tests/srt-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/srt-blob.test.js +18 -0
- package/dist/document_loaders/tests/srt.test.d.ts +1 -0
- package/dist/document_loaders/tests/srt.test.js +16 -0
- package/dist/document_loaders/tests/text-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/text-blob.test.js +14 -0
- package/dist/document_loaders/tests/text.test.d.ts +1 -0
- package/dist/document_loaders/tests/text.test.js +22 -0
- package/dist/document_loaders/tests/unstructured.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/unstructured.int.test.js +40 -0
- package/dist/document_loaders/tests/webpdf.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/webpdf.int.test.js +90 -0
- package/dist/document_transformers/tests/openai_functions.int.test.d.ts +1 -0
- package/dist/document_transformers/tests/openai_functions.int.test.js +40 -0
- package/dist/embeddings/tests/cache.test.d.ts +1 -0
- package/dist/embeddings/tests/cache.test.js +24 -0
- package/dist/embeddings/tests/fake.test.d.ts +1 -0
- package/dist/embeddings/tests/fake.test.js +34 -0
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +33 -0
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +46 -0
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +108 -0
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +26 -0
- package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/qa/tests/eval_chain.int.test.js +27 -0
- package/dist/experimental/autogpt/tests/output_parser.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/output_parser.test.js +8 -0
- package/dist/experimental/autogpt/tests/prompt.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/prompt.test.js +69 -0
- package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/prompt_generator.test.js +91 -0
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +1 -0
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +26 -0
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +1 -0
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +304 -0
- package/dist/experimental/masking/tests/masking-extended.test.d.ts +1 -0
- package/dist/experimental/masking/tests/masking-extended.test.js +58 -0
- package/dist/experimental/masking/tests/masking.test.d.ts +1 -0
- package/dist/experimental/masking/tests/masking.test.js +388 -0
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +1 -0
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +203 -0
- package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +1 -0
- package/dist/experimental/openai_files/tests/openai_file.int.test.js +87 -0
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +1 -0
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +54 -0
- package/dist/experimental/prompts/tests/handlebars.test.d.ts +1 -0
- package/dist/experimental/prompts/tests/handlebars.test.js +24 -0
- package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +1 -0
- package/dist/experimental/tools/tests/pyinterpreter.int.test.js +22 -0
- package/dist/load/import_map.cjs +1 -1
- package/dist/load/import_map.js +1 -1
- package/dist/load/tests/cross_language.test.d.ts +1 -0
- package/dist/load/tests/cross_language.test.js +83 -0
- package/dist/load/tests/load.int.test.d.ts +1 -0
- package/dist/load/tests/load.int.test.js +9 -0
- package/dist/load/tests/load.test.d.ts +1 -0
- package/dist/load/tests/load.test.js +412 -0
- package/dist/memory/tests/buffer_memory.test.d.ts +1 -0
- package/dist/memory/tests/buffer_memory.test.js +34 -0
- package/dist/memory/tests/buffer_token_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/buffer_token_memory.int.test.js +47 -0
- package/dist/memory/tests/buffer_window_memory.test.d.ts +1 -0
- package/dist/memory/tests/buffer_window_memory.test.js +42 -0
- package/dist/memory/tests/combined_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/combined_memory.int.test.js +74 -0
- package/dist/memory/tests/entity_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/entity_memory.int.test.js +79 -0
- package/dist/memory/tests/entity_memory.test.d.ts +1 -0
- package/dist/memory/tests/entity_memory.test.js +48 -0
- package/dist/memory/tests/summary.int.test.d.ts +1 -0
- package/dist/memory/tests/summary.int.test.js +50 -0
- package/dist/memory/tests/summary_buffer.int.test.d.ts +1 -0
- package/dist/memory/tests/summary_buffer.int.test.js +55 -0
- package/dist/memory/tests/vector_store_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/vector_store_memory.int.test.js +55 -0
- package/dist/output_parsers/tests/combining.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/combining.int.test.js +26 -0
- package/dist/output_parsers/tests/combining.test.d.ts +1 -0
- package/dist/output_parsers/tests/combining.test.js +54 -0
- package/dist/output_parsers/tests/datetime.test.d.ts +1 -0
- package/dist/output_parsers/tests/datetime.test.js +14 -0
- package/dist/output_parsers/tests/expression.test.d.ts +1 -0
- package/dist/output_parsers/tests/expression.test.js +339 -0
- package/dist/output_parsers/tests/http_response.test.d.ts +1 -0
- package/dist/output_parsers/tests/http_response.test.js +39 -0
- package/dist/output_parsers/tests/list.test.d.ts +1 -0
- package/dist/output_parsers/tests/list.test.js +27 -0
- package/dist/output_parsers/tests/openai_functions.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/openai_functions.int.test.js +89 -0
- package/dist/output_parsers/tests/openai_tools.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/openai_tools.int.test.js +36 -0
- package/dist/output_parsers/tests/structured.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/structured.int.test.js +150 -0
- package/dist/prompts/tests/selectors.test.d.ts +1 -0
- package/dist/prompts/tests/selectors.test.js +59 -0
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +1 -0
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +330 -0
- package/dist/retrievers/tests/chain_extract.int.test.d.ts +1 -0
- package/dist/retrievers/tests/chain_extract.int.test.js +32 -0
- package/dist/retrievers/tests/hyde.int.test.d.ts +1 -0
- package/dist/retrievers/tests/hyde.int.test.js +44 -0
- package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +1 -0
- package/dist/retrievers/tests/matryoshka_retriever.int.test.js +113 -0
- package/dist/retrievers/tests/multi_query.int.test.d.ts +1 -0
- package/dist/retrievers/tests/multi_query.int.test.js +45 -0
- package/dist/retrievers/tests/parent_document.int.test.d.ts +1 -0
- package/dist/retrievers/tests/parent_document.int.test.js +122 -0
- package/dist/retrievers/tests/score_threshold.int.test.d.ts +1 -0
- package/dist/retrievers/tests/score_threshold.int.test.js +83 -0
- package/dist/retrievers/tests/time_weighted.test.d.ts +1 -0
- package/dist/retrievers/tests/time_weighted.test.js +320 -0
- package/dist/retrievers/tests/vectorstores.test.d.ts +1 -0
- package/dist/retrievers/tests/vectorstores.test.js +50 -0
- package/dist/smith/tests/run_on_dataset.int.test.d.ts +1 -0
- package/dist/smith/tests/run_on_dataset.int.test.js +257 -0
- package/dist/smith/tests/runner_utils.int.test.d.ts +9 -0
- package/dist/smith/tests/runner_utils.int.test.js +234 -0
- package/dist/storage/tests/file_system.test.d.ts +1 -0
- package/dist/storage/tests/file_system.test.js +81 -0
- package/dist/tools/tests/chain.test.d.ts +1 -0
- package/dist/tools/tests/chain.test.js +136 -0
- package/dist/tools/tests/webbrowser.int.test.d.ts +1 -0
- package/dist/tools/tests/webbrowser.int.test.js +80 -0
- package/dist/tools/tests/webbrowser.test.d.ts +1 -0
- package/dist/tools/tests/webbrowser.test.js +21 -0
- package/dist/util/tests/async_caller.int.test.d.ts +1 -0
- package/dist/util/tests/async_caller.int.test.js +34 -0
- package/dist/util/tests/azure.test.d.ts +1 -0
- package/dist/util/tests/azure.test.js +42 -0
- package/dist/util/tests/openai-stream.test.d.ts +1 -0
- package/dist/util/tests/openai-stream.test.js +135 -0
- package/dist/util/tests/set.test.d.ts +1 -0
- package/dist/util/tests/set.test.js +36 -0
- package/dist/util/tests/sql_utils.test.d.ts +1 -0
- package/dist/util/tests/sql_utils.test.js +50 -0
- package/dist/vectorstores/tests/memory.test.d.ts +1 -0
- package/dist/vectorstores/tests/memory.test.js +78 -0
- package/package.json +5 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
3
|
+
import { OpenAPISpec } from "../../../util/openapi.js";
|
|
4
|
+
import { convertOpenAPISchemaToJSONSchema } from "../openapi.js";
|
|
5
|
+
test("Test convert OpenAPI params to JSON Schema", async () => {
|
|
6
|
+
const spec = new OpenAPISpec({
|
|
7
|
+
openapi: "3.1.0",
|
|
8
|
+
info: {
|
|
9
|
+
title: "A fake spec for testing",
|
|
10
|
+
version: "0.0.1",
|
|
11
|
+
},
|
|
12
|
+
paths: {
|
|
13
|
+
"/widgets": {
|
|
14
|
+
post: {
|
|
15
|
+
operationId: "createWidget",
|
|
16
|
+
description: "Create a widget",
|
|
17
|
+
parameters: [
|
|
18
|
+
{
|
|
19
|
+
name: "stringParam",
|
|
20
|
+
in: "query",
|
|
21
|
+
schema: {
|
|
22
|
+
type: "string",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "objectParam",
|
|
27
|
+
in: "query",
|
|
28
|
+
schema: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
foo: {
|
|
32
|
+
type: "string",
|
|
33
|
+
},
|
|
34
|
+
bar: {
|
|
35
|
+
type: "number",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "stringArrayParam",
|
|
42
|
+
in: "query",
|
|
43
|
+
schema: {
|
|
44
|
+
type: "array",
|
|
45
|
+
items: {
|
|
46
|
+
type: "string",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "nestedObjectInArrayParam",
|
|
52
|
+
in: "query",
|
|
53
|
+
schema: {
|
|
54
|
+
type: "array",
|
|
55
|
+
items: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
baz: {
|
|
59
|
+
type: "number",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "nestedArrayInObjectParam",
|
|
67
|
+
in: "query",
|
|
68
|
+
schema: {
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
qux: {
|
|
72
|
+
type: "array",
|
|
73
|
+
items: {
|
|
74
|
+
type: "string",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "inceptionParam",
|
|
82
|
+
in: "query",
|
|
83
|
+
schema: {
|
|
84
|
+
type: "array",
|
|
85
|
+
items: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
nestedArray: {
|
|
89
|
+
type: "array",
|
|
90
|
+
items: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: {
|
|
93
|
+
nestedObject: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
inception: {
|
|
97
|
+
type: "number",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
responses: {
|
|
110
|
+
"200": {
|
|
111
|
+
description: "OK",
|
|
112
|
+
content: {
|
|
113
|
+
"application/json": {
|
|
114
|
+
schema: {
|
|
115
|
+
properties: {
|
|
116
|
+
success: {
|
|
117
|
+
type: "boolean",
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const createWidget = spec.getOperation("/widgets", OpenAPIV3.HttpMethods.POST);
|
|
130
|
+
expect(createWidget).not.toBeUndefined();
|
|
131
|
+
if (!createWidget) {
|
|
132
|
+
throw new Error(`Operation not found`);
|
|
133
|
+
}
|
|
134
|
+
function getParamSchema(operation, paramName) {
|
|
135
|
+
const param = spec
|
|
136
|
+
.getParametersForOperation(operation)
|
|
137
|
+
.find((param) => param.name === paramName);
|
|
138
|
+
if (!param) {
|
|
139
|
+
throw new Error(`Param not found`);
|
|
140
|
+
}
|
|
141
|
+
if (!param.schema) {
|
|
142
|
+
throw new Error(`Param schema not found`);
|
|
143
|
+
}
|
|
144
|
+
return spec.getSchema(param.schema);
|
|
145
|
+
}
|
|
146
|
+
function expectType(type, schema) {
|
|
147
|
+
if (!schema || !("type" in schema)) {
|
|
148
|
+
throw new Error(`Schema has no type`);
|
|
149
|
+
}
|
|
150
|
+
if (schema.type !== type) {
|
|
151
|
+
throw new Error(`Unexpected type: ${schema.type}`);
|
|
152
|
+
}
|
|
153
|
+
return schema;
|
|
154
|
+
}
|
|
155
|
+
const stringParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "stringParam"), spec);
|
|
156
|
+
expectType("string", stringParamSchema);
|
|
157
|
+
const objectParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "objectParam"), spec);
|
|
158
|
+
const typedObjectParamSchema = expectType("object", objectParamSchema);
|
|
159
|
+
expectType("string", typedObjectParamSchema.properties.foo);
|
|
160
|
+
expectType("number", typedObjectParamSchema.properties.bar);
|
|
161
|
+
const stringArrayParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "stringArrayParam"), spec);
|
|
162
|
+
const typedStringArrayParamSchema = expectType("array", stringArrayParamSchema);
|
|
163
|
+
expect(typedStringArrayParamSchema.items).not.toBeUndefined();
|
|
164
|
+
expectType("string", typedStringArrayParamSchema.items);
|
|
165
|
+
const nestedObjectInArrayParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "nestedObjectInArrayParam"), spec);
|
|
166
|
+
expectType("number", expectType("object", expectType("array", nestedObjectInArrayParamSchema).items).properties.baz);
|
|
167
|
+
const nestedArrayInObjectParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "nestedArrayInObjectParam"), spec);
|
|
168
|
+
expectType("string", expectType("array", expectType("object", nestedArrayInObjectParamSchema).properties.qux).items);
|
|
169
|
+
const inceptionParamSchema = convertOpenAPISchemaToJSONSchema(getParamSchema(createWidget, "inceptionParam"), spec);
|
|
170
|
+
expectType("number", expectType("object", expectType("object", expectType("array", expectType("object", expectType("array", inceptionParamSchema).items)
|
|
171
|
+
.properties.nestedArray).items).properties.nestedObject).properties.inception);
|
|
172
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
+
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from "@langchain/core/prompts";
|
|
5
|
+
import { createStructuredOutputChainFromZod } from "../structured_output.js";
|
|
6
|
+
test("structured output chain", async () => {
|
|
7
|
+
const chain = createStructuredOutputChainFromZod(z.object({
|
|
8
|
+
name: z.string().describe("Human name"),
|
|
9
|
+
surname: z.string().describe("Human surname"),
|
|
10
|
+
age: z.number().describe("Human age"),
|
|
11
|
+
appearance: z.string().describe("Human appearance description"),
|
|
12
|
+
shortBio: z.string().describe("Short bio secription"),
|
|
13
|
+
university: z.string().optional().describe("University name if attended"),
|
|
14
|
+
gender: z.string().describe("Gender of the human"),
|
|
15
|
+
interests: z
|
|
16
|
+
.array(z.string())
|
|
17
|
+
.describe("json array of strings human interests"),
|
|
18
|
+
}), {
|
|
19
|
+
prompt: new ChatPromptTemplate({
|
|
20
|
+
promptMessages: [
|
|
21
|
+
SystemMessagePromptTemplate.fromTemplate("Generate details of a hypothetical person."),
|
|
22
|
+
HumanMessagePromptTemplate.fromTemplate("Person description: {inputText}"),
|
|
23
|
+
],
|
|
24
|
+
inputVariables: ["inputText"],
|
|
25
|
+
}),
|
|
26
|
+
llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo-0613", temperature: 0 }),
|
|
27
|
+
outputKey: "person",
|
|
28
|
+
});
|
|
29
|
+
const response = await chain.call({ inputText: "A man, living in Poland." });
|
|
30
|
+
console.log("response", response);
|
|
31
|
+
expect(response.person).toHaveProperty("name");
|
|
32
|
+
expect(response.person).toHaveProperty("surname");
|
|
33
|
+
expect(response.person).toHaveProperty("age");
|
|
34
|
+
expect(response.person).toHaveProperty("appearance");
|
|
35
|
+
expect(response.person).toHaveProperty("shortBio");
|
|
36
|
+
expect(response.person).toHaveProperty("age");
|
|
37
|
+
expect(response.person).toHaveProperty("gender");
|
|
38
|
+
expect(response.person).toHaveProperty("interests");
|
|
39
|
+
expect(response.person.interests.length).toBeGreaterThan(0);
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
|
+
import { AIMessage } from "@langchain/core/messages";
|
|
5
|
+
import { FunctionCallStructuredOutputParser } from "../structured_output.js";
|
|
6
|
+
test("structured output parser", async () => {
|
|
7
|
+
const parser = new FunctionCallStructuredOutputParser(zodToJsonSchema(z.object({
|
|
8
|
+
name: z.string().describe("Human name"),
|
|
9
|
+
surname: z.string().describe("Human surname"),
|
|
10
|
+
age: z.number().describe("Human age"),
|
|
11
|
+
appearance: z.string().describe("Human appearance description"),
|
|
12
|
+
shortBio: z.string().describe("Short bio secription"),
|
|
13
|
+
university: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe("University name if attended"),
|
|
17
|
+
gender: z.string().describe("Gender of the human"),
|
|
18
|
+
interests: z
|
|
19
|
+
.array(z.string())
|
|
20
|
+
.describe("json array of strings human interests"),
|
|
21
|
+
})));
|
|
22
|
+
const result = await parser.parseResult([
|
|
23
|
+
{
|
|
24
|
+
text: "",
|
|
25
|
+
message: new AIMessage({
|
|
26
|
+
content: "",
|
|
27
|
+
additional_kwargs: {
|
|
28
|
+
function_call: {
|
|
29
|
+
name: "",
|
|
30
|
+
arguments: JSON.stringify({
|
|
31
|
+
name: "Anna",
|
|
32
|
+
surname: "Kowalska",
|
|
33
|
+
age: 30,
|
|
34
|
+
appearance: "Anna has shoulder-length brown hair and green eyes. She has a slim build and stands at around 5'6\" tall.",
|
|
35
|
+
shortBio: "Anna is a kind and compassionate person who loves to help others. She works as a nurse at a local hospital in Poland. In her free time, she enjoys reading, cooking, and spending time with her friends and family. Anna is also passionate about traveling and exploring new places.",
|
|
36
|
+
university: null,
|
|
37
|
+
gender: "female",
|
|
38
|
+
interests: ["reading", "cooking", "traveling"],
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
console.log("result", result);
|
|
46
|
+
expect(result.name).toEqual("Anna");
|
|
47
|
+
expect(result.surname).toEqual("Kowalska");
|
|
48
|
+
expect(result.age).toEqual(30);
|
|
49
|
+
expect(result).toHaveProperty("appearance");
|
|
50
|
+
expect(result).toHaveProperty("shortBio");
|
|
51
|
+
expect(result).not.toHaveProperty("university");
|
|
52
|
+
expect(result.gender).toEqual("female");
|
|
53
|
+
expect(result.interests.length).toEqual(3);
|
|
54
|
+
});
|
|
55
|
+
test("structured output parser with Zod input", async () => {
|
|
56
|
+
const parser = new FunctionCallStructuredOutputParser({
|
|
57
|
+
zodSchema: z.object({
|
|
58
|
+
name: z.string().describe("Human name"),
|
|
59
|
+
surname: z.string().describe("Human surname"),
|
|
60
|
+
age: z.number().describe("Human age"),
|
|
61
|
+
appearance: z.string().describe("Human appearance description"),
|
|
62
|
+
shortBio: z.string().describe("Short bio secription"),
|
|
63
|
+
university: z.string().optional().describe("University name if attended"),
|
|
64
|
+
gender: z.string().describe("Gender of the human"),
|
|
65
|
+
interests: z
|
|
66
|
+
.array(z.string())
|
|
67
|
+
.describe("json array of strings human interests"),
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
const result = await parser.parseResult([
|
|
71
|
+
{
|
|
72
|
+
text: "",
|
|
73
|
+
message: new AIMessage({
|
|
74
|
+
content: "",
|
|
75
|
+
additional_kwargs: {
|
|
76
|
+
function_call: {
|
|
77
|
+
name: "",
|
|
78
|
+
arguments: JSON.stringify({
|
|
79
|
+
name: "Anna",
|
|
80
|
+
surname: "Kowalska",
|
|
81
|
+
age: 30,
|
|
82
|
+
appearance: "Anna has shoulder-length brown hair and green eyes. She has a slim build and stands at around 5'6\" tall.",
|
|
83
|
+
shortBio: "Anna is a kind and compassionate person who loves to help others. She works as a nurse at a local hospital in Poland. In her free time, she enjoys reading, cooking, and spending time with her friends and family. Anna is also passionate about traveling and exploring new places.",
|
|
84
|
+
university: null,
|
|
85
|
+
gender: "female",
|
|
86
|
+
interests: ["reading", "cooking", "traveling"],
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
93
|
+
console.log("result", result);
|
|
94
|
+
expect(result.name).toEqual("Anna");
|
|
95
|
+
expect(result.surname).toEqual("Kowalska");
|
|
96
|
+
expect(result.age).toEqual(30);
|
|
97
|
+
expect(result).toHaveProperty("appearance");
|
|
98
|
+
expect(result).toHaveProperty("shortBio");
|
|
99
|
+
expect(result).not.toHaveProperty("university");
|
|
100
|
+
expect(result.gender).toEqual("female");
|
|
101
|
+
expect(result.interests.length).toEqual(3);
|
|
102
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { createTaggingChain } from "../tagging.js";
|
|
4
|
+
test("tagging chain", async () => {
|
|
5
|
+
const chain = createTaggingChain({
|
|
6
|
+
type: "object",
|
|
7
|
+
properties: {
|
|
8
|
+
sentiment: { type: "string" },
|
|
9
|
+
tone: { type: "string" },
|
|
10
|
+
language: { type: "string" },
|
|
11
|
+
},
|
|
12
|
+
required: ["tone"],
|
|
13
|
+
}, new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 }));
|
|
14
|
+
const result = await chain.run(`Estoy increiblemente contento de haberte conocido! Creo que seremos muy buenos amigos!`);
|
|
15
|
+
expect(result).toMatchInlineSnapshot(`
|
|
16
|
+
{
|
|
17
|
+
"language": "Spanish",
|
|
18
|
+
"tone": "positive",
|
|
19
|
+
}
|
|
20
|
+
`);
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { OpenAI } from "@langchain/openai";
|
|
3
|
+
import { loadQueryConstructorRunnable } from "../index.js";
|
|
4
|
+
import { Comparators, Comparison, Operation, Operators, StructuredQuery, } from "../ir.js";
|
|
5
|
+
import { BasicTranslator } from "../../../retrievers/self_query/base.js";
|
|
6
|
+
test("Query Chain Test", async () => {
|
|
7
|
+
const sq1 = new StructuredQuery("", new Comparison(Comparators.lt, "length", 90));
|
|
8
|
+
const sq3 = new StructuredQuery("", new Comparison(Comparators.gt, "rating", 8.5));
|
|
9
|
+
const sq4 = new StructuredQuery("", new Comparison(Comparators.eq, "director", "Greta Gerwig"));
|
|
10
|
+
const sq5 = new StructuredQuery("", new Operation(Operators.and, [
|
|
11
|
+
new Operation(Operators.or, [
|
|
12
|
+
new Comparison(Comparators.eq, "genre", "comedy"),
|
|
13
|
+
new Comparison(Comparators.eq, "genre", "drama"),
|
|
14
|
+
]),
|
|
15
|
+
new Comparison(Comparators.lt, "length", 90),
|
|
16
|
+
]));
|
|
17
|
+
const filter1 = { length: { $lt: 90 } };
|
|
18
|
+
const filter3 = { rating: { $gt: 8.5 } };
|
|
19
|
+
const filter4 = { director: { $eq: "Greta Gerwig" } };
|
|
20
|
+
const filter5 = {
|
|
21
|
+
$and: [
|
|
22
|
+
{ $or: [{ genre: { $eq: "comedy" } }, { genre: { $eq: "drama" } }] },
|
|
23
|
+
{ length: { $lt: 90 } },
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
const attributeInfo = [
|
|
27
|
+
{
|
|
28
|
+
name: "genre",
|
|
29
|
+
description: "The genre of the movie",
|
|
30
|
+
type: "string or array of strings",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "year",
|
|
34
|
+
description: "The year the movie was released",
|
|
35
|
+
type: "number",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "director",
|
|
39
|
+
description: "The director of the movie",
|
|
40
|
+
type: "string",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "rating",
|
|
44
|
+
description: "The rating of the movie (1-10)",
|
|
45
|
+
type: "number",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "length",
|
|
49
|
+
description: "The length of the movie in minutes",
|
|
50
|
+
type: "number",
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
const documentContents = "Brief summary of a movie";
|
|
54
|
+
const allowedComparators = Object.values(Comparators);
|
|
55
|
+
const allowedOperators = Object.values(Operators);
|
|
56
|
+
const llm = new OpenAI({
|
|
57
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
58
|
+
temperature: 0,
|
|
59
|
+
});
|
|
60
|
+
const queryChain = loadQueryConstructorRunnable({
|
|
61
|
+
llm,
|
|
62
|
+
documentContents,
|
|
63
|
+
attributeInfo,
|
|
64
|
+
allowedComparators,
|
|
65
|
+
allowedOperators,
|
|
66
|
+
});
|
|
67
|
+
const c1 = queryChain.invoke({
|
|
68
|
+
query: "Which movies are less than 90 minutes?",
|
|
69
|
+
});
|
|
70
|
+
const c3 = queryChain.invoke({
|
|
71
|
+
query: "Which movies are rated higher than 8.5?",
|
|
72
|
+
});
|
|
73
|
+
const c4 = queryChain.invoke({
|
|
74
|
+
query: "Which movies are directed by Greta Gerwig?",
|
|
75
|
+
});
|
|
76
|
+
const c5 = queryChain.invoke({
|
|
77
|
+
query: "Which movies are either comedy or drama and are less than 90 minutes?",
|
|
78
|
+
});
|
|
79
|
+
const [r1, r3, r4, r5] = await Promise.all([c1, c3, c4, c5]);
|
|
80
|
+
expect(r1).toMatchObject(sq1);
|
|
81
|
+
expect(r3).toMatchObject(sq3);
|
|
82
|
+
expect(r4).toMatchObject(sq4);
|
|
83
|
+
expect(r5).toMatchObject(sq5);
|
|
84
|
+
const testTranslator = new BasicTranslator();
|
|
85
|
+
const { filter: parsedFilter1 } = testTranslator.visitStructuredQuery(r1);
|
|
86
|
+
const { filter: parsedFilter3 } = testTranslator.visitStructuredQuery(r3);
|
|
87
|
+
const { filter: parsedFilter4 } = testTranslator.visitStructuredQuery(r4);
|
|
88
|
+
const { filter: parsedFilter5 } = testTranslator.visitStructuredQuery(r5);
|
|
89
|
+
expect(parsedFilter1).toMatchObject(filter1);
|
|
90
|
+
expect(parsedFilter3).toMatchObject(filter3);
|
|
91
|
+
expect(parsedFilter4).toMatchObject(filter4);
|
|
92
|
+
expect(parsedFilter5).toMatchObject(filter5);
|
|
93
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { StructuredQueryOutputParser } from "../index.js";
|
|
3
|
+
import { Comparators, Comparison, Operation, Operators, StructuredQuery, } from "../ir.js";
|
|
4
|
+
const correctQuery = new StructuredQuery("teenager love", new Operation(Operators.and, [
|
|
5
|
+
new Operation(Operators.or, [
|
|
6
|
+
new Comparison(Comparators.eq, "artist", "Taylor Swift"),
|
|
7
|
+
new Comparison(Comparators.eq, "artist", "Katy Perry"),
|
|
8
|
+
]),
|
|
9
|
+
new Comparison(Comparators.lt, "length", 180),
|
|
10
|
+
new Comparison(Comparators.eq, "genre", "pop"),
|
|
11
|
+
]));
|
|
12
|
+
test("StructuredQueryOutputParser test", async () => {
|
|
13
|
+
const queryParser = StructuredQueryOutputParser.fromComponents([
|
|
14
|
+
Comparators.eq,
|
|
15
|
+
Comparators.gte,
|
|
16
|
+
Comparators.gt,
|
|
17
|
+
Comparators.lte,
|
|
18
|
+
Comparators.lt,
|
|
19
|
+
], [Operators.and, Operators.or, Operators.not]);
|
|
20
|
+
const exampleOutput = `json\`\`\`
|
|
21
|
+
{
|
|
22
|
+
"query": "teenager love",
|
|
23
|
+
"filter": "and(or(eq(\\"artist\\", \\"Taylor Swift\\"), eq(\\"artist\\", \\"Katy Perry\\")), lt(\\"length\\", 180), eq(\\"genre\\", \\"pop\\"))"
|
|
24
|
+
}
|
|
25
|
+
\`\`\``;
|
|
26
|
+
const parsedOutput = await queryParser.parse(exampleOutput);
|
|
27
|
+
expect(parsedOutput).toMatchObject(correctQuery);
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { OpenAI } from "@langchain/openai";
|
|
3
|
+
import { Document } from "@langchain/core/documents";
|
|
4
|
+
import { loadQAMapReduceChain, loadQARefineChain, loadQAStuffChain, } from "../load.js";
|
|
5
|
+
test("Test loadQAStuffChain", async () => {
|
|
6
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
7
|
+
const chain = loadQAStuffChain(model);
|
|
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 loadQAMapReduceChain", async () => {
|
|
17
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
18
|
+
const chain = loadQAMapReduceChain(model);
|
|
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 loadQARefineChain", async () => {
|
|
28
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
29
|
+
const chain = loadQARefineChain(model);
|
|
30
|
+
const docs = [
|
|
31
|
+
new Document({ pageContent: "Harrison went to Harvard." }),
|
|
32
|
+
new Document({ pageContent: "Ankush went to Princeton." }),
|
|
33
|
+
];
|
|
34
|
+
const res = await chain.call({
|
|
35
|
+
input_documents: docs,
|
|
36
|
+
question: "Where did Harrison go to college?",
|
|
37
|
+
});
|
|
38
|
+
console.log({ res });
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|