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

feat:Add API endpoint for grouped examples with associated runs #184

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Feb 19, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new API endpoint to fetch grouped dataset examples with their associated runs.
    • Enhanced query capabilities with additional parameters for offset, limit, preview, and sorting.
    • Improved response structure for clearer and more organized data delivery.

@github-actions github-actions bot merged commit bbdee1d into main Feb 19, 2025
2 of 3 checks passed
Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

This pull request introduces a new API endpoint for fetching examples with associated runs, grouped by a specified field. It updates the API documentation and enhances the query schema with additional parameters such as offset, limit, preview, and sort options. New schemas for grouping the examples and handling the response have been added alongside a new method in the dataset views to support these changes.

Changes

File(s) Change Summary
src/libs/.../openapi.yaml Added new endpoint /api/v1/datasets/{dataset_id}/group/runs and updated the API documentation with new query parameters and response schema details.
app/.../views.py Introduced the method read_examples_with_runs_grouped to handle the new grouped runs endpoint.
app/.../schemas.py Added QueryGroupedExamplesWithRuns and GroupedExamplesWithRunsResponse schemas, and updated QueryExampleSchemaWithRuns to include offset, limit, preview, and sort_params.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant API as Endpoint Handler
    participant DB as Database
    Client->>API: GET /api/v1/datasets/{dataset_id}/group/runs
    API->>DB: Query grouped examples using QueryGroupedExamplesWithRuns
    DB-->>API: Return grouped examples data
    API-->>Client: Respond with GroupedExamplesWithRunsResponse
Loading

Possibly related PRs

Suggested reviewers

  • github-actions

Poem

I'm a rabbit in a code-filled glen,
Hopping through endpoints time and again.
New routes emerge and schemas gleam,
Grouping runs like a digital dream.
With code so neat, I waddle in delight!
🐇💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Add API endpoint for grouped examples with associated runs Feb 19, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/libs/LangSmith/openapi.yaml (4)

3321-3362: New Endpoint Definition for Grouped Runs
The new /api/v1/datasets/{dataset_id}/group/runs endpoint is well-structured with clearly defined tags, summary, parameters, request body, responses, and security requirements. The description indicates that the endpoint handles associated run fetching based on session IDs; ensure that the documentation (or code comments elsewhere) clarifies exactly how grouping is determined and which field from the request body drives the grouping.


16046-16069: Introduction of GroupExampleRunsByField and GroupedExamplesWithRunsResponse
The new enum GroupExampleRunsByField with values run_metadata and example_metadata is clear and concise. The GroupedExamplesWithRunsResponse schema appropriately mandates a groups property, which is an array of ExampleWithRunsGroup objects. If possible, consider adding example values or additional descriptive documentation to further assist API consumers in understanding the expected data.


18288-18305: Enhancement of Query Parameters for Grouping
The added pagination and preview parameters (offset, limit, and preview) effectively extend query capabilities. To maintain consistency with the integer type, consider using integer literals (e.g., use 1 instead of 1.0) in the minimum and maximum constraints, even though JSON Schema may accept decimals for integers. This small refinement can improve clarity in schema definitions.


18369-18411: Definition of QueryGroupedExamplesWithRuns Schema
The new schema QueryGroupedExamplesWithRuns consolidates several key parameters needed by the endpoint, including session_ids, pagination options (offset, limit, preview), group_by, metadata_key, and per_group_limit. All required fields are appropriately specified. Similar to the previous comment, consider using whole number literals for numeric boundaries (e.g., 0 instead of 0.0 and 1 instead of 1.0) for enhanced clarity. Ensure that the documentation clearly communicates the purpose of each field, especially for new API consumers who may depend on these details when constructing queries.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5b231e and a84e79d.

⛔ Files ignored due to path filters (22)
  • src/libs/LangSmith/Generated/JsonConverters.GroupExampleRunsByField.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/JsonConverters.GroupExampleRunsByFieldNullable.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/JsonSerializerContext.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/JsonSerializerContextTypes.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.DatasetsClient.ReadExamplesWithRuns.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.DatasetsClient.ReadExamplesWithRunsGrouped.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.IDatasetsClient.ReadExamplesWithRuns.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.IDatasetsClient.ReadExamplesWithRunsGrouped.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.IPublicClient.ReadSharedDatasetExamplesWithRuns.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroup.Json.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroup.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroupFeedbackStats.Json.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroupFeedbackStats.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroupGroupKey.Json.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.ExampleWithRunsGroupGroupKey.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.GroupExampleRunsByField.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.GroupedExamplesWithRunsResponse.Json.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.GroupedExamplesWithRunsResponse.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.QueryExampleSchemaWithRuns.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.QueryGroupedExamplesWithRuns.Json.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.Models.QueryGroupedExamplesWithRuns.g.cs is excluded by !**/generated/**
  • src/libs/LangSmith/Generated/LangSmith.PublicClient.ReadSharedDatasetExamplesWithRuns.g.cs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • src/libs/LangSmith/openapi.yaml (6 hunks)
🔇 Additional comments (1)
src/libs/LangSmith/openapi.yaml (1)

18314-18321: Integration of Sort Parameters
The introduction of the sort_params property—referencing the SortParamsForRunsComparisonView schema—enhances the query's flexibility for sorting results. Please ensure that the referenced schema is defined comprehensively elsewhere in your OpenAPI document so that it meets the sorting requirements for this endpoint.

Comment on lines +15056 to +15132
ExampleWithRunsGroup:
title: ExampleWithRunsGroup
required:
- filter
- group_key
- examples
type: object
properties:
filter:
title: Filter
type: string
count:
title: Count
type: integer
nullable: true
total_tokens:
title: Total Tokens
type: integer
nullable: true
total_cost:
title: Total Cost
type: string
nullable: true
min_start_time:
title: Min Start Time
type: string
format: date-time
nullable: true
max_start_time:
title: Max Start Time
type: string
format: date-time
nullable: true
latency_p50:
title: Latency P50
type: number
nullable: true
latency_p99:
title: Latency P99
type: number
nullable: true
feedback_stats:
title: Feedback Stats
type: object
nullable: true
group_key:
title: Group Key
examples:
title: Examples
anyOf:
- type: array
items:
$ref: '#/components/schemas/ExampleWithRuns'
- type: array
items:
$ref: '#/components/schemas/ExampleWithRunsCH'
prompt_tokens:
title: Prompt Tokens
type: integer
nullable: true
completion_tokens:
title: Completion Tokens
type: integer
nullable: true
prompt_cost:
title: Prompt Cost
type: string
nullable: true
completion_cost:
title: Completion Cost
type: string
nullable: true
error_rate:
title: Error Rate
type: number
nullable: true
description: Group of examples with runs.
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Addition of ExampleWithRunsGroup Schema
The newly added ExampleWithRunsGroup schema is comprehensive and covers important properties such as filtering, counts, tokens, cost, and timing information. However, the group_key property is missing a type definition. It is required according to the schema’s required list, so please add its type (for example, "type": "string") to enforce schema consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant