Skip to content

Commit d996213

Browse files
authored
Merge branch 'main' into main
2 parents f05244f + 3457624 commit d996213

File tree

15 files changed

+99
-43
lines changed

15 files changed

+99
-43
lines changed

.config/nextest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ slow-timeout = { period = "60s", terminate-after = 2 }
8181

8282
[[profile.default.overrides]]
8383
filter = 'binary(e2e) and test(providers::sglang::)'
84+
# The model we run on SGLang often fails to emit valid tool calls, so we need many retries
85+
retries = { backoff = "fixed", count = 8, delay = "10s", jitter = true }
8486
slow-timeout = { period = "60s", terminate-after = 2 }
8587

8688
[[profile.default.overrides]]

evaluations/tests/common/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77
use tensorzero::{
88
ChatInferenceDatapoint, Client, ClientBuilder, ClientBuilderMode, JsonInferenceDatapoint,
99
};
10-
use tensorzero_core::clickhouse::test_helpers::{get_clickhouse, CLICKHOUSE_URL};
10+
use tensorzero_core::clickhouse::{
11+
test_helpers::{get_clickhouse, CLICKHOUSE_URL},
12+
TableName,
13+
};
1114
use uuid::Uuid;
1215

1316
/// Takes a chat fixture as a path to a JSONL file and writes the fixture to the dataset.
@@ -32,7 +35,7 @@ pub async fn write_chat_fixture_to_dataset(
3235
}
3336
let clickhouse = get_clickhouse().await;
3437
clickhouse
35-
.write(&datapoints, "ChatInferenceDatapoint")
38+
.write(&datapoints, TableName::ChatInferenceDatapoint)
3639
.await
3740
.unwrap();
3841
}
@@ -56,7 +59,7 @@ pub async fn write_json_fixture_to_dataset(
5659
}
5760
let clickhouse = get_clickhouse().await;
5861
clickhouse
59-
.write(&datapoints, "JsonInferenceDatapoint")
62+
.write(&datapoints, TableName::JsonInferenceDatapoint)
6063
.await
6164
.unwrap();
6265
}

tensorzero-core/src/cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use std::sync::Arc;
33

4-
use crate::clickhouse::ClickHouseConnectionInfo;
4+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
55
use crate::embeddings::{EmbeddingRequest, EmbeddingResponse};
66
use crate::error::{Error, ErrorDetails};
77
use crate::inference::types::file::serialize_with_file_data;
@@ -270,7 +270,7 @@ pub fn start_cache_write<T: Serialize + CacheOutput + Send + Sync + 'static>(
270270
finish_reason,
271271
},
272272
}],
273-
"ModelInferenceCache",
273+
TableName::ModelInferenceCache,
274274
)
275275
.await
276276
{
@@ -337,7 +337,7 @@ pub fn start_cache_write_streaming(
337337
finish_reason,
338338
},
339339
}],
340-
"ModelInferenceCache",
340+
TableName::ModelInferenceCache,
341341
)
342342
.await
343343
});

tensorzero-core/src/clickhouse/migration_manager/migrations/migration_0033.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::check_table_exists;
22
use crate::clickhouse::migration_manager::migration_trait::Migration;
33
use crate::clickhouse::migration_manager::migrations::table_is_nonempty;
4-
use crate::clickhouse::ClickHouseConnectionInfo;
4+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
55
use crate::error::Error;
66
use async_trait::async_trait;
77
use uuid::Uuid;
@@ -59,7 +59,7 @@ impl Migration for Migration0033<'_> {
5959
&[serde_json::json!({
6060
"deployment_id": deployment_id,
6161
})],
62-
"DeploymentID",
62+
TableName::DeploymentID,
6363
)
6464
.await?;
6565

tensorzero-core/src/clickhouse/migration_manager/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod migrations;
33

44
use std::time::{Duration, Instant};
55

6-
use crate::clickhouse::ClickHouseConnectionInfo;
6+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
77
use crate::endpoints::status::TENSORZERO_VERSION;
88
use crate::error::{Error, ErrorDetails};
99
use crate::serde_util::deserialize_u64;
@@ -147,7 +147,7 @@ async fn insert_migration_record(
147147
execution_time_ms: execution_time.as_millis() as u64,
148148
applied_at: None,
149149
}],
150-
"TensorZeroMigration",
150+
TableName::TensorZeroMigration,
151151
)
152152
.await?;
153153
Ok(())

tensorzero-core/src/clickhouse/mod.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,47 @@ pub fn make_clickhouse_http_client() -> Result<Client, Error> {
5151
})
5252
}
5353

