comet-ml / opik

Open-source end-to-end LLM Development Platform
Apache License 2.0
1.36k stars 73 forks source link

[Bug]: First usage or easy example #236

Closed AbhiPawar5 closed 1 week ago

AbhiPawar5 commented 2 weeks ago

Willingness to contribute

No. I can't contribute a fix for this bug at this time.

What component(s) are affected?

Opik version

Describe the problem

How do I use the Opik server locally? I'm following the steps mentioned here - https://www.comet.com/docs/opik/tracing/log_traces

but my API go to comet servers, why?

HTTP Request: POST https://www.comet.com/opik/api/v1/private/spans "HTTP/1.1 403 Forbidden"
OPIK: Failed to process CreateSpanMessage. Content: CreateSpanMessage(span_id='066e409a-b3d0-7e45-8000-1e18b8ddd447', trace_id='066e409a-b3d0-7342-8000-6f741a7b8385', project_name='Test_Asset_Desc', parent_span_id=None, name='llm_call', start_time=datetime.datetime(2024, 9, 13, 9, 45, 15, 238507, tzinfo=datetime.timezone.utc), end_time=None, input={'prompt': 'Translate the following text to French: hello, how are you?'}, output={'response': 'Comment ça va?'}, metadata=None, tags=None, type='llm', usage=None), Error: status_code: 403, body: {'code': 403, 'message': 'HTTP 403 Forbidden'}
Traceback (most recent call last):
  File "/opt/miniconda3/envs/bedrock_v2/lib/python3.9/site-packages/opik/message_processing/message_processors.py", line 42, in process
    handler(message)
  File "/opt/miniconda3/envs/bedrock_v2/lib/python3.9/site-packages/opik/message_processing/message_processors.py", line 74, in _process_create_span_message
    self._rest_client.spans.create_span(**cleaned_create_span_kwargs)
  File "/opt/miniconda3/envs/bedrock_v2/lib/python3.9/site-packages/opik/rest_api/spans/client.py", line 283, in create_span
    raise ApiError(status_code=_response.status_code, body=_response_json)
opik.rest_api.core.api_error.ApiError: status_code: 403, body: {'code': 403, 'message': 'HTTP 403 Forbidden'}

Reproduction steps

from opik import Opik, track
from opik.opik_context import update_current_span

from opik import Opik

client = Opik(project_name="Test_Asset_Desc")

# Create a trace
trace = client.trace(
    name="my_trace",
    input={"user_question": "Hello, how are you?"},
    output={"response": "Comment ça va?"}
)

# Add a span
trace.span(
    name="Add prompt template",
    input={"text": "Hello, how are you?", "prompt_template": "Translate the following text to French: {text}"},
    output={"text": "Translate the following text to French: hello, how are you?"}
)

# Add an LLM call
trace.span(
    name="llm_call",
    type="llm",
    input={"prompt": "Translate the following text to French: hello, how are you?"},
    output={"response": "Comment ça va?"}
)

# End the trace
trace.end()
jverre commented 2 weeks ago

Hi @AbhiPawar5 By default we try to log to the Opik Hosted environment, in order to point to the local environment you will need to set: export OPIK_URL_OVERRIDE="http://localhost:5173/api" or if you are in python:

import os
os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api:

On Monday we are going to release a new opik.login method that will mean you simply need to call opik.login(local=True) and everything will be set for you and saved in a configuration file.

AbhiPawar5 commented 2 weeks ago

Thank you, @jverre. To be honest and direct, the documentation and developer experience is very poor!

How do I start the Opik server again? I had stopped the container, it doesn't seem to restart by itself.

jverre commented 2 weeks ago

I appreciate the honest feedback ! We do indeed have some challenges on local deployments, they are pretty hard to set up and manage.

We are moving to a much simpler docker compose set-up which should drastically simplify the experience. This combined with the new login method will make it much simpler to get started. I'll also make some updates to the docs based on your feedback

@CRThaze can you help with instructions on how to restart the service ?

jverre commented 1 week ago

Hi @AbhiPawar5, I wanted to follow up on this as we have just released a number of improvements to make it easier to run Opik locally.

New local deployment option: We have moved to a docker compose based deployment that greatly simplifies the setup, simply clone the repo, navigate to deployments/docker-compose and run docker compose up --detach. I have also updated the self-hosting to docs with more information about starting, stoping and upgrading Opik when using this deployment approach. You can learn more about it here: https://www.comet.com/docs/opik/self-host/local_deployment.

Simplified the setup of the SDK: We have introduced a new opik configure CLI command and opik.configure(use_local=False) method that will create a Opik SDK configuration file, no more environment variables to manage ! You simply need to run this command once and once you have finished the setup process ( takes less than 30 seconds), the Opik SDK will be fully configured. We have updated many of the examples in the docs to use this method and will continue to improve the behavior here.

For now I'm going to close this ticket but happy to re-open it if you are running into issues