Skip to content

Commit

Permalink
OPIK-616 LLM Provider Api key new fields documentation and SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys Tkachenko authored and Borys Tkachenko committed Dec 20, 2024
1 parent 7cae567 commit 264a2e0
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.codahale.metrics.annotation.Timed;
import com.comet.opik.api.BatchDelete;
import com.comet.opik.api.Page;
import com.comet.opik.api.Project;
import com.comet.opik.api.ProviderApiKey;
import com.comet.opik.api.ProviderApiKeyUpdate;
Expand Down Expand Up @@ -67,16 +66,14 @@ public Response find() {
log.info("Found LLM Provider's ApiKeys for workspaceId '{}'", workspaceId);

return Response.ok().entity(
providerApiKeyPage.toBuilder()
.content(
providerApiKeyPage.content().stream()
.map(providerApiKey -> providerApiKey.toBuilder()
.apiKey(maskApiKey(decrypt(providerApiKey.apiKey())))
.build())
.toList()
)
.build()
)
providerApiKeyPage.toBuilder()
.content(
providerApiKeyPage.content().stream()
.map(providerApiKey -> providerApiKey.toBuilder()
.apiKey(maskApiKey(decrypt(providerApiKey.apiKey())))
.build())
.toList())
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
@RegisterArgumentFactory(UUIDArgumentFactory.class)
public interface LlmProviderApiKeyDAO {

@SqlUpdate("INSERT INTO llm_provider_api_key (id, provider, workspace_id, api_key, name, created_by, last_updated_by) " +
@SqlUpdate("INSERT INTO llm_provider_api_key (id, provider, workspace_id, api_key, name, created_by, last_updated_by) "
+
"VALUES (:bean.id, :bean.provider, :workspaceId, :bean.apiKey, :bean.name, :bean.createdBy, :bean.lastUpdatedBy)")
void save(@Bind("workspaceId") String workspaceId,
@BindMethods("bean") ProviderApiKey providerApiKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.comet.opik.domain;

import com.comet.opik.api.Page;
import com.comet.opik.api.ProviderApiKey;
import com.comet.opik.api.ProviderApiKeyUpdate;
import com.comet.opik.api.error.EntityAlreadyExistsException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@RegisterConstructorMapper(PromptVersionId.class)
interface PromptVersionDAO {

@SqlUpdate("INSERT INTO prompt_versions (id, prompt_id, commit, template, metadata, change_description, created_by, workspace_id) " +
@SqlUpdate("INSERT INTO prompt_versions (id, prompt_id, commit, template, metadata, change_description, created_by, workspace_id) "
+
"VALUES (:bean.id, :bean.promptId, :bean.commit, :bean.template, :bean.metadata, :bean.changeDescription, :bean.createdBy, :workspace_id)")
void save(@Bind("workspace_id") String workspaceId, @BindMethods("bean") PromptVersion prompt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ public enum ModelPrice {
SpanCostCalculator::textGenerationCost),

// Update for 2024-12-18
gpt_4o_mini_audio_preview_2024_12_17("gpt-4o-mini-audio-preview-2024-12-17", new BigDecimal("0.00000015"), new BigDecimal("0.0000006"),
gpt_4o_mini_audio_preview_2024_12_17("gpt-4o-mini-audio-preview-2024-12-17", new BigDecimal("0.00000015"),
new BigDecimal("0.0000006"),
SpanCostCalculator::textGenerationCost),
o1("o1", new BigDecimal("0.000015"), new BigDecimal("0.00006"),
SpanCostCalculator::textGenerationCost),
o1_2024_12_17("o1-2024-12-17", new BigDecimal("0.000015"), new BigDecimal("0.000060"),
SpanCostCalculator::textGenerationCost),
gpt_4o_realtime_preview_2024_12_17("gpt-4o-realtime-preview-2024-12-17", new BigDecimal("0.000005"), new BigDecimal("0.00002"),
gpt_4o_realtime_preview_2024_12_17("gpt-4o-realtime-preview-2024-12-17", new BigDecimal("0.000005"),
new BigDecimal("0.00002"),
SpanCostCalculator::textGenerationCost),
gpt_4o_mini_realtime_preview("gpt-4o-mini-realtime-preview", new BigDecimal("0.0000006"), new BigDecimal("0.0000024"),
gpt_4o_mini_realtime_preview("gpt-4o-mini-realtime-preview", new BigDecimal("0.0000006"),
new BigDecimal("0.0000024"),
SpanCostCalculator::textGenerationCost),
gpt_4o_mini_realtime_preview_2024_12_17("gpt-4o-mini-realtime-preview-2024-12-17", new BigDecimal("0.0000006"), new BigDecimal("0.0000024"),
gpt_4o_mini_realtime_preview_2024_12_17("gpt-4o-mini-realtime-preview-2024-12-17", new BigDecimal("0.0000006"),
new BigDecimal("0.0000024"),
SpanCostCalculator::textGenerationCost),

DEFAULT("", new BigDecimal("0"), new BigDecimal("0"), SpanCostCalculator::defaultCost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ProviderApiKeyManufacturer extends AbstractTypeManufacturer<Provide

@Override
public ProviderApiKey getType(DataProviderStrategy strategy, AttributeMetadata metadata,
ManufacturingContext context) {
ManufacturingContext context) {

UUID id = strategy.getTypeValue(metadata, context, UUID.class);

Expand Down
19 changes: 19 additions & 0 deletions apps/opik-documentation/documentation/rest_api/opik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3833,6 +3833,7 @@ components:
type: string
ProviderApiKey_Public:
required:
- api_key
- provider
type: object
properties:
Expand All @@ -3844,6 +3845,12 @@ components:
type: string
enum:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
created_at:
type: string
format: date-time
Expand Down Expand Up @@ -3874,6 +3881,10 @@ components:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
created_at:
type: string
format: date-time
Expand All @@ -3900,13 +3911,21 @@ components:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
ProviderApiKeyUpdate:
required:
- api_key
type: object
properties:
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
Project:
required:
- name
Expand Down
19 changes: 19 additions & 0 deletions sdks/code_generation/fern/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3833,6 +3833,7 @@ components:
type: string
ProviderApiKey_Public:
required:
- api_key
- provider
type: object
properties:
Expand All @@ -3844,6 +3845,12 @@ components:
type: string
enum:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
created_at:
type: string
format: date-time
Expand Down Expand Up @@ -3874,6 +3881,10 @@ components:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
created_at:
type: string
format: date-time
Expand All @@ -3900,13 +3911,21 @@ components:
- openai
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
ProviderApiKeyUpdate:
required:
- api_key
type: object
properties:
api_key:
type: string
name:
maxLength: 150
minLength: 0
type: string
Project:
required:
- name
Expand Down
26 changes: 24 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 @@ -112,7 +112,11 @@ def find_llm_provider_keys(
raise ApiError(status_code=_response.status_code, body=_response_json)

def store_llm_provider_api_key(
self, *, api_key: str, request_options: typing.Optional[RequestOptions] = None
self,
*,
api_key: str,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Store LLM Provider's ApiKey
Expand All @@ -121,6 +125,8 @@ def store_llm_provider_api_key(
----------
api_key : str
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Expand All @@ -142,6 +148,7 @@ def store_llm_provider_api_key(
method="POST",
json={
"api_key": api_key,
"name": name,
"provider": "openai",
},
headers={
Expand Down Expand Up @@ -239,6 +246,7 @@ def update_llm_provider_api_key(
id: str,
*,
api_key: str,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Expand All @@ -250,6 +258,8 @@ def update_llm_provider_api_key(
api_key : str
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Expand All @@ -272,6 +282,7 @@ def update_llm_provider_api_key(
method="PATCH",
json={
"api_key": api_key,
"name": name,
},
headers={
"content-type": "application/json",
Expand Down Expand Up @@ -427,7 +438,11 @@ async def main() -> None:
raise ApiError(status_code=_response.status_code, body=_response_json)

async def store_llm_provider_api_key(
self, *, api_key: str, request_options: typing.Optional[RequestOptions] = None
self,
*,
api_key: str,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Store LLM Provider's ApiKey
Expand All @@ -436,6 +451,8 @@ async def store_llm_provider_api_key(
----------
api_key : str
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Expand Down Expand Up @@ -465,6 +482,7 @@ async def main() -> None:
method="POST",
json={
"api_key": api_key,
"name": name,
"provider": "openai",
},
headers={
Expand Down Expand Up @@ -570,6 +588,7 @@ async def update_llm_provider_api_key(
id: str,
*,
api_key: str,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Expand All @@ -581,6 +600,8 @@ async def update_llm_provider_api_key(
api_key : str
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Expand Down Expand Up @@ -611,6 +632,7 @@ async def main() -> None:
method="PATCH",
json={
"api_key": api_key,
"name": name,
},
headers={
"content-type": "application/json",
Expand Down
1 change: 1 addition & 0 deletions sdks/python/src/opik/rest_api/types/provider_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ProviderApiKey(UniversalBaseModel):
id: typing.Optional[str] = None
provider: typing.Literal["openai"] = "openai"
api_key: str
name: typing.Optional[str] = None
created_at: typing.Optional[dt.datetime] = None
created_by: typing.Optional[str] = None
last_updated_at: typing.Optional[dt.datetime] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class ProviderApiKeyPublic(UniversalBaseModel):
id: typing.Optional[str] = None
provider: typing.Literal["openai"] = "openai"
api_key: str
name: typing.Optional[str] = None
created_at: typing.Optional[dt.datetime] = None
created_by: typing.Optional[str] = None
last_updated_at: typing.Optional[dt.datetime] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
*/
export interface ProviderApiKeyUpdate {
apiKey: string;
name?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
*/
export interface ProviderApiKeyWrite {
apiKey: string;
name?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ProviderApiKey {
id?: string;
provider: "openai";
apiKey: string;
name?: string;
createdAt?: Date;
createdBy?: string;
lastUpdatedAt?: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
export interface ProviderApiKeyPublic {
id?: string;
provider: "openai";
apiKey: string;
name?: string;
createdAt?: Date;
createdBy?: string;
lastUpdatedAt?: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export declare const ProviderApiKeyUpdate: core.serialization.Schema<serializers
export declare namespace ProviderApiKeyUpdate {
interface Raw {
api_key: string;
name?: string | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ exports.ProviderApiKeyUpdate = void 0;
const core = __importStar(require("../../../../../core"));
exports.ProviderApiKeyUpdate = core.serialization.object({
apiKey: core.serialization.property("api_key", core.serialization.string()),
name: core.serialization.string().optional(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export declare const ProviderApiKeyWrite: core.serialization.Schema<serializers.
export declare namespace ProviderApiKeyWrite {
interface Raw {
api_key: string;
name?: string | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ exports.ProviderApiKeyWrite = void 0;
const core = __importStar(require("../../../../../core"));
exports.ProviderApiKeyWrite = core.serialization.object({
apiKey: core.serialization.property("api_key", core.serialization.string()),
name: core.serialization.string().optional(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export declare namespace ProviderApiKey {
id?: string | null;
provider: "openai";
api_key: string;
name?: string | null;
created_at?: string | null;
created_by?: string | null;
last_updated_at?: string | null;
Expand Down
Loading

0 comments on commit 264a2e0

Please sign in to comment.