Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metadata to example, allow for creating feedback on the session level #486

Merged
merged 7 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,7 @@ def create_examples(
*,
inputs: Sequence[Mapping[str, Any]],
outputs: Optional[Sequence[Optional[Mapping[str, Any]]]] = None,
metadata: Optional[Sequence[Optional[Mapping[str, Any]]]] = None,
dataset_id: Optional[ID_TYPE] = None,
dataset_name: Optional[str] = None,
**kwargs: Any,
Expand All @@ -2494,6 +2495,8 @@ def create_examples(
The input values for the examples.
outputs : Optional[Sequence[Optional[Mapping[str, Any]]]], default=None
The output values for the examples.
metadata : Optional[Sequence[Optional[Mapping[str, Any]]]], default=None
The metadata for the examples.
dataset_id : Optional[ID_TYPE], default=None
The ID of the dataset to create the examples in.
dataset_name : Optional[str], default=None
Expand All @@ -2518,8 +2521,13 @@ def create_examples(
"inputs": in_,
"outputs": out_,
"dataset_id": dataset_id,
"metadata": metadata_,
}
for in_, out_ in zip(inputs, outputs or [None] * len(inputs))
for in_, out_, metadata_ in zip(
inputs,
outputs or [None] * len(inputs),
metadata or [None] * len(inputs),
)
]

response = self.session.post(
Expand All @@ -2537,6 +2545,7 @@ def create_example(
dataset_name: Optional[str] = None,
created_at: Optional[datetime.datetime] = None,
outputs: Optional[Mapping[str, Any]] = None,
metadata: Optional[Mapping[str, Any]] = None,
example_id: Optional[ID_TYPE] = None,
) -> ls_schemas.Example:
"""Create a dataset example in the LangSmith API.
Expand All @@ -2556,6 +2565,8 @@ def create_example(
The creation timestamp of the example.
outputs : Mapping[str, Any] or None, default=None
The output values for the example.
metadata : Mapping[str, Any] or None, default=None
The metadata for the example.
exemple_id : UUID or None, default=None
The ID of the example to create. If not provided, a new
example will be created.
Expand All @@ -2570,6 +2581,7 @@ def create_example(
"inputs": inputs,
"outputs": outputs,
"dataset_id": dataset_id,
"metadata": metadata,
}
if created_at:
data["created_at"] = created_at.isoformat()
Expand Down Expand Up @@ -2909,7 +2921,7 @@ async def aevaluate_run(

def create_feedback(
self,
run_id: ID_TYPE,
run_id: Optional[ID_TYPE],
key: str,
*,
score: Union[float, int, bool, None] = None,
Expand All @@ -2924,6 +2936,7 @@ def create_feedback(
feedback_id: Optional[ID_TYPE] = None,
feedback_config: Optional[ls_schemas.FeedbackConfig] = None,
stop_after_attempt: int = 10,
session_id: Optional[ID_TYPE] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if both none, xor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a separate method? create_aggregate_feedback()?

**kwargs: Any,
) -> ls_schemas.Feedback:
"""Create a feedback in the LangSmith API.
Expand Down Expand Up @@ -2958,7 +2971,14 @@ def create_feedback(
or freeform.
stop_after_attempt : int, default=10
The number of times to retry the request before giving up.
session_id : str or UUID
The ID of the session to provide feedback on. One - and only one - of
this and run_id must be provided.
"""
if run_id is None and session_id is None:
raise ValueError("One of run_id and session_id must be provided")
if run_id is not None and session_id is not None:
raise ValueError("Only one of run_id and session_id must be provided")
if kwargs:
warnings.warn(
"The following arguments are no longer used in the create_feedback"
Expand Down Expand Up @@ -3006,6 +3026,7 @@ def create_feedback(
created_at=datetime.datetime.now(datetime.timezone.utc),
modified_at=datetime.datetime.now(datetime.timezone.utc),
feedback_config=feedback_config,
session_id=session_id,
)
self.request_with_retries(
"POST",
Expand Down
5 changes: 4 additions & 1 deletion python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ExampleBase(BaseModel):
dataset_id: UUID
inputs: Dict[str, Any]
outputs: Optional[Dict[str, Any]] = Field(default=None)
metadata: Optional[Dict[str, Any]] = Field(default=None)

class Config:
"""Configuration class for the schema."""
Expand Down Expand Up @@ -406,7 +407,7 @@ class FeedbackBase(BaseModel):
"""The time the feedback was created."""
modified_at: Optional[datetime] = None
"""The time the feedback was last modified."""
run_id: UUID
run_id: Optional[UUID]
"""The associated run ID this feedback is logged for."""
key: str
"""The metric name, tag, or aspect to provide feedback on."""
Expand All @@ -420,6 +421,8 @@ class FeedbackBase(BaseModel):
"""Correction for the run."""
feedback_source: Optional[FeedbackSourceBase] = None
"""The source of the feedback."""
session_id: Optional[UUID] = None
"""The associated session ID this feedback is logged for."""

class Config:
"""Configuration class for the schema."""
Expand Down
Loading