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

bug: Langfuse Open AI SDK on Node doesn't create all generations for a trace #2024

Open
khaelys opened this issue May 9, 2024 · 0 comments

Comments

@khaelys
Copy link

khaelys commented May 9, 2024

Describe the bug

I have a trace with 3 generations and I'm trying to use the new Langfuse SDK for OpenAI. The trace is created correctly, but not all generations get flushed to cloud langfuse, if I don't do it manually.

I expect that all generations get flushed to cloud langfuse under the hood without doing it manually.

To reproduce

How to reproduce.

const newTrace = this.langfuse.trace({
      name: 'myTrace',
      userId: userInfo.userId,
      sessionId: userInfo.sessionId,
      metadata: metadata,
      tags: [this.configService.get().appEnv],
});

// Example of my generation Method
async function myGenerationMethod(options): Promise<string> {
   const lfOpenAi = observeOpenAI(this.openAi, {
        parent: options?.trace,
        generationName: options?.prompt.name,
        langfusePrompt: options?.prompt,
        metadata: {
          env: this.configService.get().appEnv,
          ...options?.metadata,
        },
      });
      const chatCompletion: OpenAI.Chat.ChatCompletion =
        await lfOpenAi.chat.completions.create(params);
      this.checkFinishReason(chatCompletion.choices[0].finish_reason);
      return isNotNull(chatCompletion.choices[0].message.content);
}

await Promise.all([myGenerationMethod(), myGenerationMethod(), myGenerationMethod()]);

If you run a similar example multiple times, some generations are not recorded correctly.

SDK and container versions

I'm using "openai": "4.43.0" and "langfuse": "3.9.0" on Node 18

Additional information

No response

Are you interested to contribute a fix for this bug?

No

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