diff --git a/README.md b/README.md index dd25394..037d353 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,12 @@ you to ask follow-up questions. This capability exposes the GraphModel as an Ope allowing the LLM to call into the GraphModel to answer questions. ```typescript - const convo = new Conversation(graphModel); + const convo = new Conversation(graphModel, { + toolOptions: { + getById: true, + chatWithData: true + } + }); let result = await convo.appendUserMessage('Tell me a joke about actors'); console.log(result); result = await convo.appendUserMessage('Which actor acted in Fear and Loathing in Las Vegas?'); diff --git a/docs/README.md b/docs/README.md index 8eb918b..4adba03 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,6 +12,7 @@ ## Type Aliases - [Context](type-aliases/Context.md) +- [ConversationOptions](type-aliases/ConversationOptions.md) - [EmbeddingCacheNode](type-aliases/EmbeddingCacheNode.md) - [EmbeddingFunction](type-aliases/EmbeddingFunction.md) - [FullTextIndex](type-aliases/FullTextIndex.md) @@ -20,6 +21,7 @@ - [Logger](type-aliases/Logger.md) - [PropertyBag](type-aliases/PropertyBag.md) - [SimilarityResult](type-aliases/SimilarityResult.md) +- [ToolOptions](type-aliases/ToolOptions.md) - [ToolResponse](type-aliases/ToolResponse.md) - [VectorIndex](type-aliases/VectorIndex.md) diff --git a/docs/classes/Conversation.md b/docs/classes/Conversation.md index 3467610..a755516 100644 --- a/docs/classes/Conversation.md +++ b/docs/classes/Conversation.md @@ -12,7 +12,7 @@ An LLM conversation about a GraphModel ### new Conversation() -> **new Conversation**(`graphModel`): [`Conversation`](Conversation.md) +> **new Conversation**(`graphModel`, `options`): [`Conversation`](Conversation.md) Creates a new Conversation @@ -21,6 +21,7 @@ Creates a new Conversation | Parameter | Type | Description | | :------ | :------ | :------ | | `graphModel` | [`GraphModel`](GraphModel.md) | the graph model for the conversation | +| `options` | [`ConversationOptions`](../type-aliases/ConversationOptions.md) | - | #### Returns @@ -28,7 +29,7 @@ Creates a new Conversation #### Source -[Conversation.ts:22](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/Conversation.ts#L22) +[Conversation.ts:23](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/Conversation.ts#L23) ## Properties @@ -63,4 +64,4 @@ the final result message #### Source -[Conversation.ts:35](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/Conversation.ts#L35) +[Conversation.ts:36](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/Conversation.ts#L36) diff --git a/docs/classes/GraphModel.md b/docs/classes/GraphModel.md index f8fb821..c4af80a 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/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L24) +[graphmodel.ts:24](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L24) ## Properties @@ -65,7 +65,7 @@ the query results #### Source -[graphmodel.ts:493](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L493) +[graphmodel.ts:493](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L493) *** @@ -87,7 +87,7 @@ Closes a database context. #### Source -[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L67) +[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L67) *** @@ -103,7 +103,7 @@ Connects to Neo4J #### Source -[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L38) +[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L38) *** @@ -119,7 +119,7 @@ Create Neo4J constraints for the model #### Source -[graphmodel.ts:199](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L199) +[graphmodel.ts:199](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L199) *** @@ -135,7 +135,7 @@ Create fulltext indexes for the model #### Source -[graphmodel.ts:269](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L269) +[graphmodel.ts:269](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L269) *** @@ -152,7 +152,7 @@ for the model #### Source -[graphmodel.ts:190](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L190) +[graphmodel.ts:190](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L190) *** @@ -168,7 +168,7 @@ Create vector indexes for the model #### Source -[graphmodel.ts:251](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L251) +[graphmodel.ts:251](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L251) *** @@ -184,7 +184,7 @@ Delete all nodes/edges in the graph #### Source -[graphmodel.ts:287](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L287) +[graphmodel.ts:287](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L287) *** @@ -210,7 +210,7 @@ the result #### Source -[graphmodel.ts:384](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L384) +[graphmodel.ts:384](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L384) *** @@ -226,7 +226,7 @@ Drop all Neo4J indexes for the model. #### Source -[graphmodel.ts:161](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L161) +[graphmodel.ts:161](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L161) *** @@ -252,7 +252,7 @@ the items #### Source -[graphmodel.ts:525](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L525) +[graphmodel.ts:525](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L525) *** @@ -268,16 +268,22 @@ Get all the full text indexes for the model #### Source -[graphmodel.ts:234](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L234) +[graphmodel.ts:234](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L234) *** ### getTools() -> **getTools**(): `RunnableToolFunction`\<`any`\>[] +> **getTools**(`options`): `RunnableToolFunction`\<`any`\>[] Creates OpenAI tools for the model +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `options` | [`ToolOptions`](../type-aliases/ToolOptions.md) | + #### Returns `RunnableToolFunction`\<`any`\>[] @@ -286,7 +292,7 @@ an array of OpenAI tool definitions #### Source -[graphmodel.ts:617](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L617) +[graphmodel.ts:617](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L617) *** @@ -302,7 +308,7 @@ Get all the vector indexes for the model #### Source -[graphmodel.ts:216](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L216) +[graphmodel.ts:216](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L216) *** @@ -331,7 +337,7 @@ the graph node #### Source -[graphmodel.ts:361](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L361) +[graphmodel.ts:361](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L361) *** @@ -360,7 +366,7 @@ the source node #### Source -[graphmodel.ts:399](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L399) +[graphmodel.ts:399](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L399) *** @@ -385,7 +391,7 @@ a promise to a Context for the database. #### Source -[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L55) +[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L55) *** @@ -411,7 +417,7 @@ the query results #### Source -[graphmodel.ts:334](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L334) +[graphmodel.ts:334](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L334) *** @@ -438,7 +444,7 @@ an array of similar nodes, up to the count limit #### Source -[graphmodel.ts:458](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L458) +[graphmodel.ts:458](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L458) *** @@ -463,7 +469,7 @@ Performs a similarity search on nodes with text content #### Source -[graphmodel.ts:303](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L303) +[graphmodel.ts:303](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L303) *** @@ -487,4 +493,4 @@ the Cypher query #### Source -[graphmodel.ts:482](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/graphmodel.ts#L482) +[graphmodel.ts:482](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/graphmodel.ts#L482) diff --git a/docs/functions/getOpenAiEmbedding.md b/docs/functions/getOpenAiEmbedding.md index a0729f4..f7c6b50 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/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/functions.ts#L12) +[functions.ts:12](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/functions.ts#L12) diff --git a/docs/type-aliases/Context.md b/docs/type-aliases/Context.md index 5b674ad..5010b24 100644 --- a/docs/type-aliases/Context.md +++ b/docs/type-aliases/Context.md @@ -18,4 +18,4 @@ Runtime context ## Source -[types.ts:34](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L34) +[types.ts:60](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L60) diff --git a/docs/type-aliases/ConversationOptions.md b/docs/type-aliases/ConversationOptions.md new file mode 100644 index 0000000..c9101d3 --- /dev/null +++ b/docs/type-aliases/ConversationOptions.md @@ -0,0 +1,19 @@ +[**@accordproject/concerto-graph**](../README.md) • **Docs** + +*** + +[@accordproject/concerto-graph](../README.md) / ConversationOptions + +# Type alias: ConversationOptions + +> **ConversationOptions**: `object` + +## Type declaration + +### toolOptions + +> **toolOptions**: [`ToolOptions`](ToolOptions.md) + +## Source + +[types.ts:44](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L44) diff --git a/docs/type-aliases/EmbeddingCacheNode.md b/docs/type-aliases/EmbeddingCacheNode.md index 86f8f72..8b7bc27 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:41](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L41) +[types.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L67) diff --git a/docs/type-aliases/EmbeddingFunction.md b/docs/type-aliases/EmbeddingFunction.md index 5a324b8..c920984 100644 --- a/docs/type-aliases/EmbeddingFunction.md +++ b/docs/type-aliases/EmbeddingFunction.md @@ -23,4 +23,4 @@ vector embeddings for text ## Source -[types.ts:70](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L70) +[types.ts:96](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L96) diff --git a/docs/type-aliases/FullTextIndex.md b/docs/type-aliases/FullTextIndex.md index 40a1085..b7e9fa8 100644 --- a/docs/type-aliases/FullTextIndex.md +++ b/docs/type-aliases/FullTextIndex.md @@ -26,4 +26,4 @@ Definition of a full text index over some properties ## Source -[types.ts:25](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L25) +[types.ts:51](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L51) diff --git a/docs/type-aliases/GraphModelOptions.md b/docs/type-aliases/GraphModelOptions.md index 86fa235..05cb6b0 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:91](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L91) +[types.ts:117](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L117) diff --git a/docs/type-aliases/GraphNodeProperties.md b/docs/type-aliases/GraphNodeProperties.md index ac82ae1..4fef458 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:64](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L64) +[types.ts:90](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L90) diff --git a/docs/type-aliases/Logger.md b/docs/type-aliases/Logger.md index 450941d..04196e8 100644 --- a/docs/type-aliases/Logger.md +++ b/docs/type-aliases/Logger.md @@ -89,4 +89,4 @@ Function signature for a logger ## Source -[types.ts:75](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L75) +[types.ts:101](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L101) diff --git a/docs/type-aliases/PropertyBag.md b/docs/type-aliases/PropertyBag.md index 0a28387..cc929d7 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:59](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L59) +[types.ts:85](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L85) diff --git a/docs/type-aliases/SimilarityResult.md b/docs/type-aliases/SimilarityResult.md index f5cd99b..e6f12f0 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:50](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L50) +[types.ts:76](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L76) diff --git a/docs/type-aliases/ToolOptions.md b/docs/type-aliases/ToolOptions.md new file mode 100644 index 0000000..c182e4d --- /dev/null +++ b/docs/type-aliases/ToolOptions.md @@ -0,0 +1,41 @@ +[**@accordproject/concerto-graph**](../README.md) • **Docs** + +*** + +[@accordproject/concerto-graph](../README.md) / ToolOptions + +# Type alias: ToolOptions + +> **ToolOptions**: `object` + +Options for tool generation from the model + +## Type declaration + +### chatWithData? + +> `optional` **chatWithData**: `boolean` + +Creates tools to retrieve nodes via generation of Cypher from natural language + +### fullTextSearch? + +> `optional` **fullTextSearch**: `boolean` + +Creates tools to retrieve nodes via fulltext search of indexed properties + +### getById? + +> `optional` **getById**: `boolean` + +Creates tools to retrieve nodes by id + +### similaritySearch? + +> `optional` **similaritySearch**: `boolean` + +Creates tools to retrieve nodes via similarity search of vector indexed properties + +## Source + +[types.ts:25](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L25) diff --git a/docs/type-aliases/ToolResponse.md b/docs/type-aliases/ToolResponse.md index 494fb99..1aa5ff3 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:103](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L103) +[types.ts:129](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L129) diff --git a/docs/type-aliases/VectorIndex.md b/docs/type-aliases/VectorIndex.md index ec6aa8a..7094bc6 100644 --- a/docs/type-aliases/VectorIndex.md +++ b/docs/type-aliases/VectorIndex.md @@ -34,4 +34,4 @@ Definition of a vector (embeddings) index ## Source -[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L14) +[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L14) diff --git a/docs/variables/ConsoleLogger.md b/docs/variables/ConsoleLogger.md index 41b0337..d8615f3 100644 --- a/docs/variables/ConsoleLogger.md +++ b/docs/variables/ConsoleLogger.md @@ -10,4 +10,4 @@ ## Source -[ConsoleLogger.ts:4](https://github.com/accordproject/lab-concerto-graph/blob/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/ConsoleLogger.ts#L4) +[ConsoleLogger.ts:4](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/ConsoleLogger.ts#L4) diff --git a/docs/variables/EMBEDDINGS_MAGIC.md b/docs/variables/EMBEDDINGS_MAGIC.md index e9793ba..78b17e4 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/d7fad90b4d14f7e274bc7920a0b495fb75c52dcc/src/types.ts#L9) +[types.ts:9](https://github.com/accordproject/lab-concerto-graph/blob/8f4fb74348d19b37d903f29e81aaec4eca02a552/src/types.ts#L9) diff --git a/src/Conversation.ts b/src/Conversation.ts index 6b75747..300aa51 100644 --- a/src/Conversation.ts +++ b/src/Conversation.ts @@ -2,6 +2,7 @@ import OpenAI from 'openai'; import { RunnableToolFunction } from "openai/lib/RunnableFunction"; import { OPENAI_MODEL } from "./prompt"; import { GraphModel } from "./graphmodel"; +import { ConversationOptions } from './types'; /** * An LLM conversation about a GraphModel @@ -19,9 +20,9 @@ export class Conversation { * Creates a new Conversation * @param graphModel the graph model for the conversation */ - constructor(graphModel: GraphModel) { + constructor(graphModel: GraphModel, options:ConversationOptions) { this.graphModel = graphModel; - this.tools = graphModel.getTools(); + this.tools = graphModel.getTools(options.toolOptions); this.client = new OpenAI(); this.runner = null; } diff --git a/src/demo/index.ts b/src/demo/index.ts index 346b216..c892dce 100644 --- a/src/demo/index.ts +++ b/src/demo/index.ts @@ -171,7 +171,12 @@ async function run() { } { - const convo = new Conversation(graphModel); + const convo = new Conversation(graphModel, { + toolOptions: { + getById: true, + chatWithData: true + } + }); let result = await convo.appendUserMessage('Tell me a joke about actors'); logger.success(result); result = await convo.appendUserMessage('Which actor is related to Fear and Loathing in Las Vegas?'); diff --git a/src/graphmodel.ts b/src/graphmodel.ts index f1a7954..cd3b7b2 100644 --- a/src/graphmodel.ts +++ b/src/graphmodel.ts @@ -1,6 +1,6 @@ import { ClassDeclaration, Factory, Introspector, ModelManager, ModelUtil, Property, RelationshipDeclaration, Serializer } from "@accordproject/concerto-core"; import neo4j, { DateTime, Driver, ManagedTransaction } from 'neo4j-driver'; -import { Context, EmbeddingCacheNode, FullTextIndex, GraphModelOptions, PropertyBag, SimilarityResult, VectorIndex } from "./types"; +import { Context, EmbeddingCacheNode, FullTextIndex, GraphModelOptions, PropertyBag, SimilarityResult, ToolOptions, VectorIndex } from "./types"; import { ROOT_MODEL, ROOT_NAMESPACE } from "./model"; import { getTextChecksum, textToCypher } from "./functions"; import { RunnableToolFunction } from "openai/lib/RunnableFunction"; @@ -147,7 +147,7 @@ export class GraphModel { } } - private getPropertyVectorIndexName(decl:ClassDeclaration, vectorProperty: Property) { + private getPropertyVectorIndexName(decl: ClassDeclaration, vectorProperty: Property) { return `${decl.getName()}_${vectorProperty.getName()}`.toLowerCase(); } @@ -614,88 +614,54 @@ export class GraphModel { * @returns an array of OpenAI tool definitions */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - getTools(): Array> { + getTools(options: ToolOptions): Array> { // eslint-disable-next-line @typescript-eslint/no-explicit-any const result: Array> = []; - const nodes = this.getGraphNodeDeclarations(); - for (let n = 0; n < nodes.length; n++) { - const node = nodes[n]; - // the declaration itself - result.push({ - type: "function", - function: { - description: `Get a ${node.getName()} by id`, - name: `get_${node.getName().toLowerCase()}_by_id`, - function: (async (args: { name: string }) => { - const { name } = args; - try { - return await this.query(`MATCH (n:${node.getName()} WHERE n.identifier='${name}') RETURN n;`); - } - catch (err) { - return `An error occurred: ${err}`; - } - }), - parse: JSON.parse, - parameters: { - "type": "object", - "properties": { - "name": { - "type": "string", + if (options.getById) { + const nodes = this.getGraphNodeDeclarations(); + for (let n = 0; n < nodes.length; n++) { + const node = nodes[n]; + // the declaration itself + result.push({ + type: "function", + function: { + description: `Get a ${node.getName()} by id`, + name: `get_${node.getName().toLowerCase()}_by_id`, + function: (async (args: { name: string }) => { + const { name } = args; + try { + return await this.query(`MATCH (n:${node.getName()} WHERE n.identifier='${name}') RETURN n;`); } - }, - "required": ["name"] - } - } - }) - } - // full text search - const fullTextIndexes = this.getFullTextIndexes(); - for (let n = 0; n < fullTextIndexes.length; n++) { - const index = fullTextIndexes[n]; - result.push({ - type: "function", - function: { - description: `Full-text search over ${index.type}`, - name: `fulltext_${index.type.toLowerCase()}`, - function: (async (args: { search: string, count?: number }) => { - const { search, count } = args; - try { - return await this.fullTextQuery(index.type, search, count ? count : 10); - } - catch (err) { - return `An error occurred: ${err}`; - } - }), - parse: JSON.parse, - parameters: { - "type": "object", - "properties": { - "search": { - "type": "string", - }, - "count": { - "type": "number", + catch (err) { + return `An error occurred: ${err}`; } - }, - "required": ["search"] + }), + parse: JSON.parse, + parameters: { + "type": "object", + "properties": { + "name": { + "type": "string", + } + }, + "required": ["name"] + } } - } - }) + }) + } } - // similarity search - const vectorIndexes = this.getVectorIndexes(); - for (let n = 0; n < vectorIndexes.length; n++) { - const index = vectorIndexes[n]; + // chat with data... + if (options.chatWithData) { result.push({ type: "function", function: { - description: `Similiarity/conceptual search over ${index.type}.${index.property}`, - name: `similarity_${index.type.toLowerCase()}_${index.property.toLowerCase()}`, - function: (async (args: { query: string, property: string, count?: number }) => { - const { query, count } = args; + description: `Get data from a natural language query`, + name: `chat_with_data`, + function: (async (args: { query: string }) => { + const { query } = args; try { - return await this.similarityQuery(index.type, index.property, query, count ? count : 10); + return await this.chatWithData(query); } catch (err) { return `An error occurred: ${err}`; @@ -707,9 +673,6 @@ export class GraphModel { "properties": { "query": { "type": "string", - }, - "count": { - "type": "number", } }, "required": ["query"] @@ -718,33 +681,79 @@ export class GraphModel { }) } - // generic: chat with data... - result.push({ - type: "function", - function: { - description: `Get data from a natural language query`, - name: `chat_with_data`, - function: (async (args: { query: string }) => { - const { query } = args; - try { - return await this.chatWithData(query); - } - catch (err) { - return `An error occurred: ${err}`; + // full text search + if (options.fullTextSearch) { + const fullTextIndexes = this.getFullTextIndexes(); + for (let n = 0; n < fullTextIndexes.length; n++) { + const index = fullTextIndexes[n]; + result.push({ + type: "function", + function: { + description: `Full-text search over ${index.type}`, + name: `fulltext_${index.type.toLowerCase()}`, + function: (async (args: { search: string, count?: number }) => { + const { search, count } = args; + try { + return await this.fullTextQuery(index.type, search, count ? count : 10); + } + catch (err) { + return `An error occurred: ${err}`; + } + }), + parse: JSON.parse, + parameters: { + "type": "object", + "properties": { + "search": { + "type": "string", + }, + "count": { + "type": "number", + } + }, + "required": ["search"] + } } - }), - parse: JSON.parse, - parameters: { - "type": "object", - "properties": { - "query": { - "type": "string", + }) + } + } + + // similarity search + if (options.similaritySearch) { + const vectorIndexes = this.getVectorIndexes(); + for (let n = 0; n < vectorIndexes.length; n++) { + const index = vectorIndexes[n]; + result.push({ + type: "function", + function: { + description: `Similiarity/conceptual search over ${index.type}.${index.property}`, + name: `similarity_${index.type.toLowerCase()}_${index.property.toLowerCase()}`, + function: (async (args: { query: string, property: string, count?: number }) => { + const { query, count } = args; + try { + return await this.similarityQuery(index.type, index.property, query, count ? count : 10); + } + catch (err) { + return `An error occurred: ${err}`; + } + }), + parse: JSON.parse, + parameters: { + "type": "object", + "properties": { + "query": { + "type": "string", + }, + "count": { + "type": "number", + } + }, + "required": ["query"] } - }, - "required": ["query"] - } + } + }) } - }) + } return result; } } \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 6ec715c..a85112e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,6 +19,32 @@ export type VectorIndex = { indexName: string; } +/** + * Options for tool generation from the model + */ +export type ToolOptions = { + /** + * Creates tools to retrieve nodes by id + */ + getById?: boolean, + /** + * Creates tools to retrieve nodes via fulltext search of indexed properties + */ + fullTextSearch?: boolean, + /** + * Creates tools to retrieve nodes via similarity search of vector indexed properties + */ + similaritySearch?: boolean, + /** + * Creates tools to retrieve nodes via generation of Cypher from natural language + */ + chatWithData?: boolean +} + +export type ConversationOptions = { + toolOptions: ToolOptions +} + /** * Definition of a full text index over some properties */