54+
/// Defines all of the ClickHouse tables that we write to from Rust
55+
/// This will be used to implement per-table ClickHouse write batching.
56+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
57+
pub enum TableName {
58+
BatchModelInference,
59+
BatchRequest,
60+
ChatInference,
61+
ChatInferenceDatapoint,
62+
JsonInference,
63+
JsonInferenceDatapoint,
64+
ModelInference,
65+
ModelInferenceCache,
66+
DeploymentID,
67+
TensorZeroMigration,
68+
BooleanMetricFeedback,
69+
FloatMetricFeedback,
70+
DemonstrationFeedback,
71+
CommentFeedback,
72+
}
73+
74+
impl TableName {
75+
pub fn as_str(self) -> &'static str {
76+
match self {
77+
TableName::BatchModelInference => "BatchModelInference",
78+
TableName::BatchRequest => "BatchRequest",
79+
TableName::ChatInference => "ChatInference",
80+
TableName::ChatInferenceDatapoint => "ChatInferenceDatapoint",
81+
TableName::JsonInference => "JsonInference",
82+
TableName::JsonInferenceDatapoint => "JsonInferenceDatapoint",
83+
TableName::ModelInference => "ModelInference",
84+
TableName::ModelInferenceCache => "ModelInferenceCache",
85+
TableName::DeploymentID => "DeploymentID",
86+
TableName::TensorZeroMigration => "TensorZeroMigration",
87+
TableName::BooleanMetricFeedback => "BooleanMetricFeedback",
88+
TableName::FloatMetricFeedback => "FloatMetricFeedback",
89+
TableName::DemonstrationFeedback => "DemonstrationFeedback",
90+
TableName::CommentFeedback => "CommentFeedback",
91+
}
92+
}
93+
}
94+
5495
impl ClickHouseConnectionInfo {
5596
/// Create a new ClickHouse connection info from a database URL.
5697
/// You should always use this function in production code or generic integration tests that
@@ -121,18 +162,18 @@ impl ClickHouseConnectionInfo {
121162
pub async fn write(
122163
&self,
123164
rows: &[impl Serialize + Send + Sync],
124-
table: &str,
165+
table: TableName,
125166
) -> Result<(), Error> {
126167
match self {
127168
Self::Disabled => Ok(()),
128169
Self::Mock { mock_data, .. } => {
129-
write_mock(rows, table, &mut mock_data.write().await).await
170+
write_mock(rows, table.as_str(), &mut mock_data.write().await).await
130171
}
131172
Self::Production {
132173
database_url,
133174
client,
134175
..
135-
} => write_production(database_url, client, rows, table).await,
176+
} => write_production(database_url, client, rows, table.as_str()).await,
136177
}
137178
}
138179

tensorzero-core/src/endpoints/batch_inference.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::inference::{
1818
InferenceIds, InferenceModels, InferenceParams, InferenceResponse, JsonInferenceResponse,
1919
};
2020
use crate::cache::{CacheEnabledMode, CacheOptions};
21-
use crate::clickhouse::ClickHouseConnectionInfo;
21+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
2222
use crate::config_parser::Config;
2323
use crate::error::{Error, ErrorDetails};
2424
use crate::function::{sample_variant, FunctionConfig};
@@ -632,7 +632,7 @@ async fn write_start_batch_inference<'a>(
632632
}
633633

634634
clickhouse_connection_info
635-
.write(rows.as_slice(), "BatchModelInference")
635+
.write(rows.as_slice(), TableName::BatchModelInference)
636636
.await?;
637637

638638
let batch_request_insert = BatchRequestRow::new(UnparsedBatchRequestRow {
@@ -663,7 +663,7 @@ pub async fn write_batch_request_row(
663663
batch_request: &BatchRequestRow<'_>,
664664
) -> Result<(), Error> {
665665
clickhouse_connection_info
666-
.write(&[batch_request], "BatchRequest")
666+
.write(&[batch_request], TableName::BatchRequest)
667667
.await
668668
}
669669

@@ -761,7 +761,7 @@ async fn write_batch_request_status_update(
761761
errors: vec![], // TODO (#503): add better error handling
762762
});
763763
clickhouse_connection_info
764-
.write(&[batch_request_insert], "BatchRequest")
764+
.write(&[batch_request_insert], TableName::BatchRequest)
765765
.await?;
766766
Ok(())
767767
}
@@ -919,18 +919,18 @@ pub async fn write_completed_batch_inference<'a>(
919919
match &**function {
920920
FunctionConfig::Chat(_chat_function) => {
921921
clickhouse_connection_info
922-
.write(&inference_rows_to_write, "ChatInference")
922+
.write(&inference_rows_to_write, TableName::ChatInference)
923923
.await?;
924924
}
925925
FunctionConfig::Json(_json_function) => {
926926
clickhouse_connection_info
927-
.write(&inference_rows_to_write, "JsonInference")
927+
.write(&inference_rows_to_write, TableName::JsonInference)
928928
.await?;
929929
}
930930
}
931931
// Write all the ModelInference rows to the database
932932
clickhouse_connection_info
933-
.write(&model_inference_rows_to_write, "ModelInference")
933+
.write(&model_inference_rows_to_write, TableName::ModelInference)
934934
.await?;
935935

