feat(core): Improve Langsmith traces for AI executions (#9081)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-04-08 22:51:49 +02:00
committed by GitHub
parent 3bcfef95f6
commit 936682eeaa
18 changed files with 99 additions and 26 deletions

View File

@@ -27,6 +27,7 @@ import {
getPromptInputByType,
isChatInstance,
} from '../../../utils/helpers';
import { getTracingConfig } from '../../../utils/tracing';
interface MessagesTemplate {
type: string;
@@ -154,9 +155,9 @@ async function createSimpleLLMChain(
const chain = new LLMChain({
llm,
prompt,
});
}).withConfig(getTracingConfig(context));
const response = (await chain.call({
const response = (await chain.invoke({
query,
signal: context.getExecutionCancelSignal(),
})) as string[];
@@ -203,8 +204,9 @@ async function getChain(
);
const chain = prompt.pipe(llm).pipe(combinedOutputParser);
const response = (await chain.invoke({ query })) as string | string[];
const response = (await chain.withConfig(getTracingConfig(context)).invoke({ query })) as
| string
| string[];
return Array.isArray(response) ? response : [response];
}