From 7aaff8f5633ba8c4404ff7e71694e9aad138c348 Mon Sep 17 00:00:00 2001 From: Dan Selman Date: Fri, 24 May 2024 12:26:06 +0100 Subject: [PATCH] feat: logging Signed-off-by: Dan Selman --- docs/README.md | 1 + docs/classes/Conversation.md | 4 +- docs/classes/GraphModel.md | 40 +++++++------- docs/functions/getOpenAiEmbedding.md | 2 +- docs/type-aliases/Context.md | 2 +- docs/type-aliases/EmbeddingCacheNode.md | 2 +- docs/type-aliases/EmbeddingFunction.md | 2 +- docs/type-aliases/FullTextIndex.md | 2 +- docs/type-aliases/GraphModelOptions.md | 2 +- docs/type-aliases/GraphNodeProperties.md | 2 +- docs/type-aliases/Logger.md | 67 ++++++++++++++++++++++-- docs/type-aliases/PropertyBag.md | 2 +- docs/type-aliases/SimilarityResult.md | 2 +- docs/type-aliases/ToolResponse.md | 2 +- docs/type-aliases/VectorIndex.md | 2 +- docs/variables/ConsoleLogger.md | 13 +++++ docs/variables/EMBEDDINGS_MAGIC.md | 2 +- package-lock.json | 13 ++--- package.json | 1 + src/ConsoleLogger.ts | 29 ++++++++++ src/demo/index.ts | 45 ++++++++-------- src/functions.ts | 6 +-- src/graphmodel.ts | 36 ++++++------- src/index.ts | 4 +- src/types.ts | 11 +++- 25 files changed, 203 insertions(+), 91 deletions(-) create mode 100644 docs/variables/ConsoleLogger.md create mode 100644 src/ConsoleLogger.ts diff --git a/docs/README.md b/docs/README.md index 9bdc20f..8eb918b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,6 +25,7 @@ ## Variables +- [ConsoleLogger](variables/ConsoleLogger.md) - [EMBEDDINGS\_MAGIC](variables/EMBEDDINGS_MAGIC.md) ## Functions diff --git a/docs/classes/Conversation.md b/docs/classes/Conversation.md index 52d9589..6dfe693 100644 --- a/docs/classes/Conversation.md +++ b/docs/classes/Conversation.md @@ -28,7 +28,7 @@ Creates a new Conversation #### Source -[Conversation.ts:22](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/Conversation.ts#L22) +[Conversation.ts:22](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/Conversation.ts#L22) ## Properties @@ -63,4 +63,4 @@ the final result message #### Source -[Conversation.ts:35](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/Conversation.ts#L35) +[Conversation.ts:35](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/Conversation.ts#L35) diff --git a/docs/classes/GraphModel.md b/docs/classes/GraphModel.md index 717c17c..ff440c6 100644 --- a/docs/classes/GraphModel.md +++ b/docs/classes/GraphModel.md @@ -31,7 +31,7 @@ Creates a new instance of GraphModel #### Source -[graphmodel.ts:24](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L24) +[graphmodel.ts:24](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L24) ## Properties @@ -65,7 +65,7 @@ the query results #### Source -[graphmodel.ts:459](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L459) +[graphmodel.ts:459](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L459) *** @@ -87,7 +87,7 @@ Closes a database context. #### Source -[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L67) +[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L67) *** @@ -103,7 +103,7 @@ Connects to Neo4J #### Source -[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L38) +[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L38) *** @@ -119,7 +119,7 @@ Create Neo4J constraints for the model #### Source -[graphmodel.ts:192](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L192) +[graphmodel.ts:192](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L192) *** @@ -135,7 +135,7 @@ Create fulltext indexes for the model #### Source -[graphmodel.ts:232](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L232) +[graphmodel.ts:232](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L232) *** @@ -152,7 +152,7 @@ for the model #### Source -[graphmodel.ts:183](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L183) +[graphmodel.ts:183](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L183) *** @@ -168,7 +168,7 @@ Create vector indexes for the model #### Source -[graphmodel.ts:209](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L209) +[graphmodel.ts:209](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L209) *** @@ -184,7 +184,7 @@ Delete all nodes/edges in the graph #### Source -[graphmodel.ts:254](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L254) +[graphmodel.ts:254](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L254) *** @@ -210,7 +210,7 @@ the result #### Source -[graphmodel.ts:351](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L351) +[graphmodel.ts:351](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L351) *** @@ -226,7 +226,7 @@ Drop all Neo4J indexes for the model. #### Source -[graphmodel.ts:154](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L154) +[graphmodel.ts:154](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L154) *** @@ -252,7 +252,7 @@ the items #### Source -[graphmodel.ts:491](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L491) +[graphmodel.ts:491](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L491) *** @@ -270,7 +270,7 @@ an array of OpenAI tool definitions #### Source -[graphmodel.ts:582](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L582) +[graphmodel.ts:582](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L582) *** @@ -299,7 +299,7 @@ the graph node #### Source -[graphmodel.ts:328](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L328) +[graphmodel.ts:328](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L328) *** @@ -328,7 +328,7 @@ the source node #### Source -[graphmodel.ts:366](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L366) +[graphmodel.ts:366](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L366) *** @@ -353,7 +353,7 @@ a promise to a Context for the database. #### Source -[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L55) +[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L55) *** @@ -379,7 +379,7 @@ the query results #### Source -[graphmodel.ts:301](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L301) +[graphmodel.ts:301](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L301) *** @@ -406,7 +406,7 @@ an array of similar nodes, up to the count limit #### Source -[graphmodel.ts:425](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L425) +[graphmodel.ts:425](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L425) *** @@ -431,7 +431,7 @@ Performs a similarity search on nodes with text content #### Source -[graphmodel.ts:270](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L270) +[graphmodel.ts:270](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L270) *** @@ -455,4 +455,4 @@ the Cypher query #### Source -[graphmodel.ts:448](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L448) +[graphmodel.ts:448](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/graphmodel.ts#L448) diff --git a/docs/functions/getOpenAiEmbedding.md b/docs/functions/getOpenAiEmbedding.md index 9aa55c8..56a1a0d 100644 --- a/docs/functions/getOpenAiEmbedding.md +++ b/docs/functions/getOpenAiEmbedding.md @@ -25,4 +25,4 @@ a promise to an array of numbers ## Source -[functions.ts:12](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/functions.ts#L12) +[functions.ts:12](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/functions.ts#L12) diff --git a/docs/type-aliases/Context.md b/docs/type-aliases/Context.md index 90a89c8..70a36b1 100644 --- a/docs/type-aliases/Context.md +++ b/docs/type-aliases/Context.md @@ -18,4 +18,4 @@ Runtime context ## Source -[types.ts:30](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L30) +[types.ts:30](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L30) diff --git a/docs/type-aliases/EmbeddingCacheNode.md b/docs/type-aliases/EmbeddingCacheNode.md index 777d193..8336bf8 100644 --- a/docs/type-aliases/EmbeddingCacheNode.md +++ b/docs/type-aliases/EmbeddingCacheNode.md @@ -26,4 +26,4 @@ A Node type that is used to cache vector embeddings ## Source -[types.ts:37](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L37) +[types.ts:37](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L37) diff --git a/docs/type-aliases/EmbeddingFunction.md b/docs/type-aliases/EmbeddingFunction.md index 07632eb..1d5728a 100644 --- a/docs/type-aliases/EmbeddingFunction.md +++ b/docs/type-aliases/EmbeddingFunction.md @@ -23,4 +23,4 @@ vector embeddings for text ## Source -[types.ts:66](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L66) +[types.ts:66](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L66) diff --git a/docs/type-aliases/FullTextIndex.md b/docs/type-aliases/FullTextIndex.md index 9b25945..8e07c6d 100644 --- a/docs/type-aliases/FullTextIndex.md +++ b/docs/type-aliases/FullTextIndex.md @@ -18,4 +18,4 @@ Definition of a full text index over some properties ## Source -[types.ts:23](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L23) +[types.ts:23](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L23) diff --git a/docs/type-aliases/GraphModelOptions.md b/docs/type-aliases/GraphModelOptions.md index 79c7b51..4da1c2c 100644 --- a/docs/type-aliases/GraphModelOptions.md +++ b/docs/type-aliases/GraphModelOptions.md @@ -38,4 +38,4 @@ Graph model options, used to configure Concerto Graph ## Source -[types.ts:78](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L78) +[types.ts:87](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L87) diff --git a/docs/type-aliases/GraphNodeProperties.md b/docs/type-aliases/GraphNodeProperties.md index 4920450..7f613b0 100644 --- a/docs/type-aliases/GraphNodeProperties.md +++ b/docs/type-aliases/GraphNodeProperties.md @@ -12,4 +12,4 @@ The properties allowed on graph nodes ## Source -[types.ts:60](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L60) +[types.ts:60](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L60) diff --git a/docs/type-aliases/Logger.md b/docs/type-aliases/Logger.md index 3d74c25..14f53a7 100644 --- a/docs/type-aliases/Logger.md +++ b/docs/type-aliases/Logger.md @@ -12,15 +12,76 @@ Function signature for a logger ## Type declaration +### error() + +> **error**: (`message`?, ...`optionalParams`) => `void` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `message`? | `any` | +| ...`optionalParams`? | `any`[] | + +#### Returns + +`void` + +### info() + +> **info**: (`message`?, ...`optionalParams`) => `void` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `message`? | `any` | +| ...`optionalParams`? | `any`[] | + +#### Returns + +`void` + ### log() -> **log**: (`text`) => `void` +> **log**: (`message`?, ...`optionalParams`) => `void` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `message`? | `any` | +| ...`optionalParams`? | `any`[] | + +#### Returns + +`void` + +### success() + +> **success**: (`message`?, ...`optionalParams`) => `void` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `message`? | `any` | +| ...`optionalParams`? | `any`[] | + +#### Returns + +`void` + +### warn() + +> **warn**: (`message`?, ...`optionalParams`) => `void` #### Parameters | Parameter | Type | | :------ | :------ | -| `text` | `string` | +| `message`? | `any` | +| ...`optionalParams`? | `any`[] | #### Returns @@ -28,4 +89,4 @@ Function signature for a logger ## Source -[types.ts:71](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L71) +[types.ts:71](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L71) diff --git a/docs/type-aliases/PropertyBag.md b/docs/type-aliases/PropertyBag.md index 47baed3..72fb6cf 100644 --- a/docs/type-aliases/PropertyBag.md +++ b/docs/type-aliases/PropertyBag.md @@ -12,4 +12,4 @@ A untyped set of properties ## Source -[types.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L55) +[types.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L55) diff --git a/docs/type-aliases/SimilarityResult.md b/docs/type-aliases/SimilarityResult.md index c558e96..793df6c 100644 --- a/docs/type-aliases/SimilarityResult.md +++ b/docs/type-aliases/SimilarityResult.md @@ -26,4 +26,4 @@ Result of a vector similarity search ## Source -[types.ts:46](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L46) +[types.ts:46](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L46) diff --git a/docs/type-aliases/ToolResponse.md b/docs/type-aliases/ToolResponse.md index e49a8db..8d33f4f 100644 --- a/docs/type-aliases/ToolResponse.md +++ b/docs/type-aliases/ToolResponse.md @@ -26,4 +26,4 @@ The string that we should compute embedding vectors for ## Source -[types.ts:90](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L90) +[types.ts:99](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L99) diff --git a/docs/type-aliases/VectorIndex.md b/docs/type-aliases/VectorIndex.md index 2cb0867..008402e 100644 --- a/docs/type-aliases/VectorIndex.md +++ b/docs/type-aliases/VectorIndex.md @@ -26,4 +26,4 @@ Definition of a vector (embeddings) index ## Source -[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L14) +[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L14) diff --git a/docs/variables/ConsoleLogger.md b/docs/variables/ConsoleLogger.md new file mode 100644 index 0000000..e3dae68 --- /dev/null +++ b/docs/variables/ConsoleLogger.md @@ -0,0 +1,13 @@ +[**@accordproject/concerto-graph**](../README.md) • **Docs** + +*** + +[@accordproject/concerto-graph](../README.md) / ConsoleLogger + +# Variable: ConsoleLogger + +> `const` **ConsoleLogger**: [`Logger`](../type-aliases/Logger.md) + +## Source + +[ConsoleLogger.ts:4](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/ConsoleLogger.ts#L4) diff --git a/docs/variables/EMBEDDINGS_MAGIC.md b/docs/variables/EMBEDDINGS_MAGIC.md index 28261d5..81f35b7 100644 --- a/docs/variables/EMBEDDINGS_MAGIC.md +++ b/docs/variables/EMBEDDINGS_MAGIC.md @@ -14,4 +14,4 @@ that include semantic embeddings ## Source -[types.ts:9](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L9) +[types.ts:9](https://github.com/accordproject/lab-concerto-graph/blob/8e78133b0c3a8cb9cb393d291d79fc66c6e6c373/src/types.ts#L9) diff --git a/package-lock.json b/package-lock.json index cb192fa..0ca9c7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "@accordproject/concerto-graph", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@accordproject/concerto-graph", - "version": "1.1.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@accordproject/concerto-core": "^3.16.8", + "chalk": "^4", "neo4j-driver": "^5.15.0", "openai": "^4.20.1", "uuid": "^9.0.1" @@ -3244,7 +3245,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -3792,7 +3792,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -3915,7 +3914,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -3926,8 +3924,7 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/colors": { "version": "1.4.0", @@ -5258,7 +5255,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "engines": { "node": ">=8" } @@ -8061,7 +8057,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "dependencies": { "has-flag": "^4.0.0" }, diff --git a/package.json b/package.json index 2e323d6..39ecd34 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ }, "dependencies": { "@accordproject/concerto-core": "^3.16.8", + "chalk": "^4", "neo4j-driver": "^5.15.0", "openai": "^4.20.1", "uuid": "^9.0.1" diff --git a/src/ConsoleLogger.ts b/src/ConsoleLogger.ts new file mode 100644 index 0000000..a0f88f9 --- /dev/null +++ b/src/ConsoleLogger.ts @@ -0,0 +1,29 @@ +import { Logger } from './types'; +import chalk from 'chalk'; + +export const ConsoleLogger = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + log: (message?: any, ...optionalParams: any[]) => { + console.log(message, ...optionalParams); + }, + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + info: (message?: any, ...optionalParams: any[]) => { + console.log(chalk.grey(message, ...optionalParams)); + }, + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + success: (message?: any, ...optionalParams: any[]) => { + console.info(chalk.green(message, ...optionalParams)); + }, + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: (message?: any, ...optionalParams: any[]) => { + console.error(chalk.bgBlack.red(message, ...optionalParams)); + }, + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + warn: (message?: any, ...optionalParams: any[]) => { + console.warn(chalk.bgBlack.yellow(message, ...optionalParams)); + } +} as Logger; diff --git a/src/demo/index.ts b/src/demo/index.ts index 5d03321..e13c269 100644 --- a/src/demo/index.ts +++ b/src/demo/index.ts @@ -1,4 +1,4 @@ -import { GraphModel, GraphModelOptions, getOpenAiEmbedding } from '..' +import { GraphModel, GraphModelOptions, getOpenAiEmbedding, ConsoleLogger } from '..' import { Conversation } from '../Conversation'; const NS = 'demo.graph@1.0.0'; @@ -64,11 +64,12 @@ concept Movie extends GraphNode { `; async function run() { + const logger = ConsoleLogger; const options: GraphModelOptions = { NEO4J_USER: process.env.NEO4J_USER, NEO4J_PASS: process.env.NEO4J_PASS, NEO4J_URL: process.env.NEO4J_URL, - logger: console, + logger, logQueries: false, embeddingFunction: process.env.OPENAI_API_KEY ? getOpenAiEmbedding : undefined } @@ -96,7 +97,7 @@ async function run() { const addressBook = { 'Dan': 'dan@example.com', 'Isaac': 'isaac@example.com' - }; + }; await graphModel.mergeNode(transaction, 'Movie', { identifier: 'Brazil', summary: 'The film centres on Sam Lowry, a low-ranking bureaucrat trying to find a woman who appears in his dreams while he is working in a mind-numbing job and living in a small apartment, set in a dystopian world in which there is an over-reliance on poorly maintained (and rather whimsical) machines' }); await graphModel.mergeNode(transaction, 'Movie', { identifier: 'The Man Who Killed Don Quixote', summary: 'Instead of a literal adaptation, Gilliam\'s film was about "an old, retired, and slightly kooky nobleman named Alonso Quixano".' }); await graphModel.mergeNode(transaction, 'Movie', { identifier: 'Fear and Loathing in Las Vegas', summary: 'Duke, under the influence of mescaline, complains of a swarm of giant bats, and inventories their drug stash. They pick up a young hitchhiker and explain their mission: Duke has been assigned by a magazine to cover the Mint 400 motorcycle race in Las Vegas. They bought excessive drugs for the trip, and rented a red Chevrolet Impala convertible.' }); @@ -129,63 +130,63 @@ async function run() { }); { const fullTextSearch = 'bats'; - console.log(`Full text search for movies with: '${fullTextSearch}'`); + logger.log(`Full text search for movies with: '${fullTextSearch}'`); const results = await graphModel.fullTextQuery('Movie', fullTextSearch, 2); - console.log(results); + logger.success(JSON.stringify(results, null, 2)); } if (process.env.OPENAI_API_KEY) { const search = 'working in a boring job and looking for love.'; { - console.log(`Searching for movies related to: '${search}'`); + logger.log(`Searching for movies related to: '${search}'`); const results = await graphModel.similarityQuery('Movie', 'summary', search, 3); - console.log(results); + logger.success(JSON.stringify(results, null, 2)); } { const chat = 'Which director has directed both Johnny Depp and Jonathan Pryce, but not necessarily in the same movie?'; - console.log(`Chat with data: ${chat}`); + logger.log(`Chat with data: ${chat}`); const result = await graphModel.chatWithData(chat); - console.log(JSON.stringify(result, null, 2)); + logger.success(JSON.stringify(result, null, 2)); } { const chat = `Which director has directed a Comedy that is about the concepts of ${search}? Return a single movie.`; - console.log(chat); + logger.log(chat); const result = await graphModel.chatWithData(chat); - console.log(JSON.stringify(result, null, 2)); + logger.success(JSON.stringify(result, null, 2)); } { const chat = `Which actor starred in a movie about the concepts 'journalism, hitchhiking and drugs in Las Vegas'? Return the single most likely result.`; - console.log(chat); + logger.log(chat); const result = await graphModel.chatWithData(chat); - console.log(JSON.stringify(result, null, 2)); + logger.success(JSON.stringify(result, null, 2)); } { const chat = `What is the shortest path between the director Terry Gilliam and actor Johnny Depp?`; - console.log(chat); + logger.log(chat); const result = await graphModel.chatWithData(chat); - console.log(result); + logger.success(JSON.stringify(result, null, 2)); } { const convo = new Conversation(graphModel); let result = await convo.appendUserMessage('Tell me a joke about actors'); - console.log(result); + logger.success(result); result = await convo.appendUserMessage('Which actor acted in Fear and Loathing in Las Vegas?'); - console.log(result); + logger.success(result); result = await convo.appendUserMessage('Who directed that movie?'); - console.log(result); + logger.success(result); result = await convo.appendUserMessage('How many movies do we have?'); - console.log(result); + logger.success(result); } - console.log('done'); + logger.log('done'); process.exit(); } await graphModel.closeSession(context); - console.log('done'); + logger.log('done'); process.exit(); } @@ -193,5 +194,5 @@ try { run(); } catch (err) { - console.log(err); + ConsoleLogger.error(err); } diff --git a/src/functions.ts b/src/functions.ts index 0acc4d1..e3abdd9 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -1,7 +1,7 @@ import * as crypto from 'crypto' import OpenAI from "openai"; import { EMBEDDINGS_MAGIC, GraphModelOptions, PropertyBag } from './types'; -import { OPENAI_MODEL, OPENAI_TOOLS, TOOL_GET_EMBEDDINGS_NAME, getPrompt } from './prompt'; +import { OPENAI_MODEL, OPENAI_TOOLS, getPrompt } from './prompt'; /** * Computes the vector embeddings for a text string. @@ -47,12 +47,12 @@ export async function textToCypher(options: GraphModelOptions, text: string, cto const result = await runner.finalContent(); // now we actually calling the embedding function and replace the EMBEDDINGS_MAGIC if (result && options.embeddingFunction && result.indexOf(EMBEDDINGS_MAGIC) > 0) { - options.logger?.log(`Replacing embeddings: ${result} with embeddings for: '${query}'`); + options.logger?.info(`Replacing embeddings: ${result} with embeddings for: '${query}'`); const embeddings = await options.embeddingFunction(query); return result.replaceAll(EMBEDDINGS_MAGIC, JSON.stringify(embeddings)); } else { - options.logger?.log('No EMBEDDINGS_MAGIC found.'); + options.logger?.info('No EMBEDDINGS_MAGIC found.'); } return result; } diff --git a/src/graphmodel.ts b/src/graphmodel.ts index eafbaf5..b574cb2 100644 --- a/src/graphmodel.ts +++ b/src/graphmodel.ts @@ -40,8 +40,8 @@ export class GraphModel { this.driver = neo4j.driver(this.options.NEO4J_URL ?? 'bolt://localhost:7687', neo4j.auth.basic(this.options.NEO4J_USER ?? 'neo4j', this.options.NEO4J_PASS ?? 'password')); const serverInfo = await this.driver.getServerInfo() - this.options.logger?.log('Connection established') - this.options.logger?.log(JSON.stringify(serverInfo)) + this.options.logger?.info('Connection established') + this.options.logger?.info(JSON.stringify(serverInfo)) } } @@ -152,7 +152,7 @@ export class GraphModel { * Drop all Neo4J indexes for the model. */ async dropIndexes() { - this.options.logger?.log('Dropping indexes...'); + this.options.logger?.info('Dropping indexes...'); const { session } = await this.openSession(); await session?.executeWrite(async tx => { const graphNodes = this.getGraphNodeDeclarations(); @@ -173,7 +173,7 @@ export class GraphModel { } }) await session.close(); - this.options.logger?.log('Drop indexes completed'); + this.options.logger?.info('Drop indexes completed'); } /** @@ -190,7 +190,7 @@ export class GraphModel { * Create Neo4J constraints for the model */ async createConstraints() { - this.options.logger?.log('Creating constraints...'); + this.options.logger?.info('Creating constraints...'); const { session } = await this.openSession(); await session.executeWrite(async tx => { const graphNodes = this.getGraphNodeDeclarations(); @@ -200,14 +200,14 @@ export class GraphModel { } }) await session.close(); - this.options.logger?.log('Create constraints completed'); + this.options.logger?.info('Create constraints completed'); } /** * Create vector indexes for the model */ async createVectorIndexes() { - this.options.logger?.log('Creating vector indexes...'); + this.options.logger?.info('Creating vector indexes...'); const { session } = await this.openSession(); await session.executeWrite(async tx => { const graphNodes = this.getGraphNodeDeclarations(); @@ -223,14 +223,14 @@ export class GraphModel { } }) await session.close(); - this.options.logger?.log('Create vector indexes completed'); + this.options.logger?.info('Create vector indexes completed'); } /** * Create fulltext indexes for the model */ async createFullTextIndexes() { - this.options.logger?.log('Creating full text indexes...'); + this.options.logger?.info('Creating full text indexes...'); const { session } = await this.openSession(); await session.executeWrite(async tx => { const graphNodes = this.getGraphNodeDeclarations(); @@ -245,7 +245,7 @@ export class GraphModel { } }) await session.close(); - this.options.logger?.log('Create full text indexes completed'); + this.options.logger?.info('Create full text indexes completed'); } /** @@ -300,7 +300,7 @@ export class GraphModel { */ async query(cypher: string, parameters?: PropertyBag, tx?: ManagedTransaction) { if (this.options.logQueries) { - this.options.logger?.log(cypher); + this.options.logger?.info(cypher); } if (tx) { return tx.run(cypher, parameters) @@ -398,15 +398,15 @@ export class GraphModel { const queryResult = await this.query('MATCH (n:EmbeddingCacheNode{identifier:$id}) RETURN n', { id: embeddingId }, transaction); if (queryResult && queryResult.records.length > 0) { - this.options.logger?.log('EmbeddingCacheNode cache hit'); + this.options.logger?.info('EmbeddingCacheNode cache hit'); const node = queryResult.records[0].get('n'); return { $class: `${ROOT_NAMESPACE}.EmbeddingCacheNode`, ...node.properties }; } else if (this.options.embeddingFunction) { - this.options.logger?.log('EmbeddingCacheNode cache miss'); + this.options.logger?.info('EmbeddingCacheNode cache miss'); const embedding = await this.options.embeddingFunction(text); const nodeProperties = { identifier: embeddingId, embedding, content: text }; await this.mergeNode(transaction, `${ROOT_NAMESPACE}.EmbeddingCacheNode`, nodeProperties); - this.options.logger?.log(`Created cache node ${embeddingId}`); + this.options.logger?.info(`Created cache node ${embeddingId}`); return { $class: `${ROOT_NAMESPACE}.EmbeddingCacheNode`, ...nodeProperties }; } else { @@ -434,7 +434,7 @@ export class GraphModel { return this.similarityQueryFromEmbedding(typeName, propertyName, textContentNode.embedding, count); } catch (err) { - this.options.logger?.log((err as object).toString()); + this.options.logger?.error((err as object).toString()); transaction?.rollback(); throw err; } @@ -459,7 +459,7 @@ export class GraphModel { async chatWithData(text: string) { const cypher = await this.textToCypher(text); if (cypher) { - this.options.logger?.log(`Generated Cypher: ${cypher}`); + this.options.logger?.info(`Generated Cypher: ${cypher}`); const context = await this.openSession(); const transaction = await context.session.beginTransaction(); try { @@ -473,7 +473,7 @@ export class GraphModel { }) : []; } catch (err) { - this.options.logger?.log((err as object).toString()); + this.options.logger?.error((err as object).toString()); transaction?.rollback(); throw err; } @@ -511,7 +511,7 @@ export class GraphModel { }) : []; } catch (err) { - this.options.logger?.log((err as object).toString()); + this.options.logger?.error((err as object).toString()); throw err; } } diff --git a/src/index.ts b/src/index.ts index 997869e..3d397cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,12 @@ import { Conversation } from "./Conversation"; import { getOpenAiEmbedding } from "./functions"; import { GraphModel } from "./graphmodel"; +import { ConsoleLogger } from './ConsoleLogger'; export * from './types.js'; export { getOpenAiEmbedding, GraphModel, - Conversation + Conversation, + ConsoleLogger, } \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index ce78bb4..deaea76 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,7 +69,16 @@ export type EmbeddingFunction = (text: string) => Promise>; * Function signature for a logger */ export type Logger = { - log: (text: string) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + info: (message?: any, ...optionalParams: any[]) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + log: (message?: any, ...optionalParams: any[]) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + success: (message?: any, ...optionalParams: any[]) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: (message?: any, ...optionalParams: any[]) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + warn: (message?: any, ...optionalParams: any[]) => void; } /**