Skip to content

Commit

Permalink
NO-JIRA: Updated Python SDK fern autogenerated code (#700)
Browse files Browse the repository at this point in the history
* NO-JIRA: Updated Python SDK fern autogenerated code

* Rev2: update README.md
  • Loading branch information
andrescrz authored and Sasha committed Nov 25, 2024
1 parent 3431132 commit b598ac7
Show file tree
Hide file tree
Showing 33 changed files with 1,028 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import java.time.Instant;

@Builder(toBuilder = true)
public record DataPoint(Instant time, Number value) {}
public record DataPoint(Instant time, Number value) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public record ProjectMetricRequest(
@NonNull MetricType metricType,
@NonNull TimeInterval interval,
Instant intervalStart,
Instant intervalEnd) {}
Instant intervalEnd) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Builder;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

Expand All @@ -27,5 +26,6 @@ public record ProjectMetricResponse(
@Builder(toBuilder = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record Results(String name, List<DataPoint> data) {}
public record Results(String name, List<DataPoint> data) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.comet.opik.domain;

import com.comet.opik.api.DataPoint;
import com.comet.opik.api.metrics.ProjectMetricRequest;
import com.comet.opik.api.metrics.ProjectMetricResponse;
import com.comet.opik.infrastructure.db.TransactionTemplateAsync;
Expand Down Expand Up @@ -37,7 +36,7 @@ public Mono<ProjectMetricResponse> getProjectMetrics(UUID projectId, ProjectMetr
validate(request);

return template.nonTransaction(connection -> projectMetricsDAO.getTraceCount(projectId, request,
connection)
connection)
.map(dataPoints -> ProjectMetricResponse.builder()
.projectId(projectId)
.metricType(request.metricType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ private Publisher<? extends Result> insert(List<Span> spans, Connection connecti
.bind("model" + i, span.model() != null ? span.model() : "")
.bind("provider" + i, span.provider() != null ? span.provider() : "")
.bind("total_estimated_cost" + i, estimatedCost.toString())
.bind("total_estimated_cost_version" + i, estimatedCost.compareTo(ZERO_COST) > 0 ? ESTIMATED_COST_VERSION : "")
.bind("total_estimated_cost_version" + i,
estimatedCost.compareTo(ZERO_COST) > 0 ? ESTIMATED_COST_VERSION : "")
.bind("tags" + i, span.tags() != null ? span.tags().toArray(String[]::new) : new String[]{})
.bind("created_by" + i, userName)
.bind("last_updated_by" + i, userName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,63 @@
@Getter
public enum ModelPrice {
gpt_4o("gpt-4o", new BigDecimal("0.0000025"), new BigDecimal("0.000010"), SpanCostCalculator::textGenerationCost),
gpt_4o_2024_08_06("gpt-4o-2024-08-06", new BigDecimal("0.0000025"), new BigDecimal("0.000010"), SpanCostCalculator::textGenerationCost),
gpt_4o_audio_preview("gpt-4o-audio-preview", new BigDecimal("0.0000025"), new BigDecimal("0.000010"), SpanCostCalculator::textGenerationCost),
gpt_4o_audio_preview_2024_10_01("gpt-4o-audio-preview-2024-10-01", new BigDecimal("0.0000025"), new BigDecimal("0.000010"), SpanCostCalculator::textGenerationCost),
gpt_4o_2024_05_13("gpt-4o-2024-05-13", new BigDecimal("0.000005"), new BigDecimal("0.000015"), SpanCostCalculator::textGenerationCost),
gpt_4o_mini("gpt-4o-mini", new BigDecimal("0.00000015"), new BigDecimal("0.00000060"), SpanCostCalculator::textGenerationCost),
gpt_4o_mini_2024_07_18("gpt-4o-mini-2024-07-18", new BigDecimal("0.00000015"), new BigDecimal("0.00000060"), SpanCostCalculator::textGenerationCost),
o1_preview("o1-preview", new BigDecimal("0.000015"), new BigDecimal("0.000060"), SpanCostCalculator::textGenerationCost),
o1_preview_2024_09_12("o1-preview-2024-09-12", new BigDecimal("0.000015"), new BigDecimal("0.000060"), SpanCostCalculator::textGenerationCost),
gpt_4o_2024_08_06("gpt-4o-2024-08-06", new BigDecimal("0.0000025"), new BigDecimal("0.000010"),
SpanCostCalculator::textGenerationCost),
gpt_4o_audio_preview("gpt-4o-audio-preview", new BigDecimal("0.0000025"), new BigDecimal("0.000010"),
SpanCostCalculator::textGenerationCost),
gpt_4o_audio_preview_2024_10_01("gpt-4o-audio-preview-2024-10-01", new BigDecimal("0.0000025"),
new BigDecimal("0.000010"), SpanCostCalculator::textGenerationCost),
gpt_4o_2024_05_13("gpt-4o-2024-05-13", new BigDecimal("0.000005"), new BigDecimal("0.000015"),
SpanCostCalculator::textGenerationCost),
gpt_4o_mini("gpt-4o-mini", new BigDecimal("0.00000015"), new BigDecimal("0.00000060"),
SpanCostCalculator::textGenerationCost),
gpt_4o_mini_2024_07_18("gpt-4o-mini-2024-07-18", new BigDecimal("0.00000015"), new BigDecimal("0.00000060"),
SpanCostCalculator::textGenerationCost),
o1_preview("o1-preview", new BigDecimal("0.000015"), new BigDecimal("0.000060"),
SpanCostCalculator::textGenerationCost),
o1_preview_2024_09_12("o1-preview-2024-09-12", new BigDecimal("0.000015"), new BigDecimal("0.000060"),
SpanCostCalculator::textGenerationCost),
o1_mini("o1-mini", new BigDecimal("0.000003"), new BigDecimal("0.000012"), SpanCostCalculator::textGenerationCost),
o1_mini_2024_09_12("o1-mini-2024-09-12", new BigDecimal("0.000003"), new BigDecimal("0.000012"), SpanCostCalculator::textGenerationCost),
gpt_4o_realtime_preview("gpt-4o-realtime-preview", new BigDecimal("0.000005"), new BigDecimal("0.000020"), SpanCostCalculator::textGenerationCost),
gpt_4o_realtime_preview_2024_10_01("gpt-4o-realtime-preview-2024-10-01", new BigDecimal("0.000005"), new BigDecimal("0.000020"),
o1_mini_2024_09_12("o1-mini-2024-09-12", new BigDecimal("0.000003"), new BigDecimal("0.000012"),
SpanCostCalculator::textGenerationCost),
gpt_4o_realtime_preview("gpt-4o-realtime-preview", new BigDecimal("0.000005"), new BigDecimal("0.000020"),
SpanCostCalculator::textGenerationCost),
gpt_4o_realtime_preview_2024_10_01("gpt-4o-realtime-preview-2024-10-01", new BigDecimal("0.000005"),
new BigDecimal("0.000020"),
SpanCostCalculator::textGenerationCost),
chatgpt_4o_latest("chatgpt-4o-latest", new BigDecimal("0.000005"), new BigDecimal("0.000015"),
SpanCostCalculator::textGenerationCost),
gpt_4_turbo("gpt-4-turbo", new BigDecimal("0.000010"), new BigDecimal("0.000030"),
SpanCostCalculator::textGenerationCost),
gpt_4_turbo_2024_04_09("gpt-4-turbo-2024-04-09", new BigDecimal("0.000010"), new BigDecimal("0.000030"),
SpanCostCalculator::textGenerationCost),
chatgpt_4o_latest("chatgpt-4o-latest", new BigDecimal("0.000005"), new BigDecimal("0.000015"), SpanCostCalculator::textGenerationCost),
gpt_4_turbo("gpt-4-turbo", new BigDecimal("0.000010"), new BigDecimal("0.000030"), SpanCostCalculator::textGenerationCost),
gpt_4_turbo_2024_04_09("gpt-4-turbo-2024-04-09", new BigDecimal("0.000010"), new BigDecimal("0.000030"), SpanCostCalculator::textGenerationCost),
gpt_4("gpt-4", new BigDecimal("0.000030"), new BigDecimal("0.000060"), SpanCostCalculator::textGenerationCost),
gpt_4_32k("gpt-4-32k", new BigDecimal("0.000060"), new BigDecimal("0.000120"), SpanCostCalculator::textGenerationCost),
gpt_4_0125_preview("gpt-4-0125-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"), SpanCostCalculator::textGenerationCost),
gpt_4_1106_preview("gpt-4-1106-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"), SpanCostCalculator::textGenerationCost),
gpt_4_vision_preview("gpt-4-vision-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo("gpt-3.5-turbo", new BigDecimal("0.0000015"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0125("gpt-3.5-turbo-0125", new BigDecimal("0.00000050"), new BigDecimal("0.0000015"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_instruct("gpt-3.5-turbo-instruct", new BigDecimal("0.0000015"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_1106("gpt-3.5-turbo-1106", new BigDecimal("0.000001"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0613("gpt-3.5-turbo-0613", new BigDecimal("0.0000015"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_16k_0613("gpt-3.5-turbo-16k-0613", new BigDecimal("0.000003"), new BigDecimal("0.000004"), SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0301("gpt-3.5-turbo-0301", new BigDecimal("0.0000015"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
davinci_002("davinci-002", new BigDecimal("0.000005"), new BigDecimal("0.000002"), SpanCostCalculator::textGenerationCost),
babbage_002("babbage-002", new BigDecimal("0.0000004"), new BigDecimal("0.0000004"), SpanCostCalculator::textGenerationCost),
gpt_4_32k("gpt-4-32k", new BigDecimal("0.000060"), new BigDecimal("0.000120"),
SpanCostCalculator::textGenerationCost),
gpt_4_0125_preview("gpt-4-0125-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"),
SpanCostCalculator::textGenerationCost),
gpt_4_1106_preview("gpt-4-1106-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"),
SpanCostCalculator::textGenerationCost),
gpt_4_vision_preview("gpt-4-vision-preview", new BigDecimal("0.000010"), new BigDecimal("0.000030"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo("gpt-3.5-turbo", new BigDecimal("0.0000015"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0125("gpt-3.5-turbo-0125", new BigDecimal("0.00000050"), new BigDecimal("0.0000015"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_instruct("gpt-3.5-turbo-instruct", new BigDecimal("0.0000015"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_1106("gpt-3.5-turbo-1106", new BigDecimal("0.000001"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0613("gpt-3.5-turbo-0613", new BigDecimal("0.0000015"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_16k_0613("gpt-3.5-turbo-16k-0613", new BigDecimal("0.000003"), new BigDecimal("0.000004"),
SpanCostCalculator::textGenerationCost),
gpt_3_5_turbo_0301("gpt-3.5-turbo-0301", new BigDecimal("0.0000015"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
davinci_002("davinci-002", new BigDecimal("0.000005"), new BigDecimal("0.000002"),
SpanCostCalculator::textGenerationCost),
babbage_002("babbage-002", new BigDecimal("0.0000004"), new BigDecimal("0.0000004"),
SpanCostCalculator::textGenerationCost),
DEFAULT("", new BigDecimal("0"), new BigDecimal("0"), SpanCostCalculator::defaultCost);

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class SpanCostCalculator {
public static BigDecimal textGenerationCost(ModelPrice modelPrice, Map<String, Integer> usage) {
return modelPrice.getInputPrice().multiply(BigDecimal.valueOf(usage.getOrDefault("prompt_tokens", 0)))
.add(modelPrice.getOutputPrice().multiply(BigDecimal.valueOf(usage.getOrDefault("completion_tokens", 0))));
.add(modelPrice.getOutputPrice()
.multiply(BigDecimal.valueOf(usage.getOrDefault("completion_tokens", 0))));
}

public static BigDecimal defaultCost(ModelPrice modelPrice, Map<String, Integer> usage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.comet.opik.api.DataPoint;
import com.comet.opik.api.TimeInterval;
import com.comet.opik.api.Trace;
import com.comet.opik.api.metrics.MetricType;
import com.comet.opik.api.metrics.ProjectMetricRequest;
import com.comet.opik.api.metrics.ProjectMetricResponse;
import com.comet.opik.api.Trace;
import com.comet.opik.api.resources.utils.AuthTestUtils;
import com.comet.opik.api.resources.utils.ClickHouseContainerUtils;
import com.comet.opik.api.resources.utils.ClientSupportUtils;
Expand Down Expand Up @@ -350,7 +350,8 @@ private void createTraces(String projectName, Instant marker, int count) {
.mapToObj(i -> factory.manufacturePojo(Trace.class).toBuilder()
.projectName(projectName)
.startTime(marker.plus(i, ChronoUnit.SECONDS))
.build()).toList();
.build())
.toList();
traceResourceClient.batchCreateTraces(traces, API_KEY, WORKSPACE_NAME);
}

Expand Down
33 changes: 33 additions & 0 deletions sdks/python/code_generation/fern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# How to generate new client code for communication with Opik backend

## Pre-requirements
For either the automatic script or the manual steps:
- You'll need to install the fern SDK: https://github.com/fern-api/fern

This is a one time process in the local machine generating the code.

## Automatic process
> [!IMPORTANT]
> You should generally run this script instead of manual steps below.
> The only pre-requirement is installing the fern SDK.
The following script automates this whole process:
```bash
./scripts/generate_openapi.sh
```

You simply need to run it from the repository base directory.

## Manual process

These are the manual steps (not recommended), as alternative to the automatic script.
In this case, it's also a pre-requirement to install the fern SDK.
Steps:
1. Execute the `./build_and_run.sh script` from the root of repository
2. Go to http://localhost:3003/ (URL for backend API specification)
3. Download openapi specification file - `openapi.yaml`
4. Put this file into `code_generation/fern/openapi/openapi.yaml` (overwrite it).<br>
Note that this path contains the version of the schema from which the code in `src/opik/rest_api` for the SDK was generated. Therefore, it might not be the latest version of the schema.
5. Run `fern generate` from inside `code_generation/fern` folder. This will generate a python code inside the directory called `sdks` near the `fern` one.
7. Replace content of `src/opik/rest_api` with the python package inside `sdks` (there will be few nested directories, navigate until you find python files)
8. Run `pre-commit run --all-files` to format code
Loading

0 comments on commit b598ac7

Please sign in to comment.