936936
Ok(inferences)

tensorzero-core/src/endpoints/datasets.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::clickhouse::TableName;
12
use crate::function::FunctionConfigType;
23
#[cfg(feature = "pyo3")]
34
use crate::inference::types::pyo3_helpers::{
@@ -1088,10 +1089,10 @@ pub enum DatapointKind {
10881089
}
10891090

10901091
impl DatapointKind {
1091-
pub fn table_name(&self) -> &'static str {
1092+
pub fn table_name(&self) -> TableName {
10921093
match self {
1093-
DatapointKind::Chat => "ChatInferenceDatapoint",
1094-
DatapointKind::Json => "JsonInferenceDatapoint",
1094+
DatapointKind::Chat => TableName::ChatInferenceDatapoint,
1095+
DatapointKind::Json => TableName::JsonInferenceDatapoint,
10951096
}
10961097
}
10971098
}

tensorzero-core/src/endpoints/feedback.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::time::Instant;
1212
use tracing::instrument;
1313
use uuid::Uuid;
1414

15-
use crate::clickhouse::ClickHouseConnectionInfo;
15+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
1616
use crate::config_parser::{Config, MetricConfigLevel, MetricConfigType};
1717
use crate::error::{Error, ErrorDetails};
1818
use crate::function::FunctionConfig;
@@ -274,7 +274,9 @@ async fn write_comment(
274274
});
275275
if !dryrun {
276276
tokio::spawn(async move {
277-
let _ = connection_info.write(&[payload], "CommentFeedback").await;
277+
let _ = connection_info
278+
.write(&[payload], TableName::CommentFeedback)
279+
.await;
278280
});
279281
}
280282
Ok(())
@@ -314,7 +316,7 @@ async fn write_demonstration(
314316
if !dryrun {
315317
tokio::spawn(async move {
316318
let _ = connection_info
317-
.write(&[payload], "DemonstrationFeedback")
319+
.write(&[payload], TableName::DemonstrationFeedback)
318320
.await;
319321
});
320322
}
@@ -353,7 +355,7 @@ async fn write_float(
353355
if !dryrun {
354356
tokio::spawn(async move {
355357
let _ = connection_info
356-
.write(&[payload], "FloatMetricFeedback")
358+
.write(&[payload], TableName::FloatMetricFeedback)
357359
.await;
358360
});
359361
}
@@ -390,7 +392,7 @@ async fn write_boolean(
390392
if !dryrun {
391393
tokio::spawn(async move {
392394
let _ = connection_info
393-
.write(&[payload], "BooleanMetricFeedback")
395+
.write(&[payload], TableName::BooleanMetricFeedback)
394396
.await;
395397
});
396398
}

tensorzero-core/src/endpoints/inference.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing::instrument;
2121
use uuid::Uuid;
2222

2323
use crate::cache::{CacheOptions, CacheParamsOptions};
24-
use crate::clickhouse::ClickHouseConnectionInfo;
24+
use crate::clickhouse::{ClickHouseConnectionInfo, TableName};
2525
use crate::config_parser::{Config, ObjectStoreInfo};
2626
use crate::embeddings::EmbeddingModelTable;
2727
use crate::error::{Error, ErrorDetails};
@@ -843,7 +843,7 @@ async fn write_inference(
843843
// Write the model responses to the ModelInference table
844844
for response in model_responses {
845845
let _ = clickhouse_connection_info
846-
.write(&[response], "ModelInference")
846+
.write(&[response], TableName::ModelInference)
847847
.await;
848848
}
849849
// Write the inference to the Inference table
@@ -852,14 +852,14 @@ async fn write_inference(
852852
let chat_inference =
853853
ChatInferenceDatabaseInsert::new(result, input.clone(), metadata);
854854
let _ = clickhouse_connection_info
855-
.write(&[chat_inference], "ChatInference")
855+
.write(&[chat_inference], TableName::ChatInference)
856856
.await;
857857
}
858858
InferenceResult::Json(result) => {
859859
let json_inference =
860860
JsonInferenceDatabaseInsert::new(result, input.clone(), metadata);
861861
let _ = clickhouse_connection_info
862-
.write(&[json_inference], "JsonInference")
862+
.write(&[json_inference], TableName::JsonInference)
863863
.await;
864864
}
865865
}

0 commit comments

Comments
 (0)