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.
[Security GenAI] Use AI setting to set langsmith tracing to the Integ…
…ration Assistant (elastic#187466) ## Summary Enables tracing Langchain invocations in the integrations assistant using the Langsmith settings stored by the Security AI Settings. The evaluation settings tab is still under an experimental flag, to see it: ``` xpack.securitySolution.enableExperimental: ['assistantModelEvaluation'] ``` ### Screenshots <img width="1317" alt="Settings" src="https://github.com/elastic/kibana/assets/17747913/6aed1ef6-3750-4259-9fe2-b8bf1aed5504"> After one execution of the integration assistant: <img width="1240" alt="langsmith" src="https://github.com/elastic/kibana/assets/17747913/dd3dd99c-7c83-4a35-95b2-789e7a341031"> --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
35ee0cc
commit 92099b2
Showing
32 changed files
with
231 additions
and
91 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { APMTracer } from './apm_tracer'; |
7 changes: 7 additions & 0 deletions
7
x-pack/packages/kbn-langchain/server/tracers/langsmith/index.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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
export { getLangSmithTracer, isLangSmithEnabled } from './langsmith_tracer'; |
64 changes: 64 additions & 0 deletions
64
x-pack/packages/kbn-langchain/server/tracers/langsmith/langsmith_tracer.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,64 @@ | ||
/* | ||
* 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 { Client } from 'langsmith'; | ||
import type { Logger } from '@kbn/core/server'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { LangChainTracer } from '@langchain/core/tracers/tracer_langchain'; | ||
|
||
/** | ||
* Returns a custom LangChainTracer which adds the `exampleId` so Dataset 'Test' runs are written to LangSmith | ||
* If `exampleId` is present (and a corresponding example exists in LangSmith) trace is written to the Dataset's `Tests` | ||
* section, otherwise it is written to the `Project` provided | ||
* | ||
* @param apiKey API Key for LangSmith (will fetch from env vars if not provided) | ||
* @param projectName Name of project to trace results to | ||
* @param exampleId Dataset exampleId to associate trace with | ||
* @param logger | ||
*/ | ||
export const getLangSmithTracer = ({ | ||
apiKey, | ||
projectName, | ||
exampleId, | ||
logger, | ||
}: { | ||
apiKey?: string; | ||
projectName?: string; | ||
exampleId?: string; | ||
logger: Logger | ToolingLog; | ||
}): LangChainTracer[] => { | ||
try { | ||
if (!isLangSmithEnabled() || apiKey == null) { | ||
return []; | ||
} | ||
const lcTracer = new LangChainTracer({ | ||
projectName, // Shows as the 'test' run's 'name' in langsmith ui | ||
exampleId, | ||
client: new Client({ apiKey }), | ||
}); | ||
|
||
return [lcTracer]; | ||
} catch (e) { | ||
// Note: creating a tracer can fail if the LangSmith env vars are not set correctly | ||
logger.error(`Error creating LangSmith tracer: ${e.message}`); | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
/** | ||
* Returns true if LangSmith/tracing is enabled | ||
*/ | ||
export const isLangSmithEnabled = (): boolean => { | ||
try { | ||
// Just checking if apiKey is available, if better way to check for enabled that is not env var please update | ||
const config = Client.getDefaultClientConfig(); | ||
return config.apiKey != null; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |
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
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
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
File renamed without changes.
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
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
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
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
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
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
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
Oops, something went wrong.