Skip to content

Commit

Permalink
[OPIK-89] opik configure (#247)
Browse files Browse the repository at this point in the history
* draft

* add config file saving/loading

* add more supported python versions

* change checking of api key and workspace name

* fix config save

* use account-details endpoint to check key and get default workspace

* remove force parameter

* fix using configured api key

* use configured workspace name if possible

* Draft code fix

* Draft fix

* Fix lint errors

* Fix lint errors

* Rename login to configure, skip configure unit tests

* Fix lint errors

* Update implementation so that config is not updated if all values have been already provided

* Update config updating logic

* Jacques/add cli command (#259)

* Added support for CLI command and force parameter

* Updated documentation

* Update linters

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Small change to run CI (#260)

* Small change to run CI

* Small change to run CI

* Small change to run CI

* Update _logging.py

---------

Co-authored-by: Aliaksandr Kuzmik <[email protected]>
Co-authored-by: Aliaksandr Kuzmik <[email protected]>

* Fix configure branch when running local opik is not found

* Revert accidental file updating logic for provided workspace

* Fix lint errors

---------

Co-authored-by: Aliaksandr Kuzmik <[email protected]>
Co-authored-by: Jacques Verré <[email protected]>
Co-authored-by: Aliaksandr Kuzmik <[email protected]>
  • Loading branch information
4 people authored Sep 17, 2024
1 parent e715f5c commit 7ed4c30
Show file tree
Hide file tree
Showing 28 changed files with 751 additions and 261 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ The easiest way to get started with Opik is by creating a free Comet account at



If you'd like to self-host Opik, you create a simple local version of Opik using::
If you'd like to self-host Opik, you can do so by cloning the repository and starting the platform using Docker Compose:

```bash
pip install opik-installer
# Clone the Opik repository
git clone https://github.com/comet-ml/opik.git

opik-server install
# Navigate to the opik/deployment/docker-compose directory
cd opik/deployment/docker-compose

# Start the Opik platform
docker compose up --detach
```

For more information about the different deployment options, please see our deployment guides:
Expand All @@ -82,19 +87,24 @@ For more information about the different deployment options, please see our depl

## 🏁 Get Started

If you are logging traces to the Cloud Opik platform, you will need to get your API key from the user menu and set it as the `OPIK_API_KEY` environment variable:
To get started, you will need to first install the Python SDK:

```bash
export OPIK_API_KEY=<Your API key>
export OPIK_WORKSPACE=<You workspace, often the same as your username>
pip install opik
```

If you are using a local Opik instance, you don't need to set the `OPIK_API_KEY` or `OPIK_WORKSPACE` environment variable and isntead set the environment variable `OPIK_BASE_URL` to point to your local Opik instance:
Once the SDK is installed, you can configure it by running the `opik configure` command:

```bash
export OPIK_BASE_URL=http://localhost:5173
opik configure
```

This will ensure that your API key is correctly set if you are using the Opik Cloud platform or that the Opik URL is correctly set if you are self-hosting the platform.

> [!TIP]
> You can also call the `opik.configure(use_local=False)` method from your Python code to configure the SDK.

You are now ready to start logging traces using the [Python SDK](https://www.comet.com/docs/opik/python-sdk-reference/?utm_source=opik&utm_medium=github&utm_content=sdk_link2).

### 📝 Logging Traces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ For this guide we will be evaluating the Hallucination metric included in the LL

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```

If you are running the Opik platform locally, simply set:

import opik

```python
# import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ For this guide we will be evaluating the Moderation metric included in the LLM E

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```

If you are running the Opik platform locally, simply set:

import opik

```python
#import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
16 changes: 2 additions & 14 deletions apps/opik-documentation/documentation/docs/cookbook/langchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,9 @@ We will highlight three different parts of the workflow:

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```

If you are running the Opik platform locally, simply set:

import opik

```python
# import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
16 changes: 2 additions & 14 deletions apps/opik-documentation/documentation/docs/cookbook/llama-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,9 @@ For this guide we will be downloading the essays from Paul Graham and use them a

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```
import opik

If you are running the Opik platform locally, simply set:


```python
# import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
25 changes: 2 additions & 23 deletions apps/opik-documentation/documentation/docs/cookbook/openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
16 changes: 2 additions & 14 deletions apps/opik-documentation/documentation/docs/cookbook/openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ Opik integrates with OpenAI to provide a simple way to log traces for all OpenAI

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```
import opik

If you are running the Opik platform locally, simply set:


```python
# import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
25 changes: 2 additions & 23 deletions apps/opik-documentation/documentation/docs/cookbook/ragas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import getpass\n",
"import opik\n",
"\n",
"if \"OPIK_API_KEY\" not in os.environ:\n",
" os.environ[\"OPIK_API_KEY\"] = getpass.getpass(\"Opik API Key: \")\n",
"if \"OPIK_WORKSPACE\" not in os.environ:\n",
" os.environ[\"OPIK_WORKSPACE\"] = input(\"Comet workspace (often the same as your username): \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running the Opik platform locally, simply set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"OPIK_URL_OVERRIDE\"] = \"http://localhost:5173/api\""
"opik.configure(use_local=False)"
]
},
{
Expand Down
16 changes: 2 additions & 14 deletions apps/opik-documentation/documentation/docs/cookbook/ragas.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,9 @@ There are two main ways to use Opik with Ragas:

```python
import os
import getpass

if "OPIK_API_KEY" not in os.environ:
os.environ["OPIK_API_KEY"] = getpass.getpass("Opik API Key: ")
if "OPIK_WORKSPACE" not in os.environ:
os.environ["OPIK_WORKSPACE"] = input("Comet workspace (often the same as your username): ")
```
import opik

If you are running the Opik platform locally, simply set:


```python
# import os
# os.environ["OPIK_URL_OVERRIDE"] = "http://localhost:5173/api"
opik.configure(use_local=False)
```

## Preparing our environment
Expand Down
Loading

0 comments on commit 7ed4c30

Please sign in to comment.