langchain 0.2.2 → 0.2.3
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/sql_utils.cjs +2 -1
- package/dist/util/sql_utils.js +2 -1
- 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 +4 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* eslint-disable no-process-env */
|
|
2
|
+
import { expect, test } from "@jest/globals";
|
|
3
|
+
import { OpenAI, OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";
|
|
4
|
+
import { RunnableSequence } from "@langchain/core/runnables";
|
|
5
|
+
import { OutputParserException } from "@langchain/core/output_parsers";
|
|
6
|
+
import { ChatMessageHistory } from "../../stores/message/in_memory.js";
|
|
7
|
+
import { AgentExecutor, ZeroShotAgent } from "../index.js";
|
|
8
|
+
import { SerpAPI } from "../../util/testing/tools/serpapi.js";
|
|
9
|
+
import { Calculator } from "../../util/testing/tools/calculator.js";
|
|
10
|
+
import { initializeAgentExecutorWithOptions } from "../initialize.js";
|
|
11
|
+
import { WebBrowser } from "../../tools/webbrowser.js";
|
|
12
|
+
import { BufferMemory } from "../../memory/buffer_memory.js";
|
|
13
|
+
test("Pass runnable to agent executor", async () => {
|
|
14
|
+
const model = new ChatOpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" });
|
|
15
|
+
const tools = [
|
|
16
|
+
new SerpAPI(undefined, {
|
|
17
|
+
location: "Austin,Texas,United States",
|
|
18
|
+
hl: "en",
|
|
19
|
+
gl: "us",
|
|
20
|
+
}),
|
|
21
|
+
new Calculator(),
|
|
22
|
+
];
|
|
23
|
+
const prompt = ZeroShotAgent.createPrompt(tools);
|
|
24
|
+
const outputParser = ZeroShotAgent.getDefaultOutputParser();
|
|
25
|
+
const runnable = RunnableSequence.from([
|
|
26
|
+
{
|
|
27
|
+
input: (i) => i.input,
|
|
28
|
+
agent_scratchpad: (i) => i.input,
|
|
29
|
+
},
|
|
30
|
+
prompt,
|
|
31
|
+
model,
|
|
32
|
+
outputParser,
|
|
33
|
+
]);
|
|
34
|
+
const executor = AgentExecutor.fromAgentAndTools({
|
|
35
|
+
agent: runnable,
|
|
36
|
+
tools,
|
|
37
|
+
});
|
|
38
|
+
const res = await executor.invoke({
|
|
39
|
+
input: "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?",
|
|
40
|
+
});
|
|
41
|
+
console.log({
|
|
42
|
+
res,
|
|
43
|
+
}, "Pass runnable to agent executor");
|
|
44
|
+
expect(res.output).not.toEqual("");
|
|
45
|
+
expect(res.output).not.toEqual("Agent stopped due to max iterations.");
|
|
46
|
+
});
|
|
47
|
+
test("Custom output parser", async () => {
|
|
48
|
+
const model = new ChatOpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" });
|
|
49
|
+
const tools = [
|
|
50
|
+
new SerpAPI(undefined, {
|
|
51
|
+
location: "Austin,Texas,United States",
|
|
52
|
+
hl: "en",
|
|
53
|
+
gl: "us",
|
|
54
|
+
}),
|
|
55
|
+
new Calculator(),
|
|
56
|
+
];
|
|
57
|
+
const parser = (output) => {
|
|
58
|
+
const text = output.content;
|
|
59
|
+
if (typeof text !== "string") {
|
|
60
|
+
throw new Error("Cannot parse non-string output.");
|
|
61
|
+
}
|
|
62
|
+
if (text.includes("Final Answer:")) {
|
|
63
|
+
return {
|
|
64
|
+
returnValues: {
|
|
65
|
+
output: "We did it!",
|
|
66
|
+
},
|
|
67
|
+
log: text,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const match = /Action:([\s\S]*?)(?:\nAction Input:([\s\S]*?))?$/.exec(text);
|
|
71
|
+
if (!match) {
|
|
72
|
+
throw new OutputParserException(`Could not parse LLM output: ${text}`);
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
tool: match[1].trim(),
|
|
76
|
+
toolInput: match[2]
|
|
77
|
+
? match[2].trim().replace(/^("+)(.*?)(\1)$/, "$2")
|
|
78
|
+
: "",
|
|
79
|
+
log: text,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const prompt = ZeroShotAgent.createPrompt(tools);
|
|
83
|
+
const runnable = RunnableSequence.from([
|
|
84
|
+
{
|
|
85
|
+
input: (i) => i.input,
|
|
86
|
+
agent_scratchpad: (i) => i.input,
|
|
87
|
+
},
|
|
88
|
+
prompt,
|
|
89
|
+
model,
|
|
90
|
+
parser,
|
|
91
|
+
]);
|
|
92
|
+
const executor = AgentExecutor.fromAgentAndTools({
|
|
93
|
+
agent: runnable,
|
|
94
|
+
tools,
|
|
95
|
+
});
|
|
96
|
+
const res = await executor.invoke({
|
|
97
|
+
input: "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?",
|
|
98
|
+
});
|
|
99
|
+
console.log({
|
|
100
|
+
res,
|
|
101
|
+
}, "Custom output parser");
|
|
102
|
+
expect(res.output).toEqual("We did it!");
|
|
103
|
+
});
|
|
104
|
+
test("Add a fallback method", async () => {
|
|
105
|
+
// Model should always fail since the model name passed does not exist.
|
|
106
|
+
const modelBase = new ChatOpenAI({
|
|
107
|
+
modelName: "fake-model",
|
|
108
|
+
temperature: 10,
|
|
109
|
+
});
|
|
110
|
+
const modelLarge = new ChatOpenAI({
|
|
111
|
+
modelName: "gpt-3.5-turbo-16k",
|
|
112
|
+
temperature: 0.6,
|
|
113
|
+
});
|
|
114
|
+
const model = modelBase.withFallbacks({
|
|
115
|
+
fallbacks: [modelLarge],
|
|
116
|
+
});
|
|
117
|
+
const prompt = ZeroShotAgent.createPrompt([]);
|
|
118
|
+
const outputParser = ZeroShotAgent.getDefaultOutputParser();
|
|
119
|
+
const runnable = RunnableSequence.from([
|
|
120
|
+
{
|
|
121
|
+
input: (i) => i.input,
|
|
122
|
+
agent_scratchpad: (i) => i.input,
|
|
123
|
+
},
|
|
124
|
+
prompt,
|
|
125
|
+
model,
|
|
126
|
+
outputParser,
|
|
127
|
+
]);
|
|
128
|
+
const executor = AgentExecutor.fromAgentAndTools({
|
|
129
|
+
agent: runnable,
|
|
130
|
+
tools: [],
|
|
131
|
+
});
|
|
132
|
+
const res = await executor.invoke({
|
|
133
|
+
input: "Is the sky blue? Response with a concise answer",
|
|
134
|
+
});
|
|
135
|
+
console.log({
|
|
136
|
+
res,
|
|
137
|
+
}, "Pass runnable to agent executor");
|
|
138
|
+
expect(res.output).not.toEqual("");
|
|
139
|
+
expect(res.output).not.toEqual("Agent stopped due to max iterations.");
|
|
140
|
+
});
|
|
141
|
+
test("Run agent with an abort signal", async () => {
|
|
142
|
+
const model = new OpenAI({ temperature: 0, modelName: "text-babbage-001" });
|
|
143
|
+
const tools = [new Calculator()];
|
|
144
|
+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
|
145
|
+
agentType: "zero-shot-react-description",
|
|
146
|
+
});
|
|
147
|
+
console.log("Loaded agent.");
|
|
148
|
+
const input = `What is 3 to the fourth power?`;
|
|
149
|
+
console.log(`Executing with input "${input}"...`);
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
await expect(() => {
|
|
152
|
+
const result = executor.call({ input, signal: controller.signal });
|
|
153
|
+
controller.abort();
|
|
154
|
+
return result;
|
|
155
|
+
}).rejects.toThrow();
|
|
156
|
+
});
|
|
157
|
+
test("Run agent with incorrect api key should throw error", async () => {
|
|
158
|
+
const model = new OpenAI({
|
|
159
|
+
temperature: 0,
|
|
160
|
+
modelName: "text-babbage-001",
|
|
161
|
+
openAIApiKey: "invalid",
|
|
162
|
+
});
|
|
163
|
+
const tools = [
|
|
164
|
+
new SerpAPI(undefined, {
|
|
165
|
+
location: "Austin,Texas,United States",
|
|
166
|
+
hl: "en",
|
|
167
|
+
gl: "us",
|
|
168
|
+
}),
|
|
169
|
+
new Calculator(),
|
|
170
|
+
];
|
|
171
|
+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
|
172
|
+
agentType: "zero-shot-react-description",
|
|
173
|
+
});
|
|
174
|
+
console.log("Loaded agent.");
|
|
175
|
+
const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
|
|
176
|
+
let error;
|
|
177
|
+
// Test that the model throws an error
|
|
178
|
+
await expect(async () => {
|
|
179
|
+
try {
|
|
180
|
+
await model.invoke(input);
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
error = e;
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}).rejects.toThrowError();
|
|
187
|
+
// Test that the agent throws the same error
|
|
188
|
+
await expect(() => executor.call({ input })).rejects.toThrowError(
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
190
|
+
error.message);
|
|
191
|
+
}, 10000);
|
|
192
|
+
test("Run tool web-browser", async () => {
|
|
193
|
+
const model = new OpenAI({ temperature: 0 });
|
|
194
|
+
const tools = [
|
|
195
|
+
new SerpAPI(process.env.SERPAPI_API_KEY, {
|
|
196
|
+
location: "Austin,Texas,United States",
|
|
197
|
+
hl: "en",
|
|
198
|
+
gl: "us",
|
|
199
|
+
}),
|
|
200
|
+
new Calculator(),
|
|
201
|
+
new WebBrowser({ model, embeddings: new OpenAIEmbeddings() }),
|
|
202
|
+
];
|
|
203
|
+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
|
204
|
+
agentType: "zero-shot-react-description",
|
|
205
|
+
returnIntermediateSteps: true,
|
|
206
|
+
});
|
|
207
|
+
console.log("Loaded agent.");
|
|
208
|
+
const input = `What is the word of the day on merriam webster`;
|
|
209
|
+
console.log(`Executing with input "${input}"...`);
|
|
210
|
+
const result = await executor.call({ input });
|
|
211
|
+
console.log({
|
|
212
|
+
result,
|
|
213
|
+
}, "Run tool web-browser");
|
|
214
|
+
expect(result.intermediateSteps.length).toBeGreaterThanOrEqual(1);
|
|
215
|
+
expect(result.intermediateSteps[0].action.tool).toEqual("search");
|
|
216
|
+
expect(result.intermediateSteps[1].action.tool).toEqual("web-browser");
|
|
217
|
+
expect(result.output).not.toEqual("");
|
|
218
|
+
expect(result.output).not.toEqual("Agent stopped due to max iterations.");
|
|
219
|
+
});
|
|
220
|
+
test("Agent can stream", async () => {
|
|
221
|
+
const model = new ChatOpenAI({
|
|
222
|
+
temperature: 0,
|
|
223
|
+
modelName: "gpt-4-1106-preview",
|
|
224
|
+
streaming: true,
|
|
225
|
+
});
|
|
226
|
+
const tools = [
|
|
227
|
+
new Calculator(),
|
|
228
|
+
new WebBrowser({ model, embeddings: new OpenAIEmbeddings() }),
|
|
229
|
+
];
|
|
230
|
+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
|
231
|
+
agentType: "zero-shot-react-description",
|
|
232
|
+
returnIntermediateSteps: false,
|
|
233
|
+
});
|
|
234
|
+
console.log("Loaded agent.");
|
|
235
|
+
const input = `What is the word of the day on merriam webster`;
|
|
236
|
+
console.log(`Executing with input "${input}"...`);
|
|
237
|
+
const result = await executor.stream({ input });
|
|
238
|
+
let streamIters = 0;
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
+
const finalResponse = [];
|
|
241
|
+
for await (const item of result) {
|
|
242
|
+
streamIters += 1;
|
|
243
|
+
console.log("Stream item:", item);
|
|
244
|
+
// each stream does NOT contain the previous steps,
|
|
245
|
+
// because returnIntermediateSteps is false so we
|
|
246
|
+
// push each new stream item to the array.
|
|
247
|
+
finalResponse.push(item);
|
|
248
|
+
}
|
|
249
|
+
// The last item should contain "output"
|
|
250
|
+
expect("output" in finalResponse[finalResponse.length - 1]).toBeTruthy();
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
252
|
+
const intermediateSteps = finalResponse.flatMap((item) => {
|
|
253
|
+
if ("intermediateSteps" in item) {
|
|
254
|
+
return item.intermediateSteps;
|
|
255
|
+
}
|
|
256
|
+
return [];
|
|
257
|
+
});
|
|
258
|
+
expect(streamIters).toBeGreaterThan(1);
|
|
259
|
+
const toolsUsed = intermediateSteps.map((step) => step.action.tool);
|
|
260
|
+
// the last tool used should be the web-browser
|
|
261
|
+
expect(toolsUsed?.[toolsUsed.length - 1]).toEqual("web-browser");
|
|
262
|
+
});
|
|
263
|
+
test("Agent can stream with chat messages", async () => {
|
|
264
|
+
const model = new ChatOpenAI({
|
|
265
|
+
temperature: 0,
|
|
266
|
+
modelName: "gpt-4-1106-preview",
|
|
267
|
+
streaming: true,
|
|
268
|
+
});
|
|
269
|
+
const tools = [
|
|
270
|
+
new Calculator(),
|
|
271
|
+
new WebBrowser({ model, embeddings: new OpenAIEmbeddings() }),
|
|
272
|
+
];
|
|
273
|
+
const memory = new BufferMemory({
|
|
274
|
+
chatHistory: new ChatMessageHistory([]),
|
|
275
|
+
memoryKey: "chat_history",
|
|
276
|
+
inputKey: "input",
|
|
277
|
+
outputKey: "output",
|
|
278
|
+
returnMessages: true,
|
|
279
|
+
});
|
|
280
|
+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
|
281
|
+
agentType: "chat-conversational-react-description",
|
|
282
|
+
returnIntermediateSteps: true,
|
|
283
|
+
memory,
|
|
284
|
+
});
|
|
285
|
+
console.log("Loaded agent.");
|
|
286
|
+
const input = `What is the word of the day on merriam webster, and what is the sum of all letter indices (relative to the english alphabet) in the word?`;
|
|
287
|
+
console.log(`Executing with input "${input}"...`);
|
|
288
|
+
const result = await executor.stream({ input, chat_history: [] });
|
|
289
|
+
let streamIters = 0;
|
|
290
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
|
+
let finalResponse;
|
|
292
|
+
for await (const item of result) {
|
|
293
|
+
streamIters += 1;
|
|
294
|
+
console.log("Stream item:", item);
|
|
295
|
+
// each stream contains the previous steps
|
|
296
|
+
// because returnIntermediateSteps is true),
|
|
297
|
+
// so we can overwrite on each stream.
|
|
298
|
+
finalResponse = item;
|
|
299
|
+
}
|
|
300
|
+
console.log("__finalResponse__", finalResponse);
|
|
301
|
+
expect("intermediateSteps" in finalResponse).toBeTruthy();
|
|
302
|
+
expect("output" in finalResponse).toBeTruthy();
|
|
303
|
+
expect(streamIters).toBeGreaterThan(1);
|
|
304
|
+
const toolsUsed = finalResponse.intermediateSteps.map((step) => step.action.tool);
|
|
305
|
+
// the first tool used should be web-browser, and last should be calculator.
|
|
306
|
+
// This can be flaky so if the test is failing, inspect these conditions first.
|
|
307
|
+
expect(toolsUsed?.[toolsUsed.length - 1]).toEqual("calculator");
|
|
308
|
+
expect(toolsUsed?.[0]).toEqual("web-browser");
|
|
309
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { ChatConversationalAgentOutputParser } from "../chat_convo/outputParser.js";
|
|
3
|
+
test("Can parse JSON with text in front of it", async () => {
|
|
4
|
+
const testCases = [
|
|
5
|
+
{
|
|
6
|
+
input: `Based on the information from the search, I can provide you with a query to get all the orders for the email \`example@gmail.com\`. Here's the query:\n\n\`\`\`sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'example@gmail.com'\n\`\`\`\n\nPlease make any necessary modifications depending on your database schema and table structures. Run this query on your database to retrieve the orders made by the specified user.\n\n\`\`\`json\n{\n "action": "Final Answer",\n "action_input": "To get all the orders for a user with the email \`example@gmail.com\`, you can use the following query:\\n\\n\`\`\`\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = 'example@gmail.com'\\n\`\`\`\\n\\nPlease make any necessary modifications depending on your database schema and table structures. Run this query on your database to retrieve the orders made by the specified user."\n}\n\`\`\``,
|
|
7
|
+
output: `{\n "action": "Final Answer",\n "action_input": "To get all the orders for a user with the email \`example@gmail.com\`, you can use the following query:\\n\\n\`\`\`\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = 'example@gmail.com'\\n\`\`\`\\n\\nPlease make any necessary modifications depending on your database schema and table structures. Run this query on your database to retrieve the made by the specifsredroied user."\n}`,
|
|
8
|
+
tool: "Final Answer",
|
|
9
|
+
toolInput: "To get all the orders for a user with the email ",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
input: 'Here is an example of a valid JSON object matching the provided spec:\n\n```json\n{\n "action": "metabase",\n "action_input": ["GET", "/api/table/1"]\n}\n```\n\nIn this example, the "action" key has a string value of "metabase", and the "action_input" key has an array value containing two elements: a string value of "GET" and a string value of "/api/table/1". This JSON object could be used to make a request to a Metabase API endpoint with the specified method and arguments.',
|
|
13
|
+
output: `{ "action": "metabase", "action_input": ["GET", "/api/table/1"] } `,
|
|
14
|
+
tool: "metabase",
|
|
15
|
+
toolInput: ["GET", "/api/table/1"],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
input: '```\n{\n "action": "metabase",\n "action_input": ["GET", "/api/table/1"]\n}\n```',
|
|
19
|
+
output: `{ "action": "metabase", "action_input": ["GET", "/api/table/1"] } `,
|
|
20
|
+
tool: "metabase",
|
|
21
|
+
toolInput: ["GET", "/api/table/1"],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
input: 'Here we have some boilerplate nonsense```\n{\n "action": "blogpost",\n "action_input": "```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"\n}\n``` and at the end there is more nonsense',
|
|
25
|
+
output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
|
|
26
|
+
tool: "blogpost",
|
|
27
|
+
toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
input: 'Here we have some boilerplate nonsense```json\n{\n \t\r\n"action": "blogpost",\n\t\r "action_input": "```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"\n\t\r}\n\n\n\t\r``` and at the end there is more nonsense',
|
|
31
|
+
output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
|
|
32
|
+
tool: "blogpost",
|
|
33
|
+
toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
input: '{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"\n\t\r}',
|
|
37
|
+
output: '{"action":"Final Answer","action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"}',
|
|
38
|
+
tool: "Final Answer",
|
|
39
|
+
toolInput: 'The tool input ```json\\n{\\"yes\\":true}\\n```',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
input: '```json\n{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"\n\t\r}\n\n\n\t\r```',
|
|
43
|
+
output: '{"action":"Final Answer","action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"}',
|
|
44
|
+
tool: "Final Answer",
|
|
45
|
+
toolInput: 'The tool input ```json\\n{\\"yes\\":true}\\n```',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
input: 'Here we have some boilerplate nonsense```json\n{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"\n\t\r}\n\n\n\t\r``` and at the end there is more nonsense',
|
|
49
|
+
output: '{"action":"Final Answer","action_input":"The tool input ```json\\n{\\"yes\\":true}\\n```"}',
|
|
50
|
+
tool: "Final Answer",
|
|
51
|
+
toolInput: 'The tool input ```json\\n{\\"yes\\":true}\\n```',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
input: 'Here we have some boilerplate nonsense```\n{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"The tool input ```javascript\\n{\\"yes\\":true}\\n```"\n\t\r}\n\n\n\t\r``` and at the end there is more nonsense',
|
|
55
|
+
output: '{"action":"Final Answer","action_input":"The tool input ```javascript\\n{\\"yes\\":true}\\n```"}',
|
|
56
|
+
tool: "Final Answer",
|
|
57
|
+
toolInput: 'The tool input ```javascript\\n{\\"yes\\":true}\\n```',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
input: '{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"The tool input ```javascript\\n{\\"yes\\":true}\\n```"\n\t\r}',
|
|
61
|
+
output: '{"action":"Final Answer","action_input":"The tool input ```javascript\\n{\\"yes\\":true}\\n```"}',
|
|
62
|
+
tool: "Final Answer",
|
|
63
|
+
toolInput: 'The tool input ```javascript\\n{\\"yes\\":true}\\n```',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
input: '{\n \t\r\n"action":"Final Answer",\n\t\r "action_input":"this is a regular text response"\n\t\r}',
|
|
67
|
+
output: '{"action":"Final Answer","action_input":"this is a regular text response"}',
|
|
68
|
+
tool: "Final Answer",
|
|
69
|
+
toolInput: "this is a regular text response",
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const p = new ChatConversationalAgentOutputParser({
|
|
73
|
+
toolNames: ["blogpost", "metabase", "ToolWithJson"],
|
|
74
|
+
});
|
|
75
|
+
for (const message of testCases) {
|
|
76
|
+
const parsed = await p.parse(message.input);
|
|
77
|
+
expect(parsed).toBeDefined();
|
|
78
|
+
if (message.tool === "Final Answer") {
|
|
79
|
+
expect(parsed.returnValues).toBeDefined();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
expect(parsed.tool).toEqual(message.tool);
|
|
83
|
+
if (typeof message.toolInput === "object") {
|
|
84
|
+
expect(message.toolInput).toEqual(parsed.toolInput);
|
|
85
|
+
}
|
|
86
|
+
if (typeof message.toolInput === "string") {
|
|
87
|
+
expect(message.toolInput).toContain(parsed.toolInput);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
import { test, expect } from "@jest/globals";
|
|
3
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
+
import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
|
|
5
|
+
import { pull } from "../../hub.js";
|
|
6
|
+
import { AgentExecutor, createOpenAIFunctionsAgent } from "../index.js";
|
|
7
|
+
const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
8
|
+
test("createOpenAIFunctionsAgent works", async () => {
|
|
9
|
+
const prompt = await pull("hwchase17/openai-functions-agent");
|
|
10
|
+
const llm = new ChatOpenAI({
|
|
11
|
+
modelName: "gpt-3.5-turbo-1106",
|
|
12
|
+
temperature: 0,
|
|
13
|
+
});
|
|
14
|
+
const agent = await createOpenAIFunctionsAgent({
|
|
15
|
+
llm,
|
|
16
|
+
tools,
|
|
17
|
+
prompt,
|
|
18
|
+
});
|
|
19
|
+
const agentExecutor = new AgentExecutor({
|
|
20
|
+
agent,
|
|
21
|
+
tools,
|
|
22
|
+
});
|
|
23
|
+
const input = "what is LangChain?";
|
|
24
|
+
const result = await agentExecutor.invoke({
|
|
25
|
+
input,
|
|
26
|
+
});
|
|
27
|
+
console.log(result);
|
|
28
|
+
expect(result.input).toBe(input);
|
|
29
|
+
expect(typeof result.output).toBe("string");
|
|
30
|
+
// Length greater than 10 because any less than that would warrant
|
|
31
|
+
// an investigation into why such a short generation was returned.
|
|
32
|
+
expect(result.output.length).toBeGreaterThan(10);
|
|
33
|
+
});
|
|
34
|
+
test("createOpenAIFunctionsAgent can stream log", async () => {
|
|
35
|
+
const prompt = await pull("hwchase17/openai-functions-agent");
|
|
36
|
+
const llm = new ChatOpenAI({
|
|
37
|
+
modelName: "gpt-3.5-turbo-1106",
|
|
38
|
+
temperature: 0,
|
|
39
|
+
streaming: true,
|
|
40
|
+
});
|
|
41
|
+
const agent = await createOpenAIFunctionsAgent({
|
|
42
|
+
llm,
|
|
43
|
+
tools,
|
|
44
|
+
prompt,
|
|
45
|
+
});
|
|
46
|
+
const agentExecutor = new AgentExecutor({
|
|
47
|
+
agent,
|
|
48
|
+
tools,
|
|
49
|
+
});
|
|
50
|
+
const input = "tell me a short story.";
|
|
51
|
+
const logStream = await agentExecutor.streamLog({
|
|
52
|
+
input,
|
|
53
|
+
});
|
|
54
|
+
const chunks = [];
|
|
55
|
+
let firstChunkTime;
|
|
56
|
+
for await (const chunk of logStream) {
|
|
57
|
+
if (!firstChunkTime) {
|
|
58
|
+
firstChunkTime = new Date().getTime();
|
|
59
|
+
}
|
|
60
|
+
console.log(chunk);
|
|
61
|
+
chunks.push(chunk);
|
|
62
|
+
}
|
|
63
|
+
if (!firstChunkTime) {
|
|
64
|
+
throw new Error("firstChunkTime was not set.");
|
|
65
|
+
}
|
|
66
|
+
console.log(chunks.length);
|
|
67
|
+
console.log();
|
|
68
|
+
console.log("Time to complete after first chunk:", new Date().getTime() - firstChunkTime);
|
|
69
|
+
console.log(chunks.length);
|
|
70
|
+
expect(chunks.length).toBeGreaterThan(1);
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { RunnableLambda } from "@langchain/core/runnables";
|
|
4
|
+
import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
|
|
5
|
+
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
6
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
7
|
+
import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
|
|
8
|
+
import { pull } from "../../hub.js";
|
|
9
|
+
import { AgentExecutor, createOpenAIToolsAgent } from "../index.js";
|
|
10
|
+
const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
11
|
+
test("createOpenAIToolsAgent works", async () => {
|
|
12
|
+
const prompt = await pull("hwchase17/openai-tools-agent");
|
|
13
|
+
const llm = new ChatOpenAI({
|
|
14
|
+
modelName: "gpt-3.5-turbo-1106",
|
|
15
|
+
temperature: 0,
|
|
16
|
+
});
|
|
17
|
+
const agent = await createOpenAIToolsAgent({
|
|
18
|
+
llm,
|
|
19
|
+
tools,
|
|
20
|
+
prompt,
|
|
21
|
+
});
|
|
22
|
+
const agentExecutor = new AgentExecutor({
|
|
23
|
+
agent,
|
|
24
|
+
tools,
|
|
25
|
+
});
|
|
26
|
+
const input = "what is LangChain?";
|
|
27
|
+
const result = await agentExecutor.invoke({
|
|
28
|
+
input,
|
|
29
|
+
});
|
|
30
|
+
console.log(result);
|
|
31
|
+
expect(result.input).toBe(input);
|
|
32
|
+
expect(typeof result.output).toBe("string");
|
|
33
|
+
// Length greater than 10 because any less than that would warrant
|
|
34
|
+
// an investigation into why such a short generation was returned.
|
|
35
|
+
expect(result.output.length).toBeGreaterThan(10);
|
|
36
|
+
});
|
|
37
|
+
test.skip("createOpenAIToolsAgent tracing works when it is nested in a lambda", async () => {
|
|
38
|
+
AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new AsyncLocalStorage());
|
|
39
|
+
const prompt = await pull("hwchase17/openai-tools-agent");
|
|
40
|
+
const llm = new ChatOpenAI({
|
|
41
|
+
modelName: "gpt-3.5-turbo-1106",
|
|
42
|
+
temperature: 0,
|
|
43
|
+
});
|
|
44
|
+
const agent = await createOpenAIToolsAgent({
|
|
45
|
+
llm,
|
|
46
|
+
tools,
|
|
47
|
+
prompt,
|
|
48
|
+
});
|
|
49
|
+
const agentExecutor = new AgentExecutor({
|
|
50
|
+
agent,
|
|
51
|
+
tools,
|
|
52
|
+
});
|
|
53
|
+
const outer = RunnableLambda.from(async (input) => {
|
|
54
|
+
const noop = RunnableLambda.from(() => "hi").withConfig({
|
|
55
|
+
runName: "nested_testing",
|
|
56
|
+
});
|
|
57
|
+
const noopRes = await noop.invoke({ nested: "nested" });
|
|
58
|
+
console.log(noopRes);
|
|
59
|
+
const res = await agentExecutor.invoke({
|
|
60
|
+
input,
|
|
61
|
+
});
|
|
62
|
+
return res;
|
|
63
|
+
});
|
|
64
|
+
const input = "what is LangChain?";
|
|
65
|
+
const result = await outer.invoke(input, {
|
|
66
|
+
tags: ["test"],
|
|
67
|
+
callbacks: [new LangChainTracer({ projectName: "langchainjs-tracing-2" })],
|
|
68
|
+
});
|
|
69
|
+
console.log(result);
|
|
70
|
+
expect(result.input).toBe(input);
|
|
71
|
+
expect(typeof result.output).toBe("string");
|
|
72
|
+
// Length greater than 10 because any less than that would warrant
|
|
73
|
+
// an investigation into why such a short generation was returned.
|
|
74
|
+
expect(result.output.length).toBeGreaterThan(10);
|
|
75
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { OpenAI } from "@langchain/openai";
|
|
3
|
+
import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
|
|
4
|
+
import { pull } from "../../hub.js";
|
|
5
|
+
import { AgentExecutor, createReactAgent } from "../index.js";
|
|
6
|
+
const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
7
|
+
test("createReactAgent works", async () => {
|
|
8
|
+
const prompt = await pull("hwchase17/react");
|
|
9
|
+
const llm = new OpenAI({
|
|
10
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
11
|
+
temperature: 0,
|
|
12
|
+
});
|
|
13
|
+
const agent = await createReactAgent({
|
|
14
|
+
llm,
|
|
15
|
+
tools,
|
|
16
|
+
prompt,
|
|
17
|
+
});
|
|
18
|
+
const agentExecutor = new AgentExecutor({
|
|
19
|
+
agent,
|
|
20
|
+
tools,
|
|
21
|
+
});
|
|
22
|
+
const input = "what is LangChain?";
|
|
23
|
+
const result = await agentExecutor.invoke({
|
|
24
|
+
input,
|
|
25
|
+
});
|
|
26
|
+
console.log(result);
|
|
27
|
+
expect(result.input).toBe(input);
|
|
28
|
+
expect(typeof result.output).toBe("string");
|
|
29
|
+
// Length greater than 10 because any less than that would warrant
|
|
30
|
+
// an investigation into why such a short generation was returned.
|
|
31
|
+
expect(result.output.length).toBeGreaterThan(10);
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
|
|
4
|
+
import { pull } from "../../hub.js";
|
|
5
|
+
import { AgentExecutor, createStructuredChatAgent } from "../index.js";
|
|
6
|
+
const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
7
|
+
test("createStructuredChatAgent works", async () => {
|
|
8
|
+
const prompt = await pull("hwchase17/structured-chat-agent");
|
|
9
|
+
const llm = new ChatOpenAI({
|
|
10
|
+
modelName: "gpt-3.5-turbo-1106",
|
|
11
|
+
temperature: 0,
|
|
12
|
+
});
|
|
13
|
+
const agent = await createStructuredChatAgent({
|
|
14
|
+
llm,
|
|
15
|
+
tools,
|
|
16
|
+
prompt,
|
|
17
|
+
});
|
|
18
|
+
const agentExecutor = new AgentExecutor({
|
|
19
|
+
agent,
|
|
20
|
+
tools,
|
|
21
|
+
});
|
|
22
|
+
const input = "what is LangChain?";
|
|
23
|
+
const result = await agentExecutor.invoke({
|
|
24
|
+
input,
|
|
25
|
+
});
|
|
26
|
+
console.log(result);
|
|
27
|
+
expect(result.input).toBe(input);
|
|
28
|
+
expect(typeof result.output).toBe("string");
|
|
29
|
+
// Length greater than 10 because any less than that would warrant
|
|
30
|
+
// an investigation into why such a short generation was returned.
|
|
31
|
+
expect(result.output.length).toBeGreaterThan(10);
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|