Skip to content

Commit

Permalink
fix metadata support
Browse files Browse the repository at this point in the history
  • Loading branch information
agola11 committed Mar 28, 2024
1 parent 25808cf commit a5560ce
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@
},
"./package.json": "./package.json"
}
}
}
5 changes: 4 additions & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export type CreateExampleOptions = {
datasetName?: string;
createdAt?: Date;
exampleId?: string;

metadata?: KVMap;
};

type AutoBatchQueueItem = {
Expand Down Expand Up @@ -1867,7 +1869,7 @@ export class Client {
public async createExample(
inputs: KVMap,
outputs: KVMap,
{ datasetId, datasetName, createdAt, exampleId }: CreateExampleOptions
{ datasetId, datasetName, createdAt, exampleId, metadata }: CreateExampleOptions
): Promise<Example> {
let datasetId_ = datasetId;
if (datasetId_ === undefined && datasetName === undefined) {
Expand All @@ -1886,6 +1888,7 @@ export class Client {
outputs,
created_at: createdAt_?.toISOString(),
id: exampleId,
metadata,
};

const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
Expand Down
2 changes: 2 additions & 0 deletions js/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface BaseExample {
dataset_id: string;
inputs: KVMap;
outputs?: KVMap;
metadata?: KVMap;
}

/**
Expand Down Expand Up @@ -222,6 +223,7 @@ export interface ExampleUpdate {
dataset_id?: string;
inputs?: KVMap;
outputs?: KVMap;
metadata?: KVMap;
}
export interface BaseDataset {
name: string;
Expand Down
10 changes: 10 additions & 0 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,22 @@ test.concurrent(
{ output: "hi there" },
{
datasetId: dataset.id,
metadata: { key: "value" },
}
);
const exampleValue = await client.readExample(example.id);
const initialVersion = exampleValue.modified_at;
expect(exampleValue.inputs.input).toEqual("hello world");
expect(exampleValue?.outputs?.output).toEqual("hi there");
expect(exampleValue?.metadata?.key).toEqual("value");

// Update the example by modifying the metadata
await client.updateExample(example.id, {
metadata: { key: "new value" },
});
const updatedExampleValue = await client.readExample(example.id);
expect(updatedExampleValue?.metadata?.key).toEqual("new value");

// Create multiple
await client.createExamples({
inputs: [
Expand Down
2 changes: 2 additions & 0 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,8 @@ def update_example(
The input values to update.
outputs : Mapping[str, Any] or None, default=None
The output values to update.
metadata : Dict or None, default=None
The metadata to update.
dataset_id : UUID or None, default=None
The ID of the dataset to update.
Expand Down
1 change: 1 addition & 0 deletions python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class ExampleUpdate(BaseModel):
dataset_id: Optional[UUID] = None
inputs: Optional[Dict[str, Any]] = None
outputs: Optional[Dict[str, Any]] = None
metadata: Optional[Dict[str, Any]] = None

class Config:
"""Configuration class for the schema."""
Expand Down
2 changes: 2 additions & 0 deletions python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ def test_datasets(langchain_client: Client) -> None:
example_id=example.id,
inputs={"col1": "updatedExampleCol1"},
outputs={"col2": "updatedExampleCol2"},
metadata={"foo": "bar"},
)
updated_example = langchain_client.read_example(example.id)
assert updated_example.id == example.id
updated_example_value = langchain_client.read_example(updated_example.id)
assert updated_example_value.inputs["col1"] == "updatedExampleCol1"
assert updated_example_value.outputs is not None
assert updated_example_value.outputs["col2"] == "updatedExampleCol2"
assert updated_example_value.metadata["foo"] == "bar"

langchain_client.delete_example(example.id)
examples2 = list(
Expand Down

0 comments on commit a5560ce

Please sign in to comment.