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

[OPIK-558] Typescript SDK - basic client #919

Merged
merged 30 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0fc1f1f
Initial setup for the TypeScript SDK
ferc Nov 28, 2024
42ccd8b
Add tsup/vitest configs
ferc Nov 28, 2024
c9b6d43
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Nov 29, 2024
9aa5aa2
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 5, 2024
64ea632
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 5, 2024
fb72a4e
Change code generation to have the original output instead of a compi…
ferc Dec 7, 2024
7cd4cf9
WIP: Adding test suite
ferc Dec 7, 2024
65b632f
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 9, 2024
c533653
Fix first unit tes
ferc Dec 9, 2024
392309a
WIP: Add classes instead of functions
ferc Dec 11, 2024
49c7901
Sync with main
ferc Dec 12, 2024
d8dff2f
First draft of client, trace and span classes
ferc Dec 12, 2024
7f5a8a4
Improve types
ferc Dec 12, 2024
3292b3a
Sync with main
ferc Dec 12, 2024
409d2e8
Improve defaults
ferc Dec 12, 2024
f0a85b0
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 13, 2024
086df5c
Fix conflicts
ferc Dec 16, 2024
9858b28
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 17, 2024
18f3ab1
Add support for CJS
ferc Dec 18, 2024
0fe7965
Add global headers to the configuration (comet-workspace / authorizat…
ferc Dec 18, 2024
5c5f419
Add support for custom environment, workspace and project names
ferc Dec 18, 2024
65831df
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 18, 2024
8f252c5
Fix conflicts
ferc Dec 18, 2024
7448b1d
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Dec 18, 2024
cab0047
Improve project name management
ferc Dec 18, 2024
5fb5e83
Increment patch version
ferc Dec 18, 2024
747b857
Improve metadata in the package.json
ferc Dec 18, 2024
8653d06
Sync with main and fix conflicts
ferc Dec 31, 2024
02a9ba8
Merge branch 'main' of github.com:comet-ml/opik into fernando/typescr…
ferc Jan 2, 2025
9d3e89f
Sync with main
ferc Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion apps/opik-frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "opik",
"name": "opik-frontend",
"description": "This is Front End part of Comet Opik",
"version": "0.0.1",
"private": true,
Expand Down
6 changes: 3 additions & 3 deletions sdks/code_generation/fern/fern.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"organization": "Opik",
"version": "0.45.0"
}
"organization": "Opik",
"version": "0.45.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: if you're going to update the Fern version, I'd go with the last one, which is 0.46.5

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I updated it weeks ago when I had to due a bugfix that Fern has and now they released a more updated version so agree, I'll keep it updated to the latest one, thanks for noticing

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very picky and minor: keep the extra end of line.

4 changes: 4 additions & 0 deletions sdks/code_generation/fern/generators.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
api:
path: openapi/openapi.yaml
overrides: openapi/overrides-global-headers.yaml
default-group: local
groups:
local:
Expand All @@ -14,3 +15,6 @@ groups:
output:
location: local-file-system
path: ../../typescript/src/opik/rest_api
config:
outputSourceFiles: true
includeCredentialsOnCrossOriginRequests: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x-fern-global-headers:
- header: Authorization
name: apiKey
optional: true
- header: Comet-Workspace
name: workspaceName
optional: true
10 changes: 8 additions & 2 deletions sdks/python/src/opik/rest_api/chat_completions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ def create_chat_completions(
--------
from Opik import OpikApi

client = OpikApi()
client = OpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
client.chat_completions.create_chat_completions()
"""
_response = self._client_wrapper.httpx_client.request(
Expand Down Expand Up @@ -268,7 +271,10 @@ async def create_chat_completions(

from Opik import AsyncOpikApi

client = AsyncOpikApi()
client = AsyncOpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)


async def main() -> None:
Expand Down
10 changes: 8 additions & 2 deletions sdks/python/src/opik/rest_api/check/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def access(
--------
from Opik import OpikApi

client = OpikApi()
client = OpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
client.check.access(
request={"key": "value"},
)
Expand Down Expand Up @@ -115,7 +118,10 @@ async def access(

from Opik import AsyncOpikApi

client = AsyncOpikApi()
client = AsyncOpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)


async def main() -> None:
Expand Down
42 changes: 36 additions & 6 deletions sdks/python/src/opik/rest_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class OpikApi:



api_key : typing.Optional[str]
workspace_name : typing.Optional[str]
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

Expand All @@ -64,14 +66,19 @@ class OpikApi:
--------
from Opik import OpikApi

client = OpikApi()
client = OpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
"""

def __init__(
self,
*,
base_url: typing.Optional[str] = None,
environment: OpikApiEnvironment = OpikApiEnvironment.DEFAULT,
api_key: typing.Optional[str] = None,
workspace_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.Client] = None,
Expand All @@ -81,6 +88,8 @@ def __init__(
)
self._client_wrapper = SyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
api_key=api_key,
workspace_name=workspace_name,
httpx_client=httpx_client
if httpx_client is not None
else httpx.Client(
Expand Down Expand Up @@ -126,7 +135,10 @@ def is_alive(
--------
from Opik import OpikApi

client = OpikApi()
client = OpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
client.is_alive()
"""
_response = self._client_wrapper.httpx_client.request(
Expand Down Expand Up @@ -166,7 +178,10 @@ def version(
--------
from Opik import OpikApi

client = OpikApi()
client = OpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
client.version()
"""
_response = self._client_wrapper.httpx_client.request(
Expand Down Expand Up @@ -207,6 +222,8 @@ class AsyncOpikApi:



api_key : typing.Optional[str]
workspace_name : typing.Optional[str]
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

Expand All @@ -220,14 +237,19 @@ class AsyncOpikApi:
--------
from Opik import AsyncOpikApi

client = AsyncOpikApi()
client = AsyncOpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)
"""

def __init__(
self,
*,
base_url: typing.Optional[str] = None,
environment: OpikApiEnvironment = OpikApiEnvironment.DEFAULT,
api_key: typing.Optional[str] = None,
workspace_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
Expand All @@ -237,6 +259,8 @@ def __init__(
)
self._client_wrapper = AsyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
api_key=api_key,
workspace_name=workspace_name,
httpx_client=httpx_client
if httpx_client is not None
else httpx.AsyncClient(
Expand Down Expand Up @@ -284,7 +308,10 @@ async def is_alive(

from Opik import AsyncOpikApi

client = AsyncOpikApi()
client = AsyncOpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)


async def main() -> None:
Expand Down Expand Up @@ -332,7 +359,10 @@ async def version(

from Opik import AsyncOpikApi

client = AsyncOpikApi()
client = AsyncOpikApi(
api_key="YOUR_API_KEY",
workspace_name="YOUR_WORKSPACE_NAME",
)


async def main() -> None:
Expand Down
33 changes: 30 additions & 3 deletions sdks/python/src/opik/rest_api/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@


class BaseClientWrapper:
def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None):
def __init__(
self,
*,
api_key: typing.Optional[str] = None,
workspace_name: typing.Optional[str] = None,
base_url: str,
timeout: typing.Optional[float] = None,
):
self._api_key = api_key
self._workspace_name = workspace_name
self._base_url = base_url
self._timeout = timeout

def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
}
if self._api_key is not None:
headers["Authorization"] = self._api_key
if self._workspace_name is not None:
headers["Comet-Workspace"] = self._workspace_name
return headers

def get_base_url(self) -> str:
Expand All @@ -28,11 +41,18 @@ class SyncClientWrapper(BaseClientWrapper):
def __init__(
self,
*,
api_key: typing.Optional[str] = None,
workspace_name: typing.Optional[str] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.Client,
):
super().__init__(base_url=base_url, timeout=timeout)
super().__init__(
api_key=api_key,
workspace_name=workspace_name,
base_url=base_url,
timeout=timeout,
)
self.httpx_client = HttpClient(
httpx_client=httpx_client,
base_headers=self.get_headers,
Expand All @@ -45,11 +65,18 @@ class AsyncClientWrapper(BaseClientWrapper):
def __init__(
self,
*,
api_key: typing.Optional[str] = None,
workspace_name: typing.Optional[str] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.AsyncClient,
):
super().__init__(base_url=base_url, timeout=timeout)
super().__init__(
api_key=api_key,
workspace_name=workspace_name,
base_url=base_url,
timeout=timeout,
)
self.httpx_client = AsyncHttpClient(
httpx_client=httpx_client,
base_headers=self.get_headers,
Expand Down
Loading
Loading