@ax-llm/ax 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +547 -0
- package/build/module/docs/assets/icons.d.ts +1 -0
- package/build/module/docs/assets/icons.js +19 -0
- package/build/module/docs/assets/icons.js.map +1 -0
- package/build/module/docs/assets/main.d.ts +1 -0
- package/build/module/docs/assets/main.js +629 -0
- package/build/module/docs/assets/main.js.map +1 -0
- package/build/module/docs/assets/navigation.d.ts +1 -0
- package/build/module/docs/assets/navigation.js +3 -0
- package/build/module/docs/assets/navigation.js.map +1 -0
- package/build/module/docs/assets/search.d.ts +1 -0
- package/build/module/docs/assets/search.js +3 -0
- package/build/module/docs/assets/search.js.map +1 -0
- package/build/module/src/ai/anthropic/api.d.ts +24 -0
- package/build/module/src/ai/anthropic/api.js +188 -0
- package/build/module/src/ai/anthropic/api.js.map +1 -0
- package/build/module/src/ai/anthropic/index.d.ts +2 -0
- package/build/module/src/ai/anthropic/index.js +3 -0
- package/build/module/src/ai/anthropic/index.js.map +1 -0
- package/build/module/src/ai/anthropic/info.d.ts +2 -0
- package/build/module/src/ai/anthropic/info.js +34 -0
- package/build/module/src/ai/anthropic/info.js.map +1 -0
- package/build/module/src/ai/anthropic/types.d.ts +140 -0
- package/build/module/src/ai/anthropic/types.js +13 -0
- package/build/module/src/ai/anthropic/types.js.map +1 -0
- package/build/module/src/ai/azure-openai/api.d.ts +34 -0
- package/build/module/src/ai/azure-openai/api.js +42 -0
- package/build/module/src/ai/azure-openai/api.js.map +1 -0
- package/build/module/src/ai/azure-openai/index.d.ts +1 -0
- package/build/module/src/ai/azure-openai/index.js +2 -0
- package/build/module/src/ai/azure-openai/index.js.map +1 -0
- package/build/module/src/ai/balance.d.ts +26 -0
- package/build/module/src/ai/balance.js +87 -0
- package/build/module/src/ai/balance.js.map +1 -0
- package/build/module/src/ai/base.d.ts +56 -0
- package/build/module/src/ai/base.js +328 -0
- package/build/module/src/ai/base.js.map +1 -0
- package/build/module/src/ai/cohere/api.d.ts +35 -0
- package/build/module/src/ai/cohere/api.js +214 -0
- package/build/module/src/ai/cohere/api.js.map +1 -0
- package/build/module/src/ai/cohere/index.d.ts +2 -0
- package/build/module/src/ai/cohere/index.js +3 -0
- package/build/module/src/ai/cohere/index.js.map +1 -0
- package/build/module/src/ai/cohere/info.d.ts +2 -0
- package/build/module/src/ai/cohere/info.js +52 -0
- package/build/module/src/ai/cohere/info.js.map +1 -0
- package/build/module/src/ai/cohere/types.d.ts +85 -0
- package/build/module/src/ai/cohere/types.js +23 -0
- package/build/module/src/ai/cohere/types.js.map +1 -0
- package/build/module/src/ai/deepseek/api.d.ts +27 -0
- package/build/module/src/ai/deepseek/api.js +38 -0
- package/build/module/src/ai/deepseek/api.js.map +1 -0
- package/build/module/src/ai/deepseek/index.d.ts +2 -0
- package/build/module/src/ai/deepseek/index.js +3 -0
- package/build/module/src/ai/deepseek/index.js.map +1 -0
- package/build/module/src/ai/deepseek/info.d.ts +2 -0
- package/build/module/src/ai/deepseek/info.js +16 -0
- package/build/module/src/ai/deepseek/info.js.map +1 -0
- package/build/module/src/ai/deepseek/types.d.ts +8 -0
- package/build/module/src/ai/deepseek/types.js +10 -0
- package/build/module/src/ai/deepseek/types.js.map +1 -0
- package/build/module/src/ai/google-gemini/api.d.ts +34 -0
- package/build/module/src/ai/google-gemini/api.js +268 -0
- package/build/module/src/ai/google-gemini/api.js.map +1 -0
- package/build/module/src/ai/google-gemini/index.d.ts +2 -0
- package/build/module/src/ai/google-gemini/index.js +3 -0
- package/build/module/src/ai/google-gemini/index.js.map +1 -0
- package/build/module/src/ai/google-gemini/info.d.ts +6 -0
- package/build/module/src/ai/google-gemini/info.js +29 -0
- package/build/module/src/ai/google-gemini/info.js.map +1 -0
- package/build/module/src/ai/google-gemini/types.d.ts +151 -0
- package/build/module/src/ai/google-gemini/types.js +38 -0
- package/build/module/src/ai/google-gemini/types.js.map +1 -0
- package/build/module/src/ai/groq/api.d.ts +22 -0
- package/build/module/src/ai/groq/api.js +29 -0
- package/build/module/src/ai/groq/api.js.map +1 -0
- package/build/module/src/ai/groq/index.d.ts +1 -0
- package/build/module/src/ai/groq/index.js +2 -0
- package/build/module/src/ai/groq/index.js.map +1 -0
- package/build/module/src/ai/huggingface/api.d.ts +32 -0
- package/build/module/src/ai/huggingface/api.js +99 -0
- package/build/module/src/ai/huggingface/api.js.map +1 -0
- package/build/module/src/ai/huggingface/index.d.ts +2 -0
- package/build/module/src/ai/huggingface/index.js +3 -0
- package/build/module/src/ai/huggingface/index.js.map +1 -0
- package/build/module/src/ai/huggingface/info.d.ts +6 -0
- package/build/module/src/ai/huggingface/info.js +6 -0
- package/build/module/src/ai/huggingface/info.js.map +1 -0
- package/build/module/src/ai/huggingface/types.d.ts +42 -0
- package/build/module/src/ai/huggingface/types.js +9 -0
- package/build/module/src/ai/huggingface/types.js.map +1 -0
- package/build/module/src/ai/index.d.ts +28 -0
- package/build/module/src/ai/index.js +54 -0
- package/build/module/src/ai/index.js.map +1 -0
- package/build/module/src/ai/mistral/api.d.ts +27 -0
- package/build/module/src/ai/mistral/api.js +38 -0
- package/build/module/src/ai/mistral/api.js.map +1 -0
- package/build/module/src/ai/mistral/index.d.ts +2 -0
- package/build/module/src/ai/mistral/index.js +3 -0
- package/build/module/src/ai/mistral/index.js.map +1 -0
- package/build/module/src/ai/mistral/info.d.ts +2 -0
- package/build/module/src/ai/mistral/info.js +34 -0
- package/build/module/src/ai/mistral/info.js.map +1 -0
- package/build/module/src/ai/mistral/types.d.ts +18 -0
- package/build/module/src/ai/mistral/types.js +21 -0
- package/build/module/src/ai/mistral/types.js.map +1 -0
- package/build/module/src/ai/ollama/api.d.ts +24 -0
- package/build/module/src/ai/ollama/api.js +28 -0
- package/build/module/src/ai/ollama/api.js.map +1 -0
- package/build/module/src/ai/ollama/index.d.ts +1 -0
- package/build/module/src/ai/ollama/index.js +2 -0
- package/build/module/src/ai/ollama/index.js.map +1 -0
- package/build/module/src/ai/openai/api.d.ts +49 -0
- package/build/module/src/ai/openai/api.js +333 -0
- package/build/module/src/ai/openai/api.js.map +1 -0
- package/build/module/src/ai/openai/index.d.ts +2 -0
- package/build/module/src/ai/openai/index.js +3 -0
- package/build/module/src/ai/openai/index.js.map +1 -0
- package/build/module/src/ai/openai/info.d.ts +6 -0
- package/build/module/src/ai/openai/info.js +50 -0
- package/build/module/src/ai/openai/info.js.map +1 -0
- package/build/module/src/ai/openai/types.d.ts +192 -0
- package/build/module/src/ai/openai/types.js +35 -0
- package/build/module/src/ai/openai/types.js.map +1 -0
- package/build/module/src/ai/together/api.d.ts +22 -0
- package/build/module/src/ai/together/api.js +29 -0
- package/build/module/src/ai/together/api.js.map +1 -0
- package/build/module/src/ai/together/index.d.ts +1 -0
- package/build/module/src/ai/together/index.js +2 -0
- package/build/module/src/ai/together/index.js.map +1 -0
- package/build/module/src/ai/together/info.d.ts +2 -0
- package/build/module/src/ai/together/info.js +2 -0
- package/build/module/src/ai/together/info.js.map +1 -0
- package/build/module/src/ai/types.d.ts +70 -0
- package/build/module/src/ai/types.js +2 -0
- package/build/module/src/ai/types.js.map +1 -0
- package/build/module/src/ai/util.d.ts +13 -0
- package/build/module/src/ai/util.js +112 -0
- package/build/module/src/ai/util.js.map +1 -0
- package/build/module/src/db/base.d.ts +24 -0
- package/build/module/src/db/base.js +90 -0
- package/build/module/src/db/base.js.map +1 -0
- package/build/module/src/db/cloudflare.d.ts +20 -0
- package/build/module/src/db/cloudflare.js +98 -0
- package/build/module/src/db/cloudflare.js.map +1 -0
- package/build/module/src/db/index.d.ts +12 -0
- package/build/module/src/db/index.js +23 -0
- package/build/module/src/db/index.js.map +1 -0
- package/build/module/src/db/memory.d.ts +23 -0
- package/build/module/src/db/memory.js +125 -0
- package/build/module/src/db/memory.js.map +1 -0
- package/build/module/src/db/pinecone.d.ts +20 -0
- package/build/module/src/db/pinecone.js +71 -0
- package/build/module/src/db/pinecone.js.map +1 -0
- package/build/module/src/db/types.d.ts +35 -0
- package/build/module/src/db/types.js +3 -0
- package/build/module/src/db/types.js.map +1 -0
- package/build/module/src/db/weaviate.d.ts +20 -0
- package/build/module/src/db/weaviate.js +127 -0
- package/build/module/src/db/weaviate.js.map +1 -0
- package/build/module/src/docs/index.d.ts +4 -0
- package/build/module/src/docs/index.js +5 -0
- package/build/module/src/docs/index.js.map +1 -0
- package/build/module/src/docs/manager.d.ts +45 -0
- package/build/module/src/docs/manager.js +159 -0
- package/build/module/src/docs/manager.js.map +1 -0
- package/build/module/src/docs/reranker.d.ts +7 -0
- package/build/module/src/docs/reranker.js +26 -0
- package/build/module/src/docs/reranker.js.map +1 -0
- package/build/module/src/docs/rewriter.d.ts +4 -0
- package/build/module/src/docs/rewriter.js +9 -0
- package/build/module/src/docs/rewriter.js.map +1 -0
- package/build/module/src/docs/tika.d.ts +21 -0
- package/build/module/src/docs/tika.js +46 -0
- package/build/module/src/docs/tika.js.map +1 -0
- package/build/module/src/dsp/asserts.d.ts +32 -0
- package/build/module/src/dsp/asserts.js +88 -0
- package/build/module/src/dsp/asserts.js.map +1 -0
- package/build/module/src/dsp/eval.d.ts +62 -0
- package/build/module/src/dsp/eval.js +120 -0
- package/build/module/src/dsp/eval.js.map +1 -0
- package/build/module/src/dsp/evaluate.d.ts +12 -0
- package/build/module/src/dsp/evaluate.js +32 -0
- package/build/module/src/dsp/evaluate.js.map +1 -0
- package/build/module/src/dsp/extract.d.ts +25 -0
- package/build/module/src/dsp/extract.js +152 -0
- package/build/module/src/dsp/extract.js.map +1 -0
- package/build/module/src/dsp/generate.d.ts +52 -0
- package/build/module/src/dsp/generate.js +335 -0
- package/build/module/src/dsp/generate.js.map +1 -0
- package/build/module/src/dsp/generate.test.d.ts +1 -0
- package/build/module/src/dsp/generate.test.js +41 -0
- package/build/module/src/dsp/generate.test.js.map +1 -0
- package/build/module/src/dsp/index.d.ts +14 -0
- package/build/module/src/dsp/index.js +10 -0
- package/build/module/src/dsp/index.js.map +1 -0
- package/build/module/src/dsp/loader.d.ts +25 -0
- package/build/module/src/dsp/loader.js +87 -0
- package/build/module/src/dsp/loader.js.map +1 -0
- package/build/module/src/dsp/optimize.d.ts +29 -0
- package/build/module/src/dsp/optimize.js +100 -0
- package/build/module/src/dsp/optimize.js.map +1 -0
- package/build/module/src/dsp/parser.d.ts +86 -0
- package/build/module/src/dsp/parser.js +1437 -0
- package/build/module/src/dsp/parser.js.map +1 -0
- package/build/module/src/dsp/program.d.ts +64 -0
- package/build/module/src/dsp/program.js +129 -0
- package/build/module/src/dsp/program.js.map +1 -0
- package/build/module/src/dsp/prompt.d.ts +25 -0
- package/build/module/src/dsp/prompt.js +178 -0
- package/build/module/src/dsp/prompt.js.map +1 -0
- package/build/module/src/dsp/registry.d.ts +6 -0
- package/build/module/src/dsp/registry.js +15 -0
- package/build/module/src/dsp/registry.js.map +1 -0
- package/build/module/src/dsp/router.d.ts +24 -0
- package/build/module/src/dsp/router.js +72 -0
- package/build/module/src/dsp/router.js.map +1 -0
- package/build/module/src/dsp/sig.d.ts +37 -0
- package/build/module/src/dsp/sig.js +160 -0
- package/build/module/src/dsp/sig.js.map +1 -0
- package/build/module/src/dsp/sig.test.d.ts +1 -0
- package/build/module/src/dsp/sig.test.js +25 -0
- package/build/module/src/dsp/sig.test.js.map +1 -0
- package/build/module/src/dsp/stopwords.d.ts +1 -0
- package/build/module/src/dsp/stopwords.js +1163 -0
- package/build/module/src/dsp/stopwords.js.map +1 -0
- package/build/module/src/dsp/strutil.d.ts +9 -0
- package/build/module/src/dsp/strutil.js +52 -0
- package/build/module/src/dsp/strutil.js.map +1 -0
- package/build/module/src/dsp/util.d.ts +1 -0
- package/build/module/src/dsp/util.js +14 -0
- package/build/module/src/dsp/util.js.map +1 -0
- package/build/module/src/examples/agent.d.ts +1 -0
- package/build/module/src/examples/agent.js +24 -0
- package/build/module/src/examples/agent.js.map +1 -0
- package/build/module/src/examples/chain-of-thought.d.ts +1 -0
- package/build/module/src/examples/chain-of-thought.js +18 -0
- package/build/module/src/examples/chain-of-thought.js.map +1 -0
- package/build/module/src/examples/customer-support.d.ts +1 -0
- package/build/module/src/examples/customer-support.js +22 -0
- package/build/module/src/examples/customer-support.js.map +1 -0
- package/build/module/src/examples/fibonacci.d.ts +1 -0
- package/build/module/src/examples/fibonacci.js +9 -0
- package/build/module/src/examples/fibonacci.js.map +1 -0
- package/build/module/src/examples/food-search.d.ts +1 -0
- package/build/module/src/examples/food-search.js +137 -0
- package/build/module/src/examples/food-search.js.map +1 -0
- package/build/module/src/examples/marketing.d.ts +1 -0
- package/build/module/src/examples/marketing.js +26 -0
- package/build/module/src/examples/marketing.js.map +1 -0
- package/build/module/src/examples/meetings.d.ts +1 -0
- package/build/module/src/examples/meetings.js +149 -0
- package/build/module/src/examples/meetings.js.map +1 -0
- package/build/module/src/examples/qna-tune.d.ts +1 -0
- package/build/module/src/examples/qna-tune.js +29 -0
- package/build/module/src/examples/qna-tune.js.map +1 -0
- package/build/module/src/examples/qna-use-tuned.d.ts +1 -0
- package/build/module/src/examples/qna-use-tuned.js +25 -0
- package/build/module/src/examples/qna-use-tuned.js.map +1 -0
- package/build/module/src/examples/rag-docs.d.ts +1 -0
- package/build/module/src/examples/rag-docs.js +14 -0
- package/build/module/src/examples/rag-docs.js.map +1 -0
- package/build/module/src/examples/rag.d.ts +1 -0
- package/build/module/src/examples/rag.js +14 -0
- package/build/module/src/examples/rag.js.map +1 -0
- package/build/module/src/examples/react.d.ts +1 -0
- package/build/module/src/examples/react.js +36 -0
- package/build/module/src/examples/react.js.map +1 -0
- package/build/module/src/examples/routing.d.ts +1 -0
- package/build/module/src/examples/routing.js +48 -0
- package/build/module/src/examples/routing.js.map +1 -0
- package/build/module/src/examples/streaming1.d.ts +1 -0
- package/build/module/src/examples/streaming1.js +15 -0
- package/build/module/src/examples/streaming1.js.map +1 -0
- package/build/module/src/examples/streaming2.d.ts +1 -0
- package/build/module/src/examples/streaming2.js +24 -0
- package/build/module/src/examples/streaming2.js.map +1 -0
- package/build/module/src/examples/summarize.d.ts +1 -0
- package/build/module/src/examples/summarize.js +27 -0
- package/build/module/src/examples/summarize.js.map +1 -0
- package/build/module/src/examples/vectordb.d.ts +1 -0
- package/build/module/src/examples/vectordb.js +14 -0
- package/build/module/src/examples/vectordb.js.map +1 -0
- package/build/module/src/funcs/code.d.ts +10 -0
- package/build/module/src/funcs/code.js +63 -0
- package/build/module/src/funcs/code.js.map +1 -0
- package/build/module/src/funcs/embed.d.ts +8 -0
- package/build/module/src/funcs/embed.js +29 -0
- package/build/module/src/funcs/embed.js.map +1 -0
- package/build/module/src/funcs/index.d.ts +2 -0
- package/build/module/src/funcs/index.js +3 -0
- package/build/module/src/funcs/index.js.map +1 -0
- package/build/module/src/index.d.ts +9 -0
- package/build/module/src/index.js +15 -0
- package/build/module/src/index.js.map +1 -0
- package/build/module/src/prompts/agent.d.ts +24 -0
- package/build/module/src/prompts/agent.js +65 -0
- package/build/module/src/prompts/agent.js.map +1 -0
- package/build/module/src/prompts/cot.d.ts +9 -0
- package/build/module/src/prompts/cot.js +17 -0
- package/build/module/src/prompts/cot.js.map +1 -0
- package/build/module/src/prompts/index.d.ts +4 -0
- package/build/module/src/prompts/index.js +5 -0
- package/build/module/src/prompts/index.js.map +1 -0
- package/build/module/src/prompts/prompts.test.d.ts +1 -0
- package/build/module/src/prompts/prompts.test.js +48 -0
- package/build/module/src/prompts/prompts.test.js.map +1 -0
- package/build/module/src/prompts/rag.d.ts +23 -0
- package/build/module/src/prompts/rag.js +30 -0
- package/build/module/src/prompts/rag.js.map +1 -0
- package/build/module/src/prompts/react.d.ts +8 -0
- package/build/module/src/prompts/react.js +22 -0
- package/build/module/src/prompts/react.js.map +1 -0
- package/build/module/src/text/functions.d.ts +25 -0
- package/build/module/src/text/functions.js +55 -0
- package/build/module/src/text/functions.js.map +1 -0
- package/build/module/src/text/index.d.ts +3 -0
- package/build/module/src/text/index.js +4 -0
- package/build/module/src/text/index.js.map +1 -0
- package/build/module/src/text/jsonschema.d.ts +2 -0
- package/build/module/src/text/jsonschema.js +96 -0
- package/build/module/src/text/jsonschema.js.map +1 -0
- package/build/module/src/text/memory.d.ts +21 -0
- package/build/module/src/text/memory.js +73 -0
- package/build/module/src/text/memory.js.map +1 -0
- package/build/module/src/text/types.d.ts +57 -0
- package/build/module/src/text/types.js +2 -0
- package/build/module/src/text/types.js.map +1 -0
- package/build/module/src/trace/index.d.ts +171 -0
- package/build/module/src/trace/index.js +67 -0
- package/build/module/src/trace/index.js.map +1 -0
- package/build/module/src/types/index.d.ts +81 -0
- package/build/module/src/types/index.js +2 -0
- package/build/module/src/types/index.js.map +1 -0
- package/build/module/src/util/apicall.d.ts +21 -0
- package/build/module/src/util/apicall.js +137 -0
- package/build/module/src/util/apicall.js.map +1 -0
- package/build/module/src/util/log.d.ts +14 -0
- package/build/module/src/util/log.js +30 -0
- package/build/module/src/util/log.js.map +1 -0
- package/build/module/src/util/other.d.ts +1 -0
- package/build/module/src/util/other.js +4 -0
- package/build/module/src/util/other.js.map +1 -0
- package/build/module/src/util/stream.d.ts +10 -0
- package/build/module/src/util/stream.js +28 -0
- package/build/module/src/util/stream.js.map +1 -0
- package/build/module/src/util/transform.d.ts +8 -0
- package/build/module/src/util/transform.js +57 -0
- package/build/module/src/util/transform.js.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AI, ChainOfThought, emScore, HFDataLoader, TestPrompt } from '../index.js';
|
|
2
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
3
|
+
const program = new ChainOfThought(ai, `question -> answer "in short 2 or 3 words"`);
|
|
4
|
+
// load tuning data
|
|
5
|
+
// program.loadDemos('demos.json');
|
|
6
|
+
// use directly
|
|
7
|
+
// const res = await gen.forward({
|
|
8
|
+
// question: 'What castle did David Gregory inherit?'
|
|
9
|
+
// });
|
|
10
|
+
// or test to see performance
|
|
11
|
+
const hf = new HFDataLoader();
|
|
12
|
+
const examples = await hf.getData({
|
|
13
|
+
dataset: 'hotpot_qa',
|
|
14
|
+
split: 'validation',
|
|
15
|
+
count: 10,
|
|
16
|
+
fields: ['question', 'answer']
|
|
17
|
+
});
|
|
18
|
+
// Setup a evaluation metric em, f1 scores are a popular way measure retrieval performance.
|
|
19
|
+
const metricFn = ({ prediction, example }) => {
|
|
20
|
+
return emScore(prediction.answer, example.answer);
|
|
21
|
+
};
|
|
22
|
+
const ev = new TestPrompt({ program, examples });
|
|
23
|
+
await ev.run(metricFn);
|
|
24
|
+
// console.log(res);
|
|
25
|
+
//# sourceMappingURL=qna-use-tuned.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qna-use-tuned.js","sourceRoot":"","sources":["../../../../src/examples/qna-use-tuned.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,cAAc,EACd,OAAO,EACP,YAAY,EAGZ,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAE7E,MAAM,OAAO,GAAG,IAAI,cAAc,CAChC,EAAE,EACF,4CAA4C,CAC7C,CAAC;AAEF,mBAAmB;AACnB,mCAAmC;AAEnC,eAAe;AACf,kCAAkC;AAClC,uDAAuD;AACvD,MAAM;AAEN,6BAA6B;AAC7B,MAAM,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC;AAC9B,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,OAAO,CAAuC;IACtE,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC;CAC/B,CAAC,CAAC;AAEH,2FAA2F;AAC3F,MAAM,QAAQ,GAAa,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;IACrD,OAAO,OAAO,CAAC,UAAU,CAAC,MAAgB,EAAE,OAAO,CAAC,MAAgB,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AACjD,MAAM,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEvB,oBAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AI, ApacheTika, DBManager, MemoryDB } from '../index.js';
|
|
2
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
3
|
+
const db = new MemoryDB();
|
|
4
|
+
const tika = new ApacheTika();
|
|
5
|
+
const text = await tika.convert(['./README.md']);
|
|
6
|
+
const manager = new DBManager({ ai, db });
|
|
7
|
+
await manager.insert(text, {
|
|
8
|
+
minWordsPerChunk: 50,
|
|
9
|
+
maxWordsPerChunk: 100
|
|
10
|
+
});
|
|
11
|
+
const matches = await manager.query('Explain semantic routing');
|
|
12
|
+
const topMatch = matches.at(0);
|
|
13
|
+
console.log(topMatch);
|
|
14
|
+
//# sourceMappingURL=rag-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rag-docs.js","sourceRoot":"","sources":["../../../../src/examples/rag-docs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,UAAU,EACV,SAAS,EACT,QAAQ,EAET,MAAM,aAAa,CAAC;AAErB,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAC7E,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;AAE1B,MAAM,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;AAC9B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAEjD,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1C,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;IACzB,gBAAgB,EAAE,EAAE;IACpB,gBAAgB,EAAE,GAAG;CACtB,CAAC,CAAC;AAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AI, ChainOfThought, RAG } from '../index.js';
|
|
2
|
+
// simulated vector db call using an llm
|
|
3
|
+
const fetchFromVectorDB = async (query) => {
|
|
4
|
+
const cot = new ChainOfThought(ai, 'query -> answer');
|
|
5
|
+
const { answer } = await cot.forward({ query });
|
|
6
|
+
return answer;
|
|
7
|
+
};
|
|
8
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
9
|
+
const rag = new RAG(ai, fetchFromVectorDB, { maxHops: 3 });
|
|
10
|
+
const res = await rag.forward({
|
|
11
|
+
question: 'List 3 of the top most important work done by Michael Stonebraker?'
|
|
12
|
+
});
|
|
13
|
+
console.log(res);
|
|
14
|
+
//# sourceMappingURL=rag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rag.js","sourceRoot":"","sources":["../../../../src/examples/rag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAmB,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvE,wCAAwC;AACxC,MAAM,iBAAiB,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE;IAChD,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,EAAE,EACF,iBAAiB,CAClB,CAAC;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAC7E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;AAE3D,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC;IAC5B,QAAQ,EAAE,oEAAoE;CAC/E,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AI, ReAct } from '../index.js';
|
|
2
|
+
const values = {
|
|
3
|
+
question: 'What is the weather like in tokyo?'
|
|
4
|
+
};
|
|
5
|
+
const functions = [
|
|
6
|
+
{
|
|
7
|
+
name: 'getCurrentWeather',
|
|
8
|
+
description: 'get the current weather for a location',
|
|
9
|
+
parameters: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
location: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'location to get weather for'
|
|
15
|
+
},
|
|
16
|
+
units: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: ['imperial', 'metric'],
|
|
19
|
+
default: 'imperial',
|
|
20
|
+
description: 'units to use'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
required: ['location']
|
|
24
|
+
},
|
|
25
|
+
func: async (args) => {
|
|
26
|
+
return `The weather in ${args.location} is 72 degrees`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
31
|
+
const cot = new ReAct(ai, `question:string -> answer:string`, {
|
|
32
|
+
functions
|
|
33
|
+
});
|
|
34
|
+
const res = await cot.forward(values);
|
|
35
|
+
console.log(res);
|
|
36
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../../src/examples/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAmB,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,GAAG;IACb,QAAQ,EAAE,oCAAoC;CAC/C,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB;QACE,IAAI,EAAE,mBAAmB;QACzB,WAAW,EAAE,wCAAwC;QACrD,UAAU,EAAE;YACV,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;iBAC3C;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC;oBAC5B,OAAO,EAAE,UAAU;oBACnB,WAAW,EAAE,cAAc;iBAC5B;aACF;YACD,QAAQ,EAAE,CAAC,UAAU,CAAC;SACvB;QAED,IAAI,EAAE,KAAK,EAAE,IAAmD,EAAE,EAAE;YAClE,OAAO,kBAAkB,IAAI,CAAC,QAAQ,gBAAgB,CAAC;QACzD,CAAC;KACF;CACF,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAC7E,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,kCAAkC,EAAE;IAC5D,SAAS;CACV,CAAC,CAAC;AACH,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACtC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AI, Route, Router } from '../index.js';
|
|
2
|
+
const customerSupport = new Route('customerSupport', [
|
|
3
|
+
'how can I return a product?',
|
|
4
|
+
'where is my order?',
|
|
5
|
+
'can you help me with a refund?',
|
|
6
|
+
'I need to update my shipping address',
|
|
7
|
+
'my product arrived damaged, what should I do?'
|
|
8
|
+
]);
|
|
9
|
+
const employeeHR = new Route('employeeHR', [
|
|
10
|
+
'how do I request time off?',
|
|
11
|
+
'where can I find the employee handbook?',
|
|
12
|
+
'who do I contact for IT support?',
|
|
13
|
+
'I have a question about my benefits',
|
|
14
|
+
'how do I log my work hours?'
|
|
15
|
+
]);
|
|
16
|
+
const salesInquiries = new Route('salesInquiries', [
|
|
17
|
+
'I want to buy your products',
|
|
18
|
+
'can you provide a quote?',
|
|
19
|
+
'what are the payment options?',
|
|
20
|
+
'how do I get a discount?',
|
|
21
|
+
'who can I speak with for a bulk order?'
|
|
22
|
+
]);
|
|
23
|
+
const technicalSupport = new Route('technicalSupport', [
|
|
24
|
+
'how do I install your software?',
|
|
25
|
+
'I’m having trouble logging in',
|
|
26
|
+
'can you help me configure my settings?',
|
|
27
|
+
'my application keeps crashing',
|
|
28
|
+
'how do I update to the latest version?'
|
|
29
|
+
]);
|
|
30
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
31
|
+
const router = new Router(ai);
|
|
32
|
+
await router.setRoutes([
|
|
33
|
+
customerSupport,
|
|
34
|
+
employeeHR,
|
|
35
|
+
salesInquiries,
|
|
36
|
+
technicalSupport
|
|
37
|
+
]);
|
|
38
|
+
const r1 = await router.forward('I need help with my order');
|
|
39
|
+
const r2 = await router.forward('I want to know more about the company');
|
|
40
|
+
const r3 = await router.forward('I need help installing your software');
|
|
41
|
+
const r4 = await router.forward('I did not receive my order on time');
|
|
42
|
+
const r5 = await router.forward('Where can I find info about our 401k');
|
|
43
|
+
console.log(r1 === 'salesInquiries' ? 'PASS' : 'FAIL: ' + r1);
|
|
44
|
+
console.log(r2 === 'salesInquiries' ? 'PASS' : 'FAIL: ' + r2);
|
|
45
|
+
console.log(r3 === 'technicalSupport' ? 'PASS' : 'FAIL: ' + r3);
|
|
46
|
+
console.log(r4 === 'customerSupport' ? 'PASS' : 'FAIL: ' + r4);
|
|
47
|
+
console.log(r5 === 'employeeHR' ? 'PASS' : 'FAIL: ' + r5);
|
|
48
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../../src/examples/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAmB,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,eAAe,GAAG,IAAI,KAAK,CAAC,iBAAiB,EAAE;IACnD,6BAA6B;IAC7B,oBAAoB;IACpB,gCAAgC;IAChC,sCAAsC;IACtC,+CAA+C;CAChD,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,YAAY,EAAE;IACzC,4BAA4B;IAC5B,yCAAyC;IACzC,kCAAkC;IAClC,qCAAqC;IACrC,6BAA6B;CAC9B,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,gBAAgB,EAAE;IACjD,6BAA6B;IAC7B,0BAA0B;IAC1B,+BAA+B;IAC/B,0BAA0B;IAC1B,wCAAwC;CACzC,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAC,kBAAkB,EAAE;IACrD,iCAAiC;IACjC,+BAA+B;IAC/B,wCAAwC;IACxC,+BAA+B;IAC/B,wCAAwC;CACzC,CAAC,CAAC;AAEH,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAE7E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;AAC9B,MAAM,MAAM,CAAC,SAAS,CAAC;IACrB,eAAe;IACf,UAAU;IACV,cAAc;IACd,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC7D,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC;AACzE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;AACxE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACtE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;AAExE,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;AAChE,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;AAC/D,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AI, ChainOfThought } from '../index.js';
|
|
2
|
+
// const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY } as OpenAIArgs);
|
|
3
|
+
const ai = AI('google-gemini', {
|
|
4
|
+
apiKey: process.env.GOOGLE_APIKEY
|
|
5
|
+
});
|
|
6
|
+
// setup the prompt program
|
|
7
|
+
const gen = new ChainOfThought(ai, `startNumber:number -> next10Numbers:number[]`);
|
|
8
|
+
// add a assertion to ensure that the number 5 is not in an output field
|
|
9
|
+
gen.addAssert(({ next10Numbers }) => {
|
|
10
|
+
return next10Numbers ? !next10Numbers.includes(5) : undefined;
|
|
11
|
+
}, 'Numbers 5 is not allowed');
|
|
12
|
+
// run the program with streaming enabled
|
|
13
|
+
const res = await gen.forward({ startNumber: 1 }, { stream: true, debug: true });
|
|
14
|
+
console.log('>', res);
|
|
15
|
+
//# sourceMappingURL=streaming1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming1.js","sourceRoot":"","sources":["../../../../src/examples/streaming1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAmB,MAAM,aAAa,CAAC;AAElE,gFAAgF;AAChF,MAAM,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE;IAC7B,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;CACpB,CAAC,CAAC;AAEjB,2BAA2B;AAC3B,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,EAAE,EACF,8CAA8C,CAC/C,CAAC;AAEF,wEAAwE;AACxE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,EAAyC,EAAE,EAAE;IACzE,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC,EAAE,0BAA0B,CAAC,CAAC;AAE/B,yCAAyC;AACzC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAC3B,EAAE,WAAW,EAAE,CAAC,EAAE,EAClB,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAC9B,CAAC;AAEF,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AI, ChainOfThought } from '../index.js';
|
|
2
|
+
// const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY } as OpenAIArgs);
|
|
3
|
+
const ai = AI('google-gemini', {
|
|
4
|
+
apiKey: process.env.GOOGLE_APIKEY
|
|
5
|
+
});
|
|
6
|
+
// setup the prompt program
|
|
7
|
+
const gen = new ChainOfThought(ai, `question:string -> answerInPoints:string`);
|
|
8
|
+
// add a assertion to ensure all lines start with a number and a dot.
|
|
9
|
+
gen.addStreamingAssert('answerInPoints', (value) => {
|
|
10
|
+
const re = /^\d+\./;
|
|
11
|
+
// split the value by lines, trim each line,
|
|
12
|
+
// filter out empty lines and check if all lines match the regex
|
|
13
|
+
return value
|
|
14
|
+
.split('\n')
|
|
15
|
+
.map((x) => x.trim())
|
|
16
|
+
.filter((x) => x.length > 0)
|
|
17
|
+
.every((x) => re.test(x));
|
|
18
|
+
}, 'Lines must start with a number and a dot. Eg: 1. This is a line.');
|
|
19
|
+
// run the program with streaming enabled
|
|
20
|
+
const res = await gen.forward({
|
|
21
|
+
question: 'Provide a list of optimizations to speedup LLM inference.'
|
|
22
|
+
}, { stream: true, debug: true });
|
|
23
|
+
console.log('>', res);
|
|
24
|
+
//# sourceMappingURL=streaming2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming2.js","sourceRoot":"","sources":["../../../../src/examples/streaming2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAmB,MAAM,aAAa,CAAC;AAElE,gFAAgF;AAChF,MAAM,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE;IAC7B,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;CACpB,CAAC,CAAC;AAEjB,2BAA2B;AAC3B,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAC;AAE/E,qEAAqE;AACrE,GAAG,CAAC,kBAAkB,CACpB,gBAAgB,EAChB,CAAC,KAAa,EAAE,EAAE;IAChB,MAAM,EAAE,GAAG,QAAQ,CAAC;IAEpB,4CAA4C;IAC5C,gEAAgE;IAChE,OAAO,KAAK;SACT,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC,EACD,kEAAkE,CACnE,CAAC;AAEF,yCAAyC;AACzC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAC3B;IACE,QAAQ,EAAE,2DAA2D;CACtE,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAC9B,CAAC;AAEF,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AI, ChainOfThought, OpenAIModel } from '../index.js';
|
|
2
|
+
const text = `The technological singularity—or simply the singularity[1]—is a hypothetical future point in time at which technological growth becomes uncontrollable and irreversible, resulting in unforeseeable changes to human civilization.[2][3] According to the most popular version of the singularity hypothesis, I.J. Good's intelligence explosion model, an upgradable intelligent agent will eventually enter a "runaway reaction" of self-improvement cycles, each new and more intelligent generation appearing more and more rapidly, causing an "explosion" in intelligence and resulting in a powerful superintelligence that qualitatively far surpasses all human intelligence.[4]`;
|
|
3
|
+
const ai = AI('openai', {
|
|
4
|
+
apiKey: process.env.OPENAI_APIKEY,
|
|
5
|
+
model: OpenAIModel.GPT35Turbo
|
|
6
|
+
});
|
|
7
|
+
ai.setOptions({ debug: true });
|
|
8
|
+
// const ai = AI('ollama', { model: 'nous-hermes2' });
|
|
9
|
+
const gen = new ChainOfThought(ai, `text -> shortSummary "summarize in 5 to 10 words"`);
|
|
10
|
+
gen.setExamples([
|
|
11
|
+
{
|
|
12
|
+
text: 'Mathematical platonism is a philosophical view that posits the existence of abstract mathematical objects that are independent of human thought and language. According to this view, mathematical entities such as numbers, shapes, and functions exist in a non-physical realm and can be discovered but not invented.',
|
|
13
|
+
shortSummary: 'A philosophy that suggests mathematical objects exist independently of human thought in a non-physical realm.'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
text: 'Quantum entanglement is a physical phenomenon occurring when pairs or groups of particles are generated, interact, or share spatial proximity in ways such that the quantum state of each particle cannot be described independently of the state of the others, even when the particles are separated by large distances. This leads to correlations between observable physical properties of the particles.',
|
|
17
|
+
shortSummary: 'A phenomenon where particles remain interconnected and the state of one affects the state of another, regardless of distance.'
|
|
18
|
+
}
|
|
19
|
+
]);
|
|
20
|
+
gen.addAssert(({ reason }) => {
|
|
21
|
+
if (!reason)
|
|
22
|
+
return true;
|
|
23
|
+
return !reason.includes('goat');
|
|
24
|
+
}, 'Reason should not contain "the"');
|
|
25
|
+
const res = await gen.forward({ text }, { modelConfig: { stream: true } });
|
|
26
|
+
console.log('>', res);
|
|
27
|
+
//# sourceMappingURL=summarize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../../src/examples/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,IAAI,GAAG,2pBAA2pB,CAAC;AAEzqB,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE;IACtB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;IACjC,KAAK,EAAE,WAAW,CAAC,UAAU;CAChB,CAAC,CAAC;AAEjB,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/B,sDAAsD;AAEtD,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,EAAE,EACF,mDAAmD,CACpD,CAAC;AACF,GAAG,CAAC,WAAW,CAAC;IACd;QACE,IAAI,EAAE,0TAA0T;QAChU,YAAY,EACV,+GAA+G;KAClH;IACD;QACE,IAAI,EAAE,gZAAgZ;QACtZ,YAAY,EACV,+HAA+H;KAClI;CACF,CAAC,CAAC;AAEH,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAgC,EAAE,EAAE;IACzD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC,EAAE,iCAAiC,CAAC,CAAC;AAEtC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AAE3E,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AI, DBManager, MemoryDB } from '../index.js';
|
|
2
|
+
/* cSpell:disable */
|
|
3
|
+
const text = `The technological singularity—or simply the singularity[1]—is a hypothetical future point in time at which technological growth becomes uncontrollable and irreversible, resulting in unforeseeable consequences for human civilization.[2][3] According to the most popular version of the singularity hypothesis, I. J. Good's intelligence explosion model, an upgradable intelligent agent will eventually enter a positive feedback loop of self-improvement cycles, each new and more intelligent generation appearing more and more rapidly, causing a rapid increase ("explosion") in intelligence which ultimately results in a powerful superintelligence that qualitatively far surpasses all human intelligence.[4]
|
|
4
|
+
|
|
5
|
+
One of the most successful early gastromancers was Eurykles, a prophet at Athens; gastromancers came to be referred to as Euryklides in his honour.[3] Other parts of the world also have a tradition of ventriloquism for ritual or religious purposes; historically there have been adepts of this practice among the Zulu, Inuit, and Māori peoples.[3]
|
|
6
|
+
`;
|
|
7
|
+
// Instantiate services
|
|
8
|
+
const ai = AI('openai', { apiKey: process.env.OPENAI_APIKEY });
|
|
9
|
+
const db = new MemoryDB();
|
|
10
|
+
const manager = new DBManager({ ai, db });
|
|
11
|
+
await manager.insert(text);
|
|
12
|
+
const res = await manager.query('John von Neumann on human intelligence and singularity.');
|
|
13
|
+
console.log(res);
|
|
14
|
+
//# sourceMappingURL=vectordb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectordb.js","sourceRoot":"","sources":["../../../../src/examples/vectordb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAmB,MAAM,aAAa,CAAC;AAEvE,oBAAoB;AACpB,MAAM,IAAI,GAAG;;;CAGZ,CAAC;AAEF,uBAAuB;AACvB,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAgB,CAAC,CAAC;AAC7E,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;AAE1B,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1C,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAE3B,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,KAAK,CAC7B,yDAAyD,CAC1D,CAAC;AACF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AITextFunction } from '../text/functions.js';
|
|
2
|
+
export declare const JSInterpreterFunction: (permissions?: readonly CodeInterpreterPermission[]) => AITextFunction;
|
|
3
|
+
export declare enum CodeInterpreterPermission {
|
|
4
|
+
FS = "fs",
|
|
5
|
+
NET = "net",
|
|
6
|
+
OS = "os",
|
|
7
|
+
CRYPTO = "crypto",
|
|
8
|
+
PROCESS = "process"
|
|
9
|
+
}
|
|
10
|
+
export declare const codeInterpreterJavascript: (code: string, permissions?: readonly CodeInterpreterPermission[]) => any;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as _crypto from 'crypto';
|
|
2
|
+
import * as _fs from 'fs';
|
|
3
|
+
import * as _http from 'http';
|
|
4
|
+
import * as _https from 'https';
|
|
5
|
+
import * as _os from 'os';
|
|
6
|
+
import * as _process from 'process';
|
|
7
|
+
import { runInNewContext } from 'vm';
|
|
8
|
+
export const JSInterpreterFunction = (permissions = []) => ({
|
|
9
|
+
name: 'jsInterpreter',
|
|
10
|
+
description: 'Run Javascript code',
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
code: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'JS code with a return value in the end.'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
required: ['code']
|
|
20
|
+
},
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
func: ({ code }) => {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
resolve(codeInterpreterJavascript(code, permissions));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export var CodeInterpreterPermission;
|
|
29
|
+
(function (CodeInterpreterPermission) {
|
|
30
|
+
CodeInterpreterPermission["FS"] = "fs";
|
|
31
|
+
CodeInterpreterPermission["NET"] = "net";
|
|
32
|
+
CodeInterpreterPermission["OS"] = "os";
|
|
33
|
+
CodeInterpreterPermission["CRYPTO"] = "crypto";
|
|
34
|
+
CodeInterpreterPermission["PROCESS"] = "process";
|
|
35
|
+
})(CodeInterpreterPermission || (CodeInterpreterPermission = {}));
|
|
36
|
+
export const codeInterpreterJavascript = (code, permissions = []
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
) => {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
const context = {
|
|
41
|
+
// require: require,
|
|
42
|
+
console: console
|
|
43
|
+
};
|
|
44
|
+
if (permissions.includes(CodeInterpreterPermission.FS)) {
|
|
45
|
+
context.fs = _fs;
|
|
46
|
+
}
|
|
47
|
+
if (permissions.includes(CodeInterpreterPermission.NET)) {
|
|
48
|
+
context.http = _http;
|
|
49
|
+
context.https = _https;
|
|
50
|
+
}
|
|
51
|
+
if (permissions.includes(CodeInterpreterPermission.OS)) {
|
|
52
|
+
context.os = _os;
|
|
53
|
+
}
|
|
54
|
+
if (permissions.includes(CodeInterpreterPermission.CRYPTO)) {
|
|
55
|
+
context.crypto = _crypto;
|
|
56
|
+
}
|
|
57
|
+
if (permissions.includes(CodeInterpreterPermission.PROCESS)) {
|
|
58
|
+
context.process = _process;
|
|
59
|
+
}
|
|
60
|
+
// executing code within the sandbox
|
|
61
|
+
return runInNewContext(`(function() { ${code} })()`, context);
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../../../src/funcs/code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,GAAG,MAAM,IAAI,CAAC;AAC1B,OAAO,KAAK,KAAK,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,IAAI,CAAC;AAC1B,OAAO,KAAK,QAAQ,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAIrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,cAAoD,EAAE,EACtC,EAAE,CAAC,CAAC;IACpB,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,yCAAyC;aACvD;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,CAAC;KACnB;IAED,8DAA8D;IAC9D,IAAI,EAAE,CAAC,EAAE,IAAI,EAA8B,EAAgB,EAAE;QAC3D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,OAAO,CAAC,yBAAyB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAN,IAAY,yBAMX;AAND,WAAY,yBAAyB;IACnC,sCAAS,CAAA;IACT,wCAAW,CAAA;IACX,sCAAS,CAAA;IACT,8CAAiB,CAAA;IACjB,gDAAmB,CAAA;AACrB,CAAC,EANW,yBAAyB,KAAzB,yBAAyB,QAMpC;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAY,EACZ,cAAoD,EAAE;AACtD,8DAA8D;EACzD,EAAE;IACP,8DAA8D;IAC9D,MAAM,OAAO,GAA2B;QACtC,oBAAoB;QACpB,OAAO,EAAE,OAAO;KACjB,CAAC;IAEF,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC;QACvD,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,GAAG,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;QACrB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC;QACvD,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3D,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5D,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,oCAAoC;IACpC,OAAO,eAAe,CAAC,iBAAiB,IAAI,OAAO,EAAE,OAAO,CAAC,CAAC;AAChE,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AITextFunction, AITextFunctionHandler } from '../text/functions.js';
|
|
2
|
+
import type { AIService, AIServiceActionOptions } from '../text/types.js';
|
|
3
|
+
export declare const EmbedAdapter: (ai: AIService, info: Readonly<{
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
argumentDescription: string;
|
|
7
|
+
}>, func: (args: readonly number[], extra?: Readonly<AIServiceActionOptions>) => Promise<any>) => AITextFunction;
|
|
8
|
+
export declare const embedAdapter: (ai: AIService, text: string, func: AITextFunctionHandler, extra?: Readonly<AIServiceActionOptions>) => Promise<any>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const EmbedAdapter = (ai, info, func) => ({
|
|
2
|
+
name: info.name,
|
|
3
|
+
description: info.description,
|
|
4
|
+
parameters: {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
text: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
description: info.argumentDescription
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
required: ['text']
|
|
13
|
+
},
|
|
14
|
+
func: ({ text }, extra
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
) => {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
resolve(embedAdapter(ai, text, func, extra));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export const embedAdapter = async (ai, text, func, extra
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
) => {
|
|
25
|
+
const embedRes = await ai.embed({ texts: [text] }, { sessionId: extra?.sessionId });
|
|
26
|
+
const embeds = embedRes.embeddings.at(0);
|
|
27
|
+
return func.length === 2 ? func(embeds, extra) : func(embeds);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../src/funcs/embed.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAa,EACb,IAIE,EACF,IAIiB,EACD,EAAE,CAAC,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,WAAW,EAAE,IAAI,CAAC,WAAW;IAC7B,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,mBAAmB;aACtC;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,CAAC;KACnB;IAED,IAAI,EAAE,CACJ,EAAE,IAAI,EAA8B,EACpC,KAAwC;IACxC,8DAA8D;MAChD,EAAE;QAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,EAAa,EACb,IAAY,EACZ,IAA2B,EAC3B,KAAwC;AACxC,8DAA8D;EAChD,EAAE;IAChB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,KAAK,CAC7B,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,EACjB,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAChC,CAAC;IACF,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEzC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/funcs/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './ai/index.js';
|
|
2
|
+
export * from './text/index.js';
|
|
3
|
+
export * from './prompts/index.js';
|
|
4
|
+
export * from './funcs/index.js';
|
|
5
|
+
export * from './types/index.js';
|
|
6
|
+
export * from './db/index.js';
|
|
7
|
+
export * from './dsp/index.js';
|
|
8
|
+
export * from './docs/index.js';
|
|
9
|
+
export * from './trace/index.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './ai/index.js';
|
|
2
|
+
export * from './text/index.js';
|
|
3
|
+
export * from './prompts/index.js';
|
|
4
|
+
export * from './funcs/index.js';
|
|
5
|
+
export * from './types/index.js';
|
|
6
|
+
export * from './db/index.js';
|
|
7
|
+
export * from './dsp/index.js';
|
|
8
|
+
export * from './docs/index.js';
|
|
9
|
+
export * from './trace/index.js';
|
|
10
|
+
/*
|
|
11
|
+
Transformers learn,
|
|
12
|
+
Attention guides, wisdom turns—
|
|
13
|
+
AI magic burns.
|
|
14
|
+
*/
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC;;;;EAIE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type GenerateOptions, Signature } from '../dsp/index.js';
|
|
2
|
+
import { type GenIn, type GenOut, type ITunable, type IUsable, Program, type ProgramForwardOptions } from '../dsp/program.js';
|
|
3
|
+
import { type AITextFunction } from '../text/index.js';
|
|
4
|
+
import type { AIService } from '../text/types.js';
|
|
5
|
+
export interface AgentI extends ITunable, IUsable {
|
|
6
|
+
getFunction(): AITextFunction;
|
|
7
|
+
}
|
|
8
|
+
export type AgentOptions = Omit<GenerateOptions, 'functions' | 'functionCall'>;
|
|
9
|
+
export declare class Agent<IN extends GenIn, OUT extends GenOut> extends Program<IN, OUT> implements AgentI {
|
|
10
|
+
private gen;
|
|
11
|
+
private name;
|
|
12
|
+
private description;
|
|
13
|
+
private subAgentList?;
|
|
14
|
+
private func;
|
|
15
|
+
constructor(ai: AIService, { name, description, signature, agents, functions }: Readonly<{
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
signature: Signature | string;
|
|
19
|
+
agents?: AgentI[];
|
|
20
|
+
functions?: AITextFunction[];
|
|
21
|
+
}>, options?: Readonly<AgentOptions>);
|
|
22
|
+
getFunction(): AITextFunction;
|
|
23
|
+
forward(values: IN, options?: Readonly<ProgramForwardOptions>): Promise<OUT>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Signature } from '../dsp/index.js';
|
|
2
|
+
import { Program } from '../dsp/program.js';
|
|
3
|
+
import {} from '../text/index.js';
|
|
4
|
+
import { SpanKind } from '../trace/index.js';
|
|
5
|
+
import { ChainOfThought } from './cot.js';
|
|
6
|
+
import { ReAct } from './react.js';
|
|
7
|
+
export class Agent extends Program {
|
|
8
|
+
gen;
|
|
9
|
+
name;
|
|
10
|
+
description;
|
|
11
|
+
subAgentList;
|
|
12
|
+
func;
|
|
13
|
+
constructor(ai, { name, description, signature, agents, functions }, options) {
|
|
14
|
+
super();
|
|
15
|
+
const sig = new Signature(signature);
|
|
16
|
+
const funcs = [
|
|
17
|
+
...(functions ?? []),
|
|
18
|
+
...(agents?.map((a) => a.getFunction()) ?? [])
|
|
19
|
+
];
|
|
20
|
+
const opt = {
|
|
21
|
+
promptTemplate: options?.promptTemplate,
|
|
22
|
+
asserts: options?.asserts,
|
|
23
|
+
functions: funcs
|
|
24
|
+
};
|
|
25
|
+
this.gen =
|
|
26
|
+
funcs.length > 0
|
|
27
|
+
? new ReAct(ai, sig, opt)
|
|
28
|
+
: new ChainOfThought(ai, sig, opt);
|
|
29
|
+
this.name = name;
|
|
30
|
+
this.description = description;
|
|
31
|
+
this.subAgentList = agents?.map((a) => a.getFunction().name).join(', ');
|
|
32
|
+
this.func = {
|
|
33
|
+
name: this.name,
|
|
34
|
+
description: this.description,
|
|
35
|
+
parameters: sig.toJSONSchema(),
|
|
36
|
+
func: () => this.forward
|
|
37
|
+
};
|
|
38
|
+
this.register(this.gen);
|
|
39
|
+
for (const agent of agents ?? []) {
|
|
40
|
+
this.register(agent);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
getFunction() {
|
|
44
|
+
return this.func;
|
|
45
|
+
}
|
|
46
|
+
async forward(values, options) {
|
|
47
|
+
if (!options?.tracer) {
|
|
48
|
+
return await this.gen.forward(values, options);
|
|
49
|
+
}
|
|
50
|
+
const attributes = {
|
|
51
|
+
['agent.name']: this.name,
|
|
52
|
+
['agent.description']: this.description,
|
|
53
|
+
['agent.subAgents']: this.subAgentList ?? 'none'
|
|
54
|
+
};
|
|
55
|
+
return await options?.tracer.startActiveSpan('Agent', {
|
|
56
|
+
kind: SpanKind.SERVER,
|
|
57
|
+
attributes
|
|
58
|
+
}, async (span) => {
|
|
59
|
+
const res = await this.gen.forward(values, options);
|
|
60
|
+
span.end();
|
|
61
|
+
return res;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../../src/prompts/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAKL,OAAO,EAER,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAuB,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQnC,MAAM,OAAO,KACX,SAAQ,OAAgB;IAGhB,GAAG,CAAmB;IAEtB,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,YAAY,CAAU;IACtB,IAAI,CAAiB;IAE7B,YACE,EAAa,EACb,EACE,IAAI,EACJ,WAAW,EACX,SAAS,EACT,MAAM,EACN,SAAS,EAOT,EACF,OAAgC;QAEhC,KAAK,EAAE,CAAC;QAER,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;QAErC,MAAM,KAAK,GAAqB;YAC9B,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;YACpB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;SAC/C,CAAC;QAEF,MAAM,GAAG,GAAG;YACV,cAAc,EAAE,OAAO,EAAE,cAAc;YACvC,OAAO,EAAE,OAAO,EAAE,OAAO;YACzB,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,IAAI,CAAC,GAAG;YACN,KAAK,CAAC,MAAM,GAAG,CAAC;gBACd,CAAC,CAAC,IAAI,KAAK,CAAU,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC;gBAClC,CAAC,CAAC,IAAI,cAAc,CAAU,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAEhD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG;YACV,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE;YAC9B,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO;SACzB,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAExB,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAEM,WAAW;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEe,KAAK,CAAC,OAAO,CAC3B,MAAU,EACV,OAAyC;QAEzC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,UAAU,GAAG;YACjB,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,IAAI;YACzB,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC,WAAW;YACvC,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC,YAAY,IAAI,MAAM;SACjD,CAAC;QAEF,OAAO,MAAM,OAAO,EAAE,MAAM,CAAC,eAAe,CAC1C,OAAO,EACP;YACE,IAAI,EAAE,QAAQ,CAAC,MAAM;YACrB,UAAU;SACX,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;YACb,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,OAAO,GAAG,CAAC;QACb,CAAC,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Generate, type GenerateOptions } from '../dsp/generate.js';
|
|
2
|
+
import type { GenIn, GenOut } from '../dsp/program.js';
|
|
3
|
+
import { Signature } from '../dsp/sig.js';
|
|
4
|
+
import type { AIService } from '../text/types.js';
|
|
5
|
+
export declare class ChainOfThought<IN extends GenIn = GenIn, OUT extends GenOut = GenOut> extends Generate<IN, OUT & {
|
|
6
|
+
reason: string;
|
|
7
|
+
}> {
|
|
8
|
+
constructor(ai: AIService, signature: Readonly<Signature | string>, options?: Readonly<GenerateOptions>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Generate } from '../dsp/generate.js';
|
|
2
|
+
import { Signature } from '../dsp/sig.js';
|
|
3
|
+
export class ChainOfThought extends Generate {
|
|
4
|
+
constructor(ai, signature, options) {
|
|
5
|
+
const sig = new Signature(signature);
|
|
6
|
+
const description = `Let's work this out in a step by step way in order to ensure we have the right answer.`;
|
|
7
|
+
sig.setOutputFields([
|
|
8
|
+
{
|
|
9
|
+
name: 'reason',
|
|
10
|
+
description
|
|
11
|
+
},
|
|
12
|
+
...sig.getOutputFields()
|
|
13
|
+
]);
|
|
14
|
+
super(ai, sig, options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=cot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cot.js","sourceRoot":"","sources":["../../../../src/prompts/cot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,OAAO,cAGX,SAAQ,QAAsC;IAC9C,YACE,EAAa,EACb,SAAuC,EACvC,OAAmC;QAEnC,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;QACrC,MAAM,WAAW,GAAG,wFAAwF,CAAC;QAE7G,GAAG,CAAC,eAAe,CAAC;YAClB;gBACE,IAAI,EAAE,QAAQ;gBACd,WAAW;aACZ;YACD,GAAG,GAAG,CAAC,eAAe,EAAE;SACzB,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/prompts/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|