Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add item.getLangChainHandler() to link dataset runs to langchain invocations on JS #1970

Open
marcklingen opened this issue May 3, 2024 Discussed in #1969 · 0 comments

Comments

@marcklingen
Copy link
Member

Discussed in https://github.com/orgs/langfuse/discussions/1969

Originally posted by sahellebusch May 3, 2024
I'm working w/ a typescript application and want to write a test suite using a dataset. I want to reuse some of my application code, which uses the built in langchain tracing mechanism. Is there a similar integration to the python dataset integration called out in the docs?

Example code:

const langfuseConfig = {
    secretKey: process.env.LANGFUSE_SECRET_KEY,
    publicKey: process.env.LANGFUSE_PUBLIC_KEY,
    baseUrl: 'https://us.cloud.langfuse.com',
  };

  const langfuse = new Langfuse(langfuseConfig);

  const prompt = await langfuse.getPrompt('my-prompt');

  const openAI = new ChatOpenAI({
    openAIApiKey: process.env.OPENAI_API_KEY,
    modelName: prompt.config.modelName,
    temperature: prompt.config.temperature,
  });

  const dataset = await langfuse.getDataset('my-dataset');

  await Promise.all(
    dataset.items.map(async i => {
      const res = await RunnableSequence.from([
        ChatPromptTemplate.fromMessages([
          ['system', prompt.getLangchainPrompt()],
          ['user', '{input}'],
        ]),
        openAI,
        StructuredOutputParser.fromZodSchema(
          z.object({ someProperty: z.string() }),
        ),
      ]).invoke(
        { input: i.input },
        {
          callbacks: [
            new CallbackHandler({
              ...langfuseConfig,
              userId: 'someUuid',
              metadata: {
                some: 'metadata',
              },
            }),
          ],
        },
      );

      // Here I want to link and add a score.
    }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant