forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Automatic Import] add yarn draw-graphs command (elastic#191813)
## Summary This adds the `yarn draw-graphs` plugin specific command, which is defined in our plugins `package.json`. The command can be run from the root of our plugin, and does not require any additional dependencies. The graphs are added to `docs/imgs` and linked in the README.md of the plugin. The purpose of this PR is not to write a better README or provide any automation of the task itself, that would be separate tasks, but simply allow the creation of graphs to the readme, which can be useful to debug changes to nodes and conditional edges. Examples: ![ecs_graph](https://github.com/user-attachments/assets/ccc403a2-e2b0-4482-9de7-74c016c75c16) ![ecs_subgraph](https://github.com/user-attachments/assets/ad8da90e-191e-4533-b5b2-ede4bd973993) ![log_detection_graph](https://github.com/user-attachments/assets/777c6845-ba52-4a16-a2b1-b13e172a7488) ![related_graph](https://github.com/user-attachments/assets/a5447a5b-2fa7-4b96-920f-3cd9a2c8dbe5) ![categorization_graph](https://github.com/user-attachments/assets/c61463d6-c1d8-4347-bb84-d39e5606417b) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
a118728
commit 1606db8
Showing
11 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+47 KB
x-pack/plugins/integration_assistant/docs/imgs/categorization_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"author": "Elastic", | ||
"name": "@kbn/integration-assistant-plugin", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "Elastic License 2.0", | ||
"scripts": { | ||
"draw-graphs": "node ./scripts/draw_graphs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
require('../../../../src/setup_node_env'); | ||
require('./draw_graphs_script').drawGraphs(); |
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/integration_assistant/scripts/draw_graphs_script.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server'; | ||
import { | ||
ActionsClientChatOpenAI, | ||
ActionsClientSimpleChatModel, | ||
} from '@kbn/langchain/server/language_models'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { Graph as RunnableGraph } from '@langchain/core/runnables/graph'; | ||
import { FakeLLM } from '@langchain/core/utils/testing'; | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { getCategorizationGraph } from '../server/graphs/categorization/graph'; | ||
import { getEcsGraph, getEcsSubGraph } from '../server/graphs/ecs/graph'; | ||
import { getLogFormatDetectionGraph } from '../server/graphs/log_type_detection/graph'; | ||
import { getRelatedGraph } from '../server/graphs/related/graph'; | ||
|
||
// Some mock elements just to get the graph to compile | ||
const model = new FakeLLM({ | ||
response: JSON.stringify({}, null, 2), | ||
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel; | ||
const client = 'test' as unknown as IScopedClusterClient; | ||
|
||
const logger = new ToolingLog({ | ||
level: 'info', | ||
writeTo: process.stdout, | ||
}); | ||
logger.info('Compiling graphs'); | ||
|
||
async function saveFile(filename: string, buffer: Buffer) { | ||
const outputPath = path.join(__dirname, '../docs/imgs/', filename); | ||
logger.info(`Writing graph to ${outputPath}`); | ||
await fs.writeFile(outputPath, buffer); | ||
} | ||
|
||
async function drawGraph(compiledGraph: RunnableGraph, graphName: string) { | ||
const output = await compiledGraph.drawMermaidPng(); | ||
const buffer = Buffer.from(await output.arrayBuffer()); | ||
await saveFile(`${graphName}.png`, buffer); | ||
} | ||
|
||
export async function drawGraphs() { | ||
const relatedGraph = (await getRelatedGraph({ client, model })).getGraph(); | ||
const logFormatDetectionGraph = (await getLogFormatDetectionGraph(model)).getGraph(); | ||
const categorizationGraph = (await getCategorizationGraph({ client, model })).getGraph(); | ||
const ecsSubGraph = (await getEcsSubGraph({ model })).getGraph(); | ||
const ecsGraph = (await getEcsGraph({ model })).getGraph(); | ||
drawGraph(relatedGraph, 'related_graph'); | ||
drawGraph(logFormatDetectionGraph, 'log_detection_graph'); | ||
drawGraph(categorizationGraph, 'categorization_graph'); | ||
drawGraph(ecsSubGraph, 'ecs_subgraph'); | ||
drawGraph(ecsGraph, 'ecs_graph'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters