Skip to content

Commit

Permalink
OPIK-627 Delete LLM Provider Api key endpoint documentation and SDK code
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys Tkachenko committed Dec 18, 2024
1 parent 16a3403 commit c95e11a
Show file tree
Hide file tree
Showing 24 changed files with 289 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record ProviderApiKeyUpdate(
@NotBlank @JsonDeserialize(using = ProviderApiKeyDeserializer.class) String apiKey
){
@NotBlank @JsonDeserialize(using = ProviderApiKeyDeserializer.class) String apiKey) {

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PATCH;
import jakarta.ws.rs.POST;
Expand Down Expand Up @@ -135,9 +134,11 @@ public Response updateApiKey(@PathParam("id") UUID id,
public Response deleteApiKeys(
@NotNull @RequestBody(content = @Content(schema = @Schema(implementation = BatchDelete.class))) @Valid BatchDelete batchDelete) {
String workspaceId = requestContext.get().getWorkspaceId();
log.info("Deleting api keys for LLM provider by ids, count '{}', on workspace_id '{}'", batchDelete.ids().size(), workspaceId);
log.info("Deleting api keys for LLM provider by ids, count '{}', on workspace_id '{}'",
batchDelete.ids().size(), workspaceId);
llmProviderApiKeyService.delete(batchDelete.ids(), workspaceId);
log.info("Deleted api keys for LLM provider by ids, count '{}', on workspace_id '{}'", batchDelete.ids().size(), workspaceId);
log.info("Deleted api keys for LLM provider by ids, count '{}', on workspace_id '{}'", batchDelete.ids().size(),
workspaceId);
return Response.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ void createAndBatchDeleteProviderApiKeys() {
workspaceName, 201);

// Delete
llmProviderApiKeyResourceClient.batchDeleteProviderApiKey(Set.of(createdProviderApiKey.id()), apiKey, workspaceName);
llmProviderApiKeyResourceClient.batchDeleteProviderApiKey(Set.of(createdProviderApiKey.id()), apiKey,
workspaceName);

// Delete one more time for non existing key, should return same 204 response
llmProviderApiKeyResourceClient.batchDeleteProviderApiKey(Set.of(createdProviderApiKey.id()), apiKey, workspaceName);
llmProviderApiKeyResourceClient.batchDeleteProviderApiKey(Set.of(createdProviderApiKey.id()), apiKey,
workspaceName);

// Check that it was deleted
llmProviderApiKeyResourceClient.getById(createdProviderApiKey.id(), workspaceName, apiKey, 404);
Expand Down
39 changes: 39 additions & 0 deletions apps/opik-documentation/documentation/rest_api/opik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,21 @@ paths:
responses:
"204":
description: No Content
/v1/private/llm-provider-key/delete:
post:
tags:
- LlmProviderKey
summary: Delete LLM Provider's ApiKeys
description: Delete LLM Provider's ApiKeys batch
operationId: deleteLlmProviderApiKeysBatch
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BatchDelete'
responses:
"204":
description: No Content
/v1/private/llm-provider-key:
get:
tags:
Expand Down Expand Up @@ -4422,6 +4437,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
ErrorInfo_Write:
required:
- exception_type
Expand Down Expand Up @@ -4650,6 +4671,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
SpanPage_Public:
type: object
properties:
Expand Down Expand Up @@ -4880,6 +4907,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
Trace_Write:
required:
- name
Expand Down Expand Up @@ -4999,6 +5032,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
TracePage_Public:
type: object
properties:
Expand Down
39 changes: 39 additions & 0 deletions sdks/code_generation/fern/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,21 @@ paths:
responses:
"204":
description: No Content
/v1/private/llm-provider-key/delete:
post:
tags:
- LlmProviderKey
summary: Delete LLM Provider's ApiKeys
description: Delete LLM Provider's ApiKeys batch
operationId: deleteLlmProviderApiKeysBatch
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BatchDelete'
responses:
"204":
description: No Content
/v1/private/llm-provider-key:
get:
tags:
Expand Down Expand Up @@ -4422,6 +4437,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
ErrorInfo_Write:
required:
- exception_type
Expand Down Expand Up @@ -4650,6 +4671,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
SpanPage_Public:
type: object
properties:
Expand Down Expand Up @@ -4880,6 +4907,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
Trace_Write:
required:
- name
Expand Down Expand Up @@ -4999,6 +5032,12 @@ components:
total_estimated_cost:
type: number
readOnly: true
duration:
type: number
description: Duration in milliseconds as a decimal number to support sub-millisecond
precision
format: double
readOnly: true
TracePage_Public:
type: object
properties:
Expand Down
104 changes: 102 additions & 2 deletions sdks/python/src/opik/rest_api/llm_provider_key/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import typing
from ..core.client_wrapper import SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.project_page_public import ProjectPagePublic
from ..core.pydantic_utilities import parse_obj_as
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.project_page_public import ProjectPagePublic
from ..core.pydantic_utilities import parse_obj_as
from ..errors.unauthorized_error import UnauthorizedError
from ..types.error_message import ErrorMessage
from ..errors.forbidden_error import ForbiddenError
Expand All @@ -23,6 +23,52 @@ class LlmProviderKeyClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper

def delete_llm_provider_api_keys_batch(
self,
*,
ids: typing.Sequence[str],
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Delete LLM Provider's ApiKeys batch
Parameters
----------
ids : typing.Sequence[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from Opik import OpikApi
client = OpikApi()
client.llm_provider_key.delete_llm_provider_api_keys_batch(
ids=["ids"],
)
"""
_response = self._client_wrapper.httpx_client.request(
"v1/private/llm-provider-key/delete",
method="POST",
json={
"ids": ids,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def find_llm_provider_keys(
self, *, request_options: typing.Optional[RequestOptions] = None
) -> ProjectPagePublic:
Expand Down Expand Up @@ -276,6 +322,60 @@ class AsyncLlmProviderKeyClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._client_wrapper = client_wrapper

async def delete_llm_provider_api_keys_batch(
self,
*,
ids: typing.Sequence[str],
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Delete LLM Provider's ApiKeys batch
Parameters
----------
ids : typing.Sequence[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
import asyncio
from Opik import AsyncOpikApi
client = AsyncOpikApi()
async def main() -> None:
await client.llm_provider_key.delete_llm_provider_api_keys_batch(
ids=["ids"],
)
asyncio.run(main())
"""
_response = await self._client_wrapper.httpx_client.request(
"v1/private/llm-provider-key/delete",
method="POST",
json={
"ids": ids,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def find_llm_provider_keys(
self, *, request_options: typing.Optional[RequestOptions] = None
) -> ProjectPagePublic:
Expand Down
4 changes: 4 additions & 0 deletions sdks/python/src/opik/rest_api/types/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Span(UniversalBaseModel):
last_updated_by: typing.Optional[str] = None
feedback_scores: typing.Optional[typing.List[FeedbackScore]] = None
total_estimated_cost: typing.Optional[float] = None
duration: typing.Optional[float] = pydantic.Field(default=None)
"""
Duration in milliseconds as a decimal number to support sub-millisecond precision
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
Expand Down
6 changes: 5 additions & 1 deletion sdks/python/src/opik/rest_api/types/span_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .json_node_public import JsonNodePublic
from .error_info_public import ErrorInfoPublic
from .feedback_score_public import FeedbackScorePublic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class SpanPublic(UniversalBaseModel):
Expand All @@ -34,6 +34,10 @@ class SpanPublic(UniversalBaseModel):
last_updated_by: typing.Optional[str] = None
feedback_scores: typing.Optional[typing.List[FeedbackScorePublic]] = None
total_estimated_cost: typing.Optional[float] = None
duration: typing.Optional[float] = pydantic.Field(default=None)
"""
Duration in milliseconds as a decimal number to support sub-millisecond precision
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
Expand Down
4 changes: 4 additions & 0 deletions sdks/python/src/opik/rest_api/types/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Trace(UniversalBaseModel):
last_updated_by: typing.Optional[str] = None
feedback_scores: typing.Optional[typing.List[FeedbackScore]] = None
total_estimated_cost: typing.Optional[float] = None
duration: typing.Optional[float] = pydantic.Field(default=None)
"""
Duration in milliseconds as a decimal number to support sub-millisecond precision
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
Expand Down
6 changes: 5 additions & 1 deletion sdks/python/src/opik/rest_api/types/trace_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .json_node_public import JsonNodePublic
from .error_info_public import ErrorInfoPublic
from .feedback_score_public import FeedbackScorePublic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class TracePublic(UniversalBaseModel):
Expand All @@ -28,6 +28,10 @@ class TracePublic(UniversalBaseModel):
last_updated_by: typing.Optional[str] = None
feedback_scores: typing.Optional[typing.List[FeedbackScorePublic]] = None
total_estimated_cost: typing.Optional[float] = None
duration: typing.Optional[float] = pydantic.Field(default=None)
"""
Duration in milliseconds as a decimal number to support sub-millisecond precision
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
Expand Down
Loading

0 comments on commit c95e11a

Please sign in to comment.