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

Javascript SDK #876

Open
jverre opened this issue Dec 12, 2024 · 12 comments
Open

Javascript SDK #876

jverre opened this issue Dec 12, 2024 · 12 comments
Labels
enhancement New feature or request resolved This issue has been resolved

Comments

@jverre
Copy link
Collaborator

jverre commented Dec 12, 2024

Proposal summary

We are currently working on a Javascript SDK, feel free to leave comments below on the functionality you would like us to add !

We are currently planning to release the SDK in different phases:

  1. Low level client: Similar to the opik.Opik class in Python which allows you to log traces manually
  2. Track decorator: Similar to the opik.track decorator
  3. Evaluation metrics: Add Hallucination, Relevance, etc metrics
  4. Evaluation support: Add support for running evaluations from the UI

Motivation

No response

@jverre jverre added the enhancement New feature or request label Dec 12, 2024
@jverre jverre pinned this issue Dec 12, 2024
@Bayesian4042
Copy link

@jverre Could you provide an update on the JavaScript SDK? Do you have an estimate of when it will be ready for use? Thank you!

@jverre
Copy link
Collaborator Author

jverre commented Dec 24, 2024

Hi @Bayesian4042,
The first version will be ready in the next couple of weeks, as Nimrod mentioned in the other thread the PR is open but will take a little while to merge in due to the holiday season

@Bayesian4042
Copy link

@jverre thanks for the update, I see the PR has been merged, is it possible to have a documentation on how to use it?. thank you

@jverre
Copy link
Collaborator Author

jverre commented Jan 8, 2025

Hi @Bayesian4042

@ferc is working on auto-generating the docs, should be ready in the next couple of days and will ping you here

@Bayesian4042
Copy link

Bayesian4042 commented Jan 18, 2025

HI @jverre @ferc any update ? :)

@Bayesian4042
Copy link

Bayesian4042 commented Jan 29, 2025

@jverre how is the progress going on ? I'm eager to integrate some evaluation tool in our application :)

@JassimranK
Copy link

Hi, any ETA on this, this will save us so much time.

@jverre
Copy link
Collaborator Author

jverre commented Feb 3, 2025

Hi @JassimranK @Bayesian4042 ,

Sorry for the delays here, we are not moving as quickly as we were hoping but progress is being made. We have a PR open for adding batching to the Javascript SDK which is what we were waiting for to make the SDK public.

Once that is merged, we will add the Javascript reference docs to the website. We are getting closer

@ferc
Copy link
Collaborator

ferc commented Feb 3, 2025

@JassimranK / @Bayesian4042 as @jverre mentioned we're currently making progress on it!

May I ask you the exact use case that you expect to have in our JavaScript/TypeScript SDK? that would help us to prioritize properly the work here :)

Currently you can install the alpha version of this SDK from NPM (not documented yet, as Jacques mentioned, it's still in an early phase): https://www.npmjs.com/package/opik

Currently it supports logging spans and traces manually:

import { Opik } from "opik";

// Create a new Opik client with your configuration
const client = new Opik({
  apiKey: "<your-api-key>",
  host: "https://www.comet.com/opik/api",
  projectName: "<your-project-name>",
  workspaceName: "<your-workspace-name>",
});

// Log 10 traces
for (let i = 0; i < 10; i++) {
  const someTrace = client.trace({
    name: `Trace ${i}`,
    input: {
      prompt: `Hello, world! ${i}`,
    },
    output: {
      response: `Hello, world! ${i}`,
    },
  });

  // For each trace, log 10 spans
  for (let j = 0; j < 10; j++) {
    const someSpan = someTrace.span({
      name: `Span ${i}-${j}`,
      type: "llm",
      input: {
        prompt: `Hello, world! ${i}:${j}`,
      },
      output: {
        response: `Hello, world! ${i}:${j}`,
      },
    });

    // Some LLM work
    await new Promise((resolve) => setTimeout(resolve, 100));

    // Mark the span as ended
    someSpan.end();
  }

  // Mark the trace as ended
  someTrace.end();
}

// Flush the client to send all traces and spans
await client.flush();

Which creates:
Image

Also the client.api exposes all the endpoints that we currently have in Opik so even when there is pending work to add more helpers and improve the DX, the current client.api could help a lot in your integration with Opik using JS/TS

Hope that helps!

@dsblank
Copy link
Contributor

dsblank commented Feb 12, 2025

Good news everyone! The JavaScript PR has been merged, and we will be adding a specific doc page for it shortly.

@dsblank dsblank added resolved This issue has been resolved and removed work in progress labels Feb 12, 2025
@Bayesian4042
Copy link

@dsblank thank you for the update, the given example is not very clear me, could you help me with actuall openai LLM call example, thank you

@ferc
Copy link
Collaborator

ferc commented Feb 14, 2025

Hello @Bayesian4042 as part of the TypeScript SDK work we introduced an integration with Vercel AI SDK: #1253

Therefore now it's possible to integrate Opik with any provider/model listed here: https://sdk.vercel.ai/docs/foundations/providers-and-models (including OpenAI models, Anthropic, Gemini and more)

How to integrate Opik with it?

.env file (cloud version, for self-hosted version only OPENAI_API_KEY would be needed):

OPIK_API_KEY="your-api-key"
OPIK_HOST="https://www.comet.com/opik/api"
OPIK_PROJECT_NAME="your-project-name"
OPIK_WORKSPACE_NAME="your-workspace-name"
OPENAI_API_KEY="your-openai-key"

Dependencies installation:

npm install opik ai @ai-sdk/openai @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node
import { openai } from "@ai-sdk/openai";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { generateText } from "ai";
import { OpikExporter } from "opik/vercel";

const sdk = new NodeSDK({
  traceExporter: new OpikExporter(),
  instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();

const { text } = await generateText({
  model: openai("gpt-4o-mini"),
  prompt: "What is love? Describe it in 10 words or less.",
  experimental_telemetry: OpikExporter.getSettings({
    name: "ai-sdk-integration",
  }),
});

await sdk.shutdown();

Depending on the environment where you're using it (develop or production monitoring), the code snippet could be defined in a better way, we're going to add soon the proper documentation for it

If you are looking for a direct OpenAI wrapper, let us know and we can prioritize that work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request resolved This issue has been resolved
Projects
None yet
Development

No branches or pull requests

5 participants