Upgrade Langfuse to v2

JavaScript pattern

Upgrade the Langfuse SDK to v2 following this guide.

Rewrites generation parameters if there is a langfuse import

BEFORE
import { LangfuseGenerationClient } from 'langfuse';
import { messages, trace } from './messages';

const generation: LangfuseGenerationClient = trace.generation({
  name: 'chat-completion',
  model: 'gpt-3.5-turbo',
  modelParameters: {
    temperature: 0.9,
    maxTokens: 2000,
  },
  prompt: messages,
  completion: 'completion',
});
AFTER
import { LangfuseGenerationClient } from 'langfuse';
import { messages, trace } from './messages';

const generation: LangfuseGenerationClient = trace.generation({
  name: 'chat-completion',
  model: 'gpt-3.5-turbo',
  modelParameters: {
    temperature: 0.9,
    maxTokens: 2000,
  },
  input: messages,
  output: 'completion',
});

Does nothing if there is no langfuse import

JS
import { messages, trace } from './messages';

const generation = trace.generation({
  name: 'chat-completion',
  model: 'gpt-3.5-turbo',
  modelParameters: {
    temperature: 0.9,
    maxTokens: 2000,
  },
  prompt: messages,
  completion: 'completion',
});