langchain 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat_models/universal.cjs +1 -0
- package/chat_models/universal.d.cts +1 -0
- package/chat_models/universal.d.ts +1 -0
- package/chat_models/universal.js +1 -0
- package/dist/chat_models/universal.cjs +600 -0
- package/dist/chat_models/universal.d.ts +115 -0
- package/dist/chat_models/universal.js +595 -0
- package/dist/document_loaders/web/assemblyai.cjs +9 -1
- package/dist/document_loaders/web/assemblyai.js +9 -1
- package/dist/experimental/chrome_ai/app/dist/bundle.cjs +1250 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +1 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.js +1249 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/package.json +65 -6
- package/dist/agents/tests/agent.int.test.d.ts +0 -1
- package/dist/agents/tests/agent.int.test.js +0 -309
- package/dist/agents/tests/chat_convo_output_parser.test.d.ts +0 -1
- package/dist/agents/tests/chat_convo_output_parser.test.js +0 -91
- package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +0 -2
- package/dist/agents/tests/create_openai_functions_agent.int.test.js +0 -71
- package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_openai_tools_agent.int.test.js +0 -75
- package/dist/agents/tests/create_react_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_react_agent.int.test.js +0 -32
- package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_structured_chat_agent.int.test.js +0 -32
- package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_tool_calling_agent.int.test.js +0 -122
- package/dist/agents/tests/create_xml_agent.int.test.d.ts +0 -1
- package/dist/agents/tests/create_xml_agent.int.test.js +0 -32
- package/dist/agents/tests/json.test.d.ts +0 -1
- package/dist/agents/tests/json.test.js +0 -74
- package/dist/agents/tests/react.test.d.ts +0 -1
- package/dist/agents/tests/react.test.js +0 -44
- package/dist/agents/tests/runnable.int.test.d.ts +0 -1
- package/dist/agents/tests/runnable.int.test.js +0 -104
- package/dist/agents/tests/sql.test.d.ts +0 -1
- package/dist/agents/tests/sql.test.js +0 -133
- package/dist/agents/tests/structured_chat_output_parser.test.d.ts +0 -1
- package/dist/agents/tests/structured_chat_output_parser.test.js +0 -35
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +0 -1
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +0 -44
- package/dist/agents/tests/structured_output_runnables.int.test.d.ts +0 -1
- package/dist/agents/tests/structured_output_runnables.int.test.js +0 -112
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +0 -1
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +0 -41
- package/dist/cache/tests/file_system.int.test.d.ts +0 -1
- package/dist/cache/tests/file_system.int.test.js +0 -32
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +0 -139
- package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/extraction.int.test.js +0 -33
- package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/openapi.int.test.js +0 -130
- package/dist/chains/openai_functions/tests/openapi.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/openapi.test.js +0 -172
- package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/structured_output.int.test.js +0 -40
- package/dist/chains/openai_functions/tests/structured_output.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/structured_output.test.js +0 -102
- package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +0 -1
- package/dist/chains/openai_functions/tests/tagging.int.test.js +0 -21
- package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +0 -1
- package/dist/chains/query_constructor/tests/query_chain.int.test.js +0 -93
- package/dist/chains/query_constructor/tests/query_parser.test.d.ts +0 -1
- package/dist/chains/query_constructor/tests/query_parser.test.js +0 -28
- package/dist/chains/question_answering/tests/load.int.test.d.ts +0 -1
- package/dist/chains/question_answering/tests/load.int.test.js +0 -39
- package/dist/chains/router/tests/multi_prompt.int.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_prompt.int.test.js +0 -45
- package/dist/chains/router/tests/multi_prompt.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_prompt.test.js +0 -62
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +0 -67
- package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +0 -1
- package/dist/chains/router/tests/multi_retrieval_qa.test.js +0 -125
- package/dist/chains/summarization/tests/load.int.test.d.ts +0 -1
- package/dist/chains/summarization/tests/load.int.test.js +0 -37
- package/dist/chains/tests/api_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/api_chain.int.test.js +0 -55
- package/dist/chains/tests/combine_docs_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/combine_docs_chain.int.test.js +0 -50
- package/dist/chains/tests/combine_docs_chain.test.d.ts +0 -1
- package/dist/chains/tests/combine_docs_chain.test.js +0 -98
- package/dist/chains/tests/constitutional_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/constitutional_chain.int.test.js +0 -30
- package/dist/chains/tests/constitutional_chain.test.d.ts +0 -1
- package/dist/chains/tests/constitutional_chain.test.js +0 -63
- package/dist/chains/tests/conversation_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/conversation_chain.int.test.js +0 -9
- package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/conversational_retrieval_chain.int.test.js +0 -243
- package/dist/chains/tests/example_data/open_meteo_docs.d.ts +0 -1
- package/dist/chains/tests/example_data/open_meteo_docs.js +0 -29
- package/dist/chains/tests/history_aware_retriever.int.test.d.ts +0 -1
- package/dist/chains/tests/history_aware_retriever.int.test.js +0 -41
- package/dist/chains/tests/history_aware_retriever.test.d.ts +0 -1
- package/dist/chains/tests/history_aware_retriever.test.js +0 -27
- package/dist/chains/tests/llm_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/llm_chain.int.test.js +0 -119
- package/dist/chains/tests/openai_moderation.int.test.d.ts +0 -1
- package/dist/chains/tests/openai_moderation.int.test.js +0 -30
- package/dist/chains/tests/retrieval_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/retrieval_chain.int.test.js +0 -69
- package/dist/chains/tests/retrieval_chain.test.d.ts +0 -1
- package/dist/chains/tests/retrieval_chain.test.js +0 -36
- package/dist/chains/tests/sequential_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/sequential_chain.int.test.js +0 -88
- package/dist/chains/tests/sequential_chain.test.d.ts +0 -1
- package/dist/chains/tests/sequential_chain.test.js +0 -295
- package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/simple_sequential_chain.int.test.js +0 -81
- package/dist/chains/tests/simple_sequential_chain.test.d.ts +0 -1
- package/dist/chains/tests/simple_sequential_chain.test.js +0 -128
- package/dist/chains/tests/sql_db_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/sql_db_chain.int.test.js +0 -125
- package/dist/chains/tests/transform.test.d.ts +0 -1
- package/dist/chains/tests/transform.test.js +0 -12
- package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +0 -1
- package/dist/chains/tests/vector_db_qa_chain.int.test.js +0 -45
- package/dist/document_loaders/tests/assemblyai.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/assemblyai.int.test.js +0 -111
- package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/chatgpt-blob.test.js +0 -30
- package/dist/document_loaders/tests/chatgpt.test.d.ts +0 -1
- package/dist/document_loaders/tests/chatgpt.test.js +0 -29
- package/dist/document_loaders/tests/cheerio.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/cheerio.int.test.js +0 -21
- package/dist/document_loaders/tests/college_confidential.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/college_confidential.int.test.js +0 -6
- package/dist/document_loaders/tests/confluence.test.d.ts +0 -1
- package/dist/document_loaders/tests/confluence.test.js +0 -52
- package/dist/document_loaders/tests/couchbase.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/couchbase.int.test.js +0 -28
- package/dist/document_loaders/tests/csv-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/csv-blob.test.js +0 -53
- package/dist/document_loaders/tests/csv.test.d.ts +0 -1
- package/dist/document_loaders/tests/csv.test.js +0 -41
- package/dist/document_loaders/tests/directory.test.d.ts +0 -1
- package/dist/document_loaders/tests/directory.test.js +0 -38
- package/dist/document_loaders/tests/docx.test.d.ts +0 -1
- package/dist/document_loaders/tests/docx.test.js +0 -11
- package/dist/document_loaders/tests/epub.test.d.ts +0 -1
- package/dist/document_loaders/tests/epub.test.js +0 -18
- package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +0 -5
- package/dist/document_loaders/tests/example_data/github_api_responses.js +0 -91
- package/dist/document_loaders/tests/figma.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/figma.int.test.js +0 -13
- package/dist/document_loaders/tests/firecrawl.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/firecrawl.int.test.js +0 -30
- package/dist/document_loaders/tests/gitbook.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/gitbook.int.test.js +0 -14
- package/dist/document_loaders/tests/github.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/github.int.test.js +0 -86
- package/dist/document_loaders/tests/github.test.d.ts +0 -1
- package/dist/document_loaders/tests/github.test.js +0 -51
- package/dist/document_loaders/tests/hn.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/hn.int.test.js +0 -6
- package/dist/document_loaders/tests/imsdb.test.d.ts +0 -1
- package/dist/document_loaders/tests/imsdb.test.js +0 -6
- package/dist/document_loaders/tests/json-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/json-blob.test.js +0 -91
- package/dist/document_loaders/tests/json.test.d.ts +0 -1
- package/dist/document_loaders/tests/json.test.js +0 -69
- package/dist/document_loaders/tests/jsonl-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/jsonl-blob.test.js +0 -46
- package/dist/document_loaders/tests/jsonl.test.d.ts +0 -1
- package/dist/document_loaders/tests/jsonl.test.js +0 -15
- package/dist/document_loaders/tests/multi_file.test.d.ts +0 -1
- package/dist/document_loaders/tests/multi_file.test.js +0 -49
- package/dist/document_loaders/tests/notion.test.d.ts +0 -1
- package/dist/document_loaders/tests/notion.test.js +0 -11
- package/dist/document_loaders/tests/notionapi.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/notionapi.int.test.js +0 -80
- package/dist/document_loaders/tests/notionapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/notionapi.test.js +0 -84
- package/dist/document_loaders/tests/notiondb.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/notiondb.int.test.js +0 -13
- package/dist/document_loaders/tests/obsidian.test.d.ts +0 -1
- package/dist/document_loaders/tests/obsidian.test.js +0 -119
- package/dist/document_loaders/tests/pdf-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/pdf-blob.test.js +0 -44
- package/dist/document_loaders/tests/pdf.test.d.ts +0 -1
- package/dist/document_loaders/tests/pdf.test.js +0 -25
- package/dist/document_loaders/tests/playwright_web.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/playwright_web.int.test.js +0 -27
- package/dist/document_loaders/tests/pptx.test.d.ts +0 -1
- package/dist/document_loaders/tests/pptx.test.js +0 -17
- package/dist/document_loaders/tests/puppeteer.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/puppeteer.int.test.js +0 -47
- package/dist/document_loaders/tests/recursive_url.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/recursive_url.int.test.js +0 -64
- package/dist/document_loaders/tests/s3.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/s3.int.test.js +0 -48
- package/dist/document_loaders/tests/searchapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/searchapi.test.js +0 -29
- package/dist/document_loaders/tests/serpapi.test.d.ts +0 -1
- package/dist/document_loaders/tests/serpapi.test.js +0 -21
- package/dist/document_loaders/tests/sitemap.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sitemap.int.test.js +0 -28
- package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sonix_audio.int.test.js +0 -55
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +0 -38
- package/dist/document_loaders/tests/srt-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/srt-blob.test.js +0 -18
- package/dist/document_loaders/tests/srt.test.d.ts +0 -1
- package/dist/document_loaders/tests/srt.test.js +0 -16
- package/dist/document_loaders/tests/text-blob.test.d.ts +0 -1
- package/dist/document_loaders/tests/text-blob.test.js +0 -14
- package/dist/document_loaders/tests/text.test.d.ts +0 -1
- package/dist/document_loaders/tests/text.test.js +0 -22
- package/dist/document_loaders/tests/unstructured.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/unstructured.int.test.js +0 -58
- package/dist/document_loaders/tests/webpdf.int.test.d.ts +0 -1
- package/dist/document_loaders/tests/webpdf.int.test.js +0 -90
- package/dist/document_transformers/tests/openai_functions.int.test.d.ts +0 -1
- package/dist/document_transformers/tests/openai_functions.int.test.js +0 -40
- package/dist/embeddings/tests/cache.test.d.ts +0 -1
- package/dist/embeddings/tests/cache.test.js +0 -24
- package/dist/embeddings/tests/fake.test.d.ts +0 -1
- package/dist/embeddings/tests/fake.test.js +0 -34
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +0 -33
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +0 -46
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +0 -108
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +0 -26
- package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +0 -1
- package/dist/evaluation/qa/tests/eval_chain.int.test.js +0 -27
- package/dist/experimental/autogpt/tests/output_parser.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/output_parser.test.js +0 -8
- package/dist/experimental/autogpt/tests/prompt.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/prompt.test.js +0 -69
- package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +0 -1
- package/dist/experimental/autogpt/tests/prompt_generator.test.js +0 -91
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +0 -1
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +0 -26
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +0 -1
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +0 -304
- package/dist/experimental/masking/tests/masking-extended.test.d.ts +0 -1
- package/dist/experimental/masking/tests/masking-extended.test.js +0 -58
- package/dist/experimental/masking/tests/masking.test.d.ts +0 -1
- package/dist/experimental/masking/tests/masking.test.js +0 -388
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +0 -1
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +0 -203
- package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +0 -1
- package/dist/experimental/openai_files/tests/openai_file.int.test.js +0 -87
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +0 -1
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +0 -54
- package/dist/experimental/prompts/tests/handlebars.test.d.ts +0 -1
- package/dist/experimental/prompts/tests/handlebars.test.js +0 -24
- package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +0 -1
- package/dist/experimental/tools/tests/pyinterpreter.int.test.js +0 -22
- package/dist/load/tests/cross_language.test.d.ts +0 -1
- package/dist/load/tests/cross_language.test.js +0 -83
- package/dist/load/tests/load.int.test.d.ts +0 -1
- package/dist/load/tests/load.int.test.js +0 -9
- package/dist/load/tests/load.test.d.ts +0 -1
- package/dist/load/tests/load.test.js +0 -412
- package/dist/memory/tests/buffer_memory.test.d.ts +0 -1
- package/dist/memory/tests/buffer_memory.test.js +0 -34
- package/dist/memory/tests/buffer_token_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/buffer_token_memory.int.test.js +0 -47
- package/dist/memory/tests/buffer_window_memory.test.d.ts +0 -1
- package/dist/memory/tests/buffer_window_memory.test.js +0 -42
- package/dist/memory/tests/combined_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/combined_memory.int.test.js +0 -74
- package/dist/memory/tests/entity_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/entity_memory.int.test.js +0 -79
- package/dist/memory/tests/entity_memory.test.d.ts +0 -1
- package/dist/memory/tests/entity_memory.test.js +0 -48
- package/dist/memory/tests/summary.int.test.d.ts +0 -1
- package/dist/memory/tests/summary.int.test.js +0 -50
- package/dist/memory/tests/summary_buffer.int.test.d.ts +0 -1
- package/dist/memory/tests/summary_buffer.int.test.js +0 -55
- package/dist/memory/tests/vector_store_memory.int.test.d.ts +0 -1
- package/dist/memory/tests/vector_store_memory.int.test.js +0 -55
- package/dist/output_parsers/tests/combining.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/combining.int.test.js +0 -26
- package/dist/output_parsers/tests/combining.test.d.ts +0 -1
- package/dist/output_parsers/tests/combining.test.js +0 -54
- package/dist/output_parsers/tests/datetime.test.d.ts +0 -1
- package/dist/output_parsers/tests/datetime.test.js +0 -14
- package/dist/output_parsers/tests/expression.test.d.ts +0 -1
- package/dist/output_parsers/tests/expression.test.js +0 -339
- package/dist/output_parsers/tests/http_response.test.d.ts +0 -1
- package/dist/output_parsers/tests/http_response.test.js +0 -39
- package/dist/output_parsers/tests/list.test.d.ts +0 -1
- package/dist/output_parsers/tests/list.test.js +0 -27
- package/dist/output_parsers/tests/openai_functions.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/openai_functions.int.test.js +0 -89
- package/dist/output_parsers/tests/openai_tools.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/openai_tools.int.test.js +0 -36
- package/dist/output_parsers/tests/structured.int.test.d.ts +0 -1
- package/dist/output_parsers/tests/structured.int.test.js +0 -150
- package/dist/prompts/tests/selectors.test.d.ts +0 -1
- package/dist/prompts/tests/selectors.test.js +0 -59
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +0 -1
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +0 -330
- package/dist/retrievers/tests/chain_extract.int.test.d.ts +0 -1
- package/dist/retrievers/tests/chain_extract.int.test.js +0 -32
- package/dist/retrievers/tests/ensemble_retriever.int.test.d.ts +0 -1
- package/dist/retrievers/tests/ensemble_retriever.int.test.js +0 -74
- package/dist/retrievers/tests/hyde.int.test.d.ts +0 -1
- package/dist/retrievers/tests/hyde.int.test.js +0 -44
- package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +0 -1
- package/dist/retrievers/tests/matryoshka_retriever.int.test.js +0 -113
- package/dist/retrievers/tests/multi_query.int.test.d.ts +0 -1
- package/dist/retrievers/tests/multi_query.int.test.js +0 -45
- package/dist/retrievers/tests/parent_document.int.test.d.ts +0 -1
- package/dist/retrievers/tests/parent_document.int.test.js +0 -122
- package/dist/retrievers/tests/score_threshold.int.test.d.ts +0 -1
- package/dist/retrievers/tests/score_threshold.int.test.js +0 -83
- package/dist/retrievers/tests/time_weighted.test.d.ts +0 -1
- package/dist/retrievers/tests/time_weighted.test.js +0 -320
- package/dist/retrievers/tests/vectorstores.test.d.ts +0 -1
- package/dist/retrievers/tests/vectorstores.test.js +0 -50
- package/dist/smith/tests/run_on_dataset.int.test.d.ts +0 -1
- package/dist/smith/tests/run_on_dataset.int.test.js +0 -257
- package/dist/smith/tests/runner_utils.int.test.d.ts +0 -9
- package/dist/smith/tests/runner_utils.int.test.js +0 -234
- package/dist/storage/tests/file_system.test.d.ts +0 -1
- package/dist/storage/tests/file_system.test.js +0 -81
- package/dist/tools/tests/chain.test.d.ts +0 -1
- package/dist/tools/tests/chain.test.js +0 -136
- package/dist/tools/tests/webbrowser.int.test.d.ts +0 -1
- package/dist/tools/tests/webbrowser.int.test.js +0 -80
- package/dist/tools/tests/webbrowser.test.d.ts +0 -1
- package/dist/tools/tests/webbrowser.test.js +0 -21
- package/dist/util/tests/async_caller.int.test.d.ts +0 -1
- package/dist/util/tests/async_caller.int.test.js +0 -34
- package/dist/util/tests/azure.test.d.ts +0 -1
- package/dist/util/tests/azure.test.js +0 -42
- package/dist/util/tests/openai-stream.test.d.ts +0 -1
- package/dist/util/tests/openai-stream.test.js +0 -135
- package/dist/util/tests/set.test.d.ts +0 -1
- package/dist/util/tests/set.test.js +0 -36
- package/dist/util/tests/sql_utils.test.d.ts +0 -1
- package/dist/util/tests/sql_utils.test.js +0 -50
- package/dist/vectorstores/tests/memory.test.d.ts +0 -1
- package/dist/vectorstores/tests/memory.test.js +0 -78
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-process-env */
|
|
2
|
-
import { test, expect, beforeEach, afterEach } from "@jest/globals";
|
|
3
|
-
import { DataSource } from "typeorm";
|
|
4
|
-
import { InfoSqlTool, QuerySqlTool, ListTablesSqlTool, QueryCheckerTool, } from "../../tools/sql.js";
|
|
5
|
-
import { SqlDatabase } from "../../sql_db.js";
|
|
6
|
-
const previousEnv = process.env;
|
|
7
|
-
let db;
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
const datasource = new DataSource({
|
|
10
|
-
type: "sqlite",
|
|
11
|
-
database: ":memory:",
|
|
12
|
-
synchronize: true,
|
|
13
|
-
});
|
|
14
|
-
await datasource.initialize();
|
|
15
|
-
await datasource.query(`
|
|
16
|
-
CREATE TABLE products (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, price INTEGER);
|
|
17
|
-
`);
|
|
18
|
-
await datasource.query(`
|
|
19
|
-
INSERT INTO products (name, price) VALUES ('Apple', 100);
|
|
20
|
-
`);
|
|
21
|
-
await datasource.query(`
|
|
22
|
-
INSERT INTO products (name, price) VALUES ('Banana', 200);
|
|
23
|
-
`);
|
|
24
|
-
await datasource.query(`
|
|
25
|
-
INSERT INTO products (name, price) VALUES ('Orange', 300);
|
|
26
|
-
`);
|
|
27
|
-
await datasource.query(`
|
|
28
|
-
CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER);
|
|
29
|
-
`);
|
|
30
|
-
await datasource.query(`
|
|
31
|
-
INSERT INTO users (name, age) VALUES ('Alice', 20);
|
|
32
|
-
`);
|
|
33
|
-
await datasource.query(`
|
|
34
|
-
INSERT INTO users (name, age) VALUES ('Bob', 21);
|
|
35
|
-
`);
|
|
36
|
-
await datasource.query(`
|
|
37
|
-
INSERT INTO users (name, age) VALUES ('Charlie', 22);
|
|
38
|
-
`);
|
|
39
|
-
db = await SqlDatabase.fromDataSourceParams({
|
|
40
|
-
appDataSource: datasource,
|
|
41
|
-
});
|
|
42
|
-
process.env = { ...previousEnv, OPENAI_API_KEY: "test" };
|
|
43
|
-
});
|
|
44
|
-
afterEach(async () => {
|
|
45
|
-
process.env = previousEnv;
|
|
46
|
-
await db.appDataSource.destroy();
|
|
47
|
-
});
|
|
48
|
-
test.skip("QuerySqlTool", async () => {
|
|
49
|
-
const querySqlTool = new QuerySqlTool(db);
|
|
50
|
-
const result = await querySqlTool.invoke("SELECT * FROM users");
|
|
51
|
-
expect(result).toBe(`[{"id":1,"name":"Alice","age":20},{"id":2,"name":"Bob","age":21},{"id":3,"name":"Charlie","age":22}]`);
|
|
52
|
-
});
|
|
53
|
-
test.skip("QuerySqlTool with error", async () => {
|
|
54
|
-
const querySqlTool = new QuerySqlTool(db);
|
|
55
|
-
const result = await querySqlTool.invoke("SELECT * FROM userss");
|
|
56
|
-
expect(result).toBe(`QueryFailedError: SQLITE_ERROR: no such table: userss`);
|
|
57
|
-
});
|
|
58
|
-
test.skip("InfoSqlTool", async () => {
|
|
59
|
-
const infoSqlTool = new InfoSqlTool(db);
|
|
60
|
-
const result = await infoSqlTool.invoke("users, products");
|
|
61
|
-
const expectStr = `
|
|
62
|
-
CREATE TABLE products (
|
|
63
|
-
id INTEGER , name TEXT , price INTEGER )
|
|
64
|
-
SELECT * FROM "products" LIMIT 3;
|
|
65
|
-
id name price
|
|
66
|
-
1 Apple 100
|
|
67
|
-
2 Banana 200
|
|
68
|
-
3 Orange 300
|
|
69
|
-
CREATE TABLE users (
|
|
70
|
-
id INTEGER , name TEXT , age INTEGER )
|
|
71
|
-
SELECT * FROM "users" LIMIT 3;
|
|
72
|
-
id name age
|
|
73
|
-
1 Alice 20
|
|
74
|
-
2 Bob 21
|
|
75
|
-
3 Charlie 22`;
|
|
76
|
-
expect(result.trim()).toBe(expectStr.trim());
|
|
77
|
-
});
|
|
78
|
-
test.skip("InfoSqlTool with customDescription", async () => {
|
|
79
|
-
db.customDescription = {
|
|
80
|
-
products: "Custom Description for Products Table",
|
|
81
|
-
users: "Custom Description for Users Table",
|
|
82
|
-
userss: "Should not appear",
|
|
83
|
-
};
|
|
84
|
-
const infoSqlTool = new InfoSqlTool(db);
|
|
85
|
-
const result = await infoSqlTool.invoke("users, products");
|
|
86
|
-
const expectStr = `
|
|
87
|
-
Custom Description for Products Table
|
|
88
|
-
CREATE TABLE products (
|
|
89
|
-
id INTEGER , name TEXT , price INTEGER )
|
|
90
|
-
SELECT * FROM "products" LIMIT 3;
|
|
91
|
-
id name price
|
|
92
|
-
1 Apple 100
|
|
93
|
-
2 Banana 200
|
|
94
|
-
3 Orange 300
|
|
95
|
-
Custom Description for Users Table
|
|
96
|
-
CREATE TABLE users (
|
|
97
|
-
id INTEGER , name TEXT , age INTEGER )
|
|
98
|
-
SELECT * FROM "users" LIMIT 3;
|
|
99
|
-
id name age
|
|
100
|
-
1 Alice 20
|
|
101
|
-
2 Bob 21
|
|
102
|
-
3 Charlie 22`;
|
|
103
|
-
expect(result.trim()).toBe(expectStr.trim());
|
|
104
|
-
});
|
|
105
|
-
test.skip("InfoSqlTool with error", async () => {
|
|
106
|
-
const infoSqlTool = new InfoSqlTool(db);
|
|
107
|
-
const result = await infoSqlTool.invoke("userss, products");
|
|
108
|
-
expect(result).toBe(`Error: Wrong target table name: the table userss was not found in the database`);
|
|
109
|
-
});
|
|
110
|
-
test.skip("ListTablesSqlTool", async () => {
|
|
111
|
-
const listSqlTool = new ListTablesSqlTool(db);
|
|
112
|
-
const result = await listSqlTool.invoke("");
|
|
113
|
-
expect(result).toBe(`products, users`);
|
|
114
|
-
});
|
|
115
|
-
test.skip("QueryCheckerTool", async () => {
|
|
116
|
-
const queryCheckerTool = new QueryCheckerTool();
|
|
117
|
-
expect(queryCheckerTool.llmChain).not.toBeNull();
|
|
118
|
-
expect(queryCheckerTool.llmChain.inputKeys).toEqual(["query"]);
|
|
119
|
-
});
|
|
120
|
-
test.skip("ListTablesSqlTool with include tables", async () => {
|
|
121
|
-
const includesTables = ["users"];
|
|
122
|
-
db.includesTables = includesTables;
|
|
123
|
-
const listSqlTool = new ListTablesSqlTool(db);
|
|
124
|
-
const result = await listSqlTool.invoke("");
|
|
125
|
-
expect(result).toBe("users");
|
|
126
|
-
});
|
|
127
|
-
test.skip("ListTablesSqlTool with ignore tables", async () => {
|
|
128
|
-
const ignoreTables = ["products"];
|
|
129
|
-
db.ignoreTables = ignoreTables;
|
|
130
|
-
const listSqlTool = new ListTablesSqlTool(db);
|
|
131
|
-
const result = await listSqlTool.invoke("");
|
|
132
|
-
expect(result).toBe("users");
|
|
133
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { StructuredChatOutputParser } from "../structured_chat/outputParser.js";
|
|
3
|
-
test("Can parse JSON with text in front of it", async () => {
|
|
4
|
-
const testCases = [
|
|
5
|
-
{
|
|
6
|
-
input: 'Here we have some boilerplate nonsense```json\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',
|
|
7
|
-
output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
|
|
8
|
-
tool: "blogpost",
|
|
9
|
-
toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
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',
|
|
13
|
-
output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
|
|
14
|
-
tool: "blogpost",
|
|
15
|
-
toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
const p = new StructuredChatOutputParser({ toolNames: ["blogpost"] });
|
|
19
|
-
for (const message of testCases) {
|
|
20
|
-
const parsed = await p.parse(message.input);
|
|
21
|
-
expect(parsed).toBeDefined();
|
|
22
|
-
if (message.tool === "Final Answer") {
|
|
23
|
-
expect(parsed.returnValues).toBeDefined();
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
expect(parsed.tool).toEqual(message.tool);
|
|
27
|
-
if (typeof message.toolInput === "object") {
|
|
28
|
-
expect(message.toolInput).toEqual(parsed.toolInput);
|
|
29
|
-
}
|
|
30
|
-
if (typeof message.toolInput === "string") {
|
|
31
|
-
expect(message.toolInput).toContain(parsed.toolInput);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
-
import { StructuredChatOutputParserWithRetries } from "../structured_chat/outputParser.js";
|
|
4
|
-
test("Can parse JSON with text in front of it", async () => {
|
|
5
|
-
const testCases = [
|
|
6
|
-
{
|
|
7
|
-
input: 'Here we have an invalid format (missing markdown block) that the parser should retry and fix: {\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',
|
|
8
|
-
tool: "blogpost",
|
|
9
|
-
toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
input: 'Here we have an invalid format (missing markdown block) with a structured tool that the parser should retry and fix: {\n \t\r\n"action": "blogpost",\n\t\r "action_input": {"query": "SELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = $1",\n\t"parameters": ["bud"]\n\t}\n\t\r}\n\n\n\t\r and at the end there is more nonsense',
|
|
13
|
-
tool: "blogpost",
|
|
14
|
-
toolInput: {
|
|
15
|
-
query: "SELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = $1",
|
|
16
|
-
parameters: ["bud"],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
input: `I don't know the answer.`,
|
|
21
|
-
tool: "Final Answer",
|
|
22
|
-
toolInput: "I don't know the answer.",
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
const p = StructuredChatOutputParserWithRetries.fromLLM(new ChatOpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" }), {
|
|
26
|
-
toolNames: ["blogpost"],
|
|
27
|
-
});
|
|
28
|
-
for (const message of testCases) {
|
|
29
|
-
const parsed = await p.parse(message.input);
|
|
30
|
-
expect(parsed).toBeDefined();
|
|
31
|
-
if (message.tool === "Final Answer") {
|
|
32
|
-
expect(parsed.returnValues).toBeDefined();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
expect(parsed.tool).toEqual(message.tool);
|
|
36
|
-
if (typeof message.toolInput === "object") {
|
|
37
|
-
expect(message.toolInput).toEqual(parsed.toolInput);
|
|
38
|
-
}
|
|
39
|
-
if (typeof message.toolInput === "string") {
|
|
40
|
-
expect(message.toolInput).toContain(parsed.toolInput);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";
|
|
5
|
-
import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
|
|
6
|
-
import { RunnableSequence } from "@langchain/core/runnables";
|
|
7
|
-
import { ChatPromptTemplate, MessagesPlaceholder, } from "@langchain/core/prompts";
|
|
8
|
-
import { createRetrieverTool } from "../toolkits/index.js";
|
|
9
|
-
import { RecursiveCharacterTextSplitter } from "../../text_splitter.js";
|
|
10
|
-
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
11
|
-
import { AgentExecutor } from "../executor.js";
|
|
12
|
-
import { formatForOpenAIFunctions } from "../format_scratchpad/openai_functions.js";
|
|
13
|
-
/** Define a custom structured output parser. */
|
|
14
|
-
const structuredOutputParser = (output) => {
|
|
15
|
-
if (typeof output.content !== "string") {
|
|
16
|
-
throw new Error("Cannot parse non-string output.");
|
|
17
|
-
}
|
|
18
|
-
if (output.additional_kwargs.function_call === undefined) {
|
|
19
|
-
return { returnValues: { output: output.content }, log: output.content };
|
|
20
|
-
}
|
|
21
|
-
const functionCall = output.additional_kwargs.function_call;
|
|
22
|
-
const name = functionCall?.name;
|
|
23
|
-
const inputs = functionCall?.arguments;
|
|
24
|
-
console.log(functionCall);
|
|
25
|
-
const jsonInput = JSON.parse(inputs);
|
|
26
|
-
if (name === "response") {
|
|
27
|
-
return { returnValues: { ...jsonInput }, log: output.content };
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
tool: name,
|
|
31
|
-
toolInput: jsonInput,
|
|
32
|
-
log: output.content,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
test("Pass custom structured output parsers", async () => {
|
|
36
|
-
/** Read text file & embed documents */
|
|
37
|
-
const text = fs.readFileSync("../examples/state_of_the_union.txt", "utf8");
|
|
38
|
-
const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000 });
|
|
39
|
-
let docs = await textSplitter.createDocuments([text]);
|
|
40
|
-
// Add fake source information
|
|
41
|
-
docs = docs.map((doc, i) => ({
|
|
42
|
-
...doc,
|
|
43
|
-
metadata: {
|
|
44
|
-
page_chunk: i,
|
|
45
|
-
},
|
|
46
|
-
}));
|
|
47
|
-
/** Initialize docs & create retriever */
|
|
48
|
-
const vectorStore = await MemoryVectorStore.fromDocuments(docs, new OpenAIEmbeddings());
|
|
49
|
-
const retriever = vectorStore.asRetriever();
|
|
50
|
-
/** Instantiate the LLM */
|
|
51
|
-
const llm = new ChatOpenAI({});
|
|
52
|
-
/** Define the prompt template */
|
|
53
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
54
|
-
["system", "You are a helpful assistant"],
|
|
55
|
-
new MessagesPlaceholder("agent_scratchpad"),
|
|
56
|
-
["user", "{input}"],
|
|
57
|
-
]);
|
|
58
|
-
/** Define the response schema */
|
|
59
|
-
const responseSchema = z.object({
|
|
60
|
-
answer: z.string().describe("The final answer to respond to the user"),
|
|
61
|
-
sources: z
|
|
62
|
-
.array(z.string())
|
|
63
|
-
.describe("List of page chunks that contain answer to the question. Only include a page chunk if it contains relevant information"),
|
|
64
|
-
});
|
|
65
|
-
/** Create the response function */
|
|
66
|
-
const responseOpenAIFunction = {
|
|
67
|
-
name: "response",
|
|
68
|
-
description: "Return the response to the user",
|
|
69
|
-
parameters: zodToJsonSchema(responseSchema),
|
|
70
|
-
};
|
|
71
|
-
/** Convert retriever into a tool */
|
|
72
|
-
const retrieverTool = createRetrieverTool(retriever, {
|
|
73
|
-
name: "state-of-union-retriever",
|
|
74
|
-
description: "Query a retriever to get information about state of the union address",
|
|
75
|
-
});
|
|
76
|
-
/** Bind both retriever and response functions to LLM */
|
|
77
|
-
const llmWithTools = llm.bind({
|
|
78
|
-
functions: [convertToOpenAIFunction(retrieverTool), responseOpenAIFunction],
|
|
79
|
-
});
|
|
80
|
-
/** Create the runnable */
|
|
81
|
-
const runnableAgent = RunnableSequence.from([
|
|
82
|
-
{
|
|
83
|
-
input: (i) => i.input,
|
|
84
|
-
agent_scratchpad: (i) => formatForOpenAIFunctions(i.steps),
|
|
85
|
-
},
|
|
86
|
-
prompt,
|
|
87
|
-
llmWithTools,
|
|
88
|
-
structuredOutputParser,
|
|
89
|
-
]);
|
|
90
|
-
/** Create the agent by passing in the runnable & tools */
|
|
91
|
-
const executor = AgentExecutor.fromAgentAndTools({
|
|
92
|
-
agent: runnableAgent,
|
|
93
|
-
tools: [retrieverTool],
|
|
94
|
-
});
|
|
95
|
-
/** Call invoke on the agent */
|
|
96
|
-
const res = await executor.invoke({
|
|
97
|
-
input: "what did the president say about kentaji brown jackson",
|
|
98
|
-
});
|
|
99
|
-
console.log({
|
|
100
|
-
res,
|
|
101
|
-
});
|
|
102
|
-
/**
|
|
103
|
-
{
|
|
104
|
-
res: {
|
|
105
|
-
answer: 'President mentioned that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. He described her as one of our nation’s top legal minds and stated that she will continue Justice Breyer’s legacy of excellence.',
|
|
106
|
-
sources: [
|
|
107
|
-
'And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence. A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.'
|
|
108
|
-
]
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
*/
|
|
112
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { test } from "@jest/globals";
|
|
2
|
-
import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";
|
|
3
|
-
import { MemoryVectorStore } from "../../../vectorstores/memory.js";
|
|
4
|
-
import { createConversationalRetrievalAgent } from "../conversational_retrieval/openai_functions.js";
|
|
5
|
-
import { createRetrieverTool } from "../conversational_retrieval/tool.js";
|
|
6
|
-
test("Test ConversationalRetrievalAgent", async () => {
|
|
7
|
-
const vectorStore = await MemoryVectorStore.fromTexts([
|
|
8
|
-
"LangCo made $10000 in July",
|
|
9
|
-
"LangCo made $20 in August",
|
|
10
|
-
"Foo is red",
|
|
11
|
-
"Bar is red",
|
|
12
|
-
"Buildings are made out of brick",
|
|
13
|
-
"Mitochondria is the powerhouse of the cell",
|
|
14
|
-
], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new OpenAIEmbeddings());
|
|
15
|
-
const llm = new ChatOpenAI({});
|
|
16
|
-
const tools = [
|
|
17
|
-
createRetrieverTool(vectorStore.asRetriever(), {
|
|
18
|
-
name: "search_LangCo_knowledge",
|
|
19
|
-
description: "Searches for and returns documents regarding LangCo",
|
|
20
|
-
}),
|
|
21
|
-
];
|
|
22
|
-
const executor = await createConversationalRetrievalAgent(llm, tools, {
|
|
23
|
-
verbose: true,
|
|
24
|
-
});
|
|
25
|
-
const result = await executor.invoke({
|
|
26
|
-
input: "Hi, I'm Bob!",
|
|
27
|
-
});
|
|
28
|
-
console.log(result);
|
|
29
|
-
const result2 = await executor.invoke({
|
|
30
|
-
input: "What's my name?",
|
|
31
|
-
});
|
|
32
|
-
console.log(result2);
|
|
33
|
-
const result3 = await executor.invoke({
|
|
34
|
-
input: "How much money did LangCo make in July?",
|
|
35
|
-
});
|
|
36
|
-
console.log(result3);
|
|
37
|
-
const result4 = await executor.invoke({
|
|
38
|
-
input: "How about in August?",
|
|
39
|
-
});
|
|
40
|
-
console.log(result4);
|
|
41
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import * as os from "node:os";
|
|
5
|
-
import { OpenAI, ChatOpenAI } from "@langchain/openai";
|
|
6
|
-
import { LocalFileCache } from "../file_system.js";
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
let tmpDir;
|
|
9
|
-
describe("Test LocalFileCache", () => {
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "langchain-"));
|
|
12
|
-
});
|
|
13
|
-
afterAll(async () => {
|
|
14
|
-
await fs.rm(tmpDir, { recursive: true });
|
|
15
|
-
});
|
|
16
|
-
test("FSCache with an LLM", async () => {
|
|
17
|
-
const cache = await LocalFileCache.create(tmpDir);
|
|
18
|
-
const model = new OpenAI({ cache });
|
|
19
|
-
const response1 = await model.invoke("What is something random?");
|
|
20
|
-
const response2 = await model.invoke("What is something random?");
|
|
21
|
-
expect(response1).toEqual(response2);
|
|
22
|
-
});
|
|
23
|
-
test("FSCache with a chat model", async () => {
|
|
24
|
-
const cache = await LocalFileCache.create(tmpDir);
|
|
25
|
-
const model = new ChatOpenAI({ cache });
|
|
26
|
-
const response1 = await model.invoke("What is something random?");
|
|
27
|
-
const response2 = await model.invoke("What is something random?");
|
|
28
|
-
expect(response1).not.toBeUndefined();
|
|
29
|
-
console.log(response1, response2);
|
|
30
|
-
expect(response1).toEqual(response2);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
3
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
-
import { expect, test } from "@jest/globals";
|
|
5
|
-
import { JsonOutputFunctionsParser } from "../../../output_parsers/openai_functions.js";
|
|
6
|
-
import { createOpenAIFnRunnable, createStructuredOutputRunnable, } from "../base.js";
|
|
7
|
-
const personJSONSchema = {
|
|
8
|
-
title: "Person",
|
|
9
|
-
description: "Identifying information about a person.",
|
|
10
|
-
type: "object",
|
|
11
|
-
properties: {
|
|
12
|
-
name: { title: "Name", description: "The person's name", type: "string" },
|
|
13
|
-
age: { title: "Age", description: "The person's age", type: "integer" },
|
|
14
|
-
fav_food: {
|
|
15
|
-
title: "Fav Food",
|
|
16
|
-
description: "The person's favorite food",
|
|
17
|
-
type: "string",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
required: ["name", "age"],
|
|
21
|
-
};
|
|
22
|
-
const personDetailsFunction = {
|
|
23
|
-
name: "get_person_details",
|
|
24
|
-
description: "Get details about a person",
|
|
25
|
-
parameters: personJSONSchema,
|
|
26
|
-
};
|
|
27
|
-
const weatherFunction = {
|
|
28
|
-
name: "get_weather",
|
|
29
|
-
description: "Get the weather for a location",
|
|
30
|
-
parameters: {
|
|
31
|
-
title: "Location",
|
|
32
|
-
description: "The location to get the weather for.",
|
|
33
|
-
type: "object",
|
|
34
|
-
properties: {
|
|
35
|
-
state: {
|
|
36
|
-
title: "State",
|
|
37
|
-
description: "The location's state",
|
|
38
|
-
type: "string",
|
|
39
|
-
},
|
|
40
|
-
city: {
|
|
41
|
-
title: "City",
|
|
42
|
-
description: "The location's city",
|
|
43
|
-
type: "string",
|
|
44
|
-
},
|
|
45
|
-
zip_code: {
|
|
46
|
-
title: "Zip Code",
|
|
47
|
-
description: "The locations's zip code",
|
|
48
|
-
type: "string",
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
required: ["state", "city"],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
test("createStructuredOutputRunnable works with Zod", async () => {
|
|
55
|
-
const model = new ChatOpenAI();
|
|
56
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
57
|
-
["human", "Human description: {description}"],
|
|
58
|
-
]);
|
|
59
|
-
const zodSchema = z.object({
|
|
60
|
-
person: z.object({
|
|
61
|
-
name: z.string(),
|
|
62
|
-
age: z.string(),
|
|
63
|
-
fav_food: z.optional(z.string()),
|
|
64
|
-
}),
|
|
65
|
-
});
|
|
66
|
-
const outputParser = new JsonOutputFunctionsParser();
|
|
67
|
-
const runnable = createStructuredOutputRunnable({
|
|
68
|
-
outputSchema: zodSchema,
|
|
69
|
-
llm: model,
|
|
70
|
-
prompt,
|
|
71
|
-
outputParser,
|
|
72
|
-
});
|
|
73
|
-
const response = await runnable.invoke({
|
|
74
|
-
description: "My name's John Doe and I'm 30 years old. My favorite kind of food are chocolate chip cookies.",
|
|
75
|
-
});
|
|
76
|
-
console.log(response);
|
|
77
|
-
expect("person" in response).toBe(true);
|
|
78
|
-
expect("name" in response.person).toBe(true);
|
|
79
|
-
expect("age" in response.person).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
test("createStructuredOutputRunnable works with JSON schema", async () => {
|
|
82
|
-
const model = new ChatOpenAI();
|
|
83
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
84
|
-
["human", "Human description: {description}"],
|
|
85
|
-
]);
|
|
86
|
-
const outputParser = new JsonOutputFunctionsParser();
|
|
87
|
-
const runnable = createStructuredOutputRunnable({
|
|
88
|
-
outputSchema: personJSONSchema,
|
|
89
|
-
llm: model,
|
|
90
|
-
prompt,
|
|
91
|
-
outputParser,
|
|
92
|
-
});
|
|
93
|
-
const response = await runnable.invoke({
|
|
94
|
-
description: "My name's John Doe and I'm 30 years old. My favorite kind of food are chocolate chip cookies.",
|
|
95
|
-
});
|
|
96
|
-
console.log(response);
|
|
97
|
-
expect("name" in response).toBe(true);
|
|
98
|
-
expect("age" in response).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
test("createOpenAIFnRunnable works", async () => {
|
|
101
|
-
const model = new ChatOpenAI();
|
|
102
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
103
|
-
["human", "Human description: {description}"],
|
|
104
|
-
]);
|
|
105
|
-
const outputParser = new JsonOutputFunctionsParser();
|
|
106
|
-
const runnable = createOpenAIFnRunnable({
|
|
107
|
-
functions: [personDetailsFunction],
|
|
108
|
-
llm: model,
|
|
109
|
-
prompt,
|
|
110
|
-
enforceSingleFunctionUsage: true,
|
|
111
|
-
outputParser,
|
|
112
|
-
});
|
|
113
|
-
const response = await runnable.invoke({
|
|
114
|
-
description: "My name's John Doe and I'm 30 years old. My favorite kind of food are chocolate chip cookies.",
|
|
115
|
-
});
|
|
116
|
-
console.log(response);
|
|
117
|
-
expect("name" in response).toBe(true);
|
|
118
|
-
expect("age" in response).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
test("createOpenAIFnRunnable works with multiple functions", async () => {
|
|
121
|
-
const model = new ChatOpenAI();
|
|
122
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
123
|
-
["human", "Question: {question}"],
|
|
124
|
-
]);
|
|
125
|
-
const outputParser = new JsonOutputFunctionsParser();
|
|
126
|
-
const runnable = createOpenAIFnRunnable({
|
|
127
|
-
functions: [personDetailsFunction, weatherFunction],
|
|
128
|
-
llm: model,
|
|
129
|
-
prompt,
|
|
130
|
-
enforceSingleFunctionUsage: false,
|
|
131
|
-
outputParser,
|
|
132
|
-
});
|
|
133
|
-
const response = await runnable.invoke({
|
|
134
|
-
question: "What's the weather like in Berkeley CA?",
|
|
135
|
-
});
|
|
136
|
-
console.log(response);
|
|
137
|
-
expect("state" in response).toBe(true);
|
|
138
|
-
expect("city" in response).toBe(true);
|
|
139
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "@jest/globals";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
-
import { createExtractionChainFromZod } from "../extraction.js";
|
|
5
|
-
test("extraction chain", async () => {
|
|
6
|
-
const chain = createExtractionChainFromZod(z.object({
|
|
7
|
-
"person-name": z.string().optional(),
|
|
8
|
-
"person-age": z.number().optional(),
|
|
9
|
-
"person-hair_color": z.string().optional(),
|
|
10
|
-
"dog-name": z.string().optional(),
|
|
11
|
-
"dog-breed": z.string().optional(),
|
|
12
|
-
}), new ChatOpenAI({ modelName: "gpt-3.5-turbo-0613", temperature: 0 }));
|
|
13
|
-
const result = await chain.run(`Alex is 5 feet tall. Claudia is 4 feet taller Alex and jumps higher than him. Claudia is a brunette and Alex is blonde.
|
|
14
|
-
Alex's dog Frosty is a labrador and likes to play hide and seek.`);
|
|
15
|
-
expect(result).toMatchInlineSnapshot(`
|
|
16
|
-
[
|
|
17
|
-
{
|
|
18
|
-
"dog-breed": "labrador",
|
|
19
|
-
"dog-name": "Frosty",
|
|
20
|
-
"person-age": 0,
|
|
21
|
-
"person-hair_color": "blonde",
|
|
22
|
-
"person-name": "Alex",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"dog-breed": "",
|
|
26
|
-
"dog-name": "",
|
|
27
|
-
"person-age": 0,
|
|
28
|
-
"person-hair_color": "brunette",
|
|
29
|
-
"person-name": "Claudia",
|
|
30
|
-
},
|
|
31
|
-
]
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|