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 new /studio/v1/library/answer endpoint to AI21 Studio API #68

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Nov 12, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new API endpoint for generating answers based on user questions (POST /studio/v1/library/answer).
    • Added support for customizable request parameters and response structures to enhance user interaction.
    • Implemented enumerations for answer length and mode to provide more options for users.

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

This pull request introduces a new endpoint to the AI21 Studio API, specifically the /studio/v1/library/answer endpoint which supports POST requests. This endpoint facilitates answer generation based on user questions, utilizing the RAG Engine. Alongside the new endpoint, it adds several schemas for request and response handling, including LibraryAnswerRequest and LibraryAnswerResponse, as well as enumerations for answer length and mode.

Changes

File Change Summary
src/libs/AI21/openapi.yaml - Added new endpoint: POST /studio/v1/library/answer (operation ID: v1_library_answer)
- Introduced LibraryAnswerRequest schema for request body
- Introduced LibraryAnswerResponse schema for response
- Added enumeration AnswerLength for answer length options
- Added enumeration Mode for specifying the mode of operation

Possibly related PRs

🐇 In the meadow, bright and fair,
A new endpoint's in the air!
With questions asked, and answers sought,
The RAG Engine works, a clever thought.
So hop along, let queries flow,
With LibraryAnswer, watch us grow! 🌼


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 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.

@github-actions github-actions bot enabled auto-merge November 12, 2024 12:41
@github-actions github-actions bot merged commit abdcded into main Nov 12, 2024
3 checks passed
@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Add new /studio/v1/library/answer endpoint to AI21 Studio API Nov 12, 2024
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

🧹 Outside diff range and nitpick comments (3)
src/libs/AI21/openapi.yaml (3)

1188-1219: Add endpoint description and examples.

The new /studio/v1/library/answer endpoint would benefit from:

  • A description field explaining its purpose and use cases
  • Example request/response pairs to guide API consumers
  /studio/v1/library/answer:
    post:
      tags:
        - RAG Engine
      summary: Answer
+     description: |
+       Generates answers to questions using the RAG Engine by searching through documents
+       in your library. The response includes the answer and relevant source documents.
+     externalDocs:
+       description: Learn more about the RAG Engine
+       url: https://docs.ai21.com/docs/rag-engine-overview
+     x-code-samples:
+       - lang: curl
+         source: |
+           curl -X POST https://api.ai21.com/studio/v1/library/answer \
+             -H "Authorization: Bearer YOUR_API_KEY" \
+             -H "Content-Type: application/json" \
+             -d '{
+               "question": "What are the key features?",
+               "maxSegments": 5
+             }'
      operationId: v1_library_answer

2151-2204: Enhance schema documentation and validation.

The LibraryAnswerRequest schema needs additional documentation and validation:

  1. Add descriptions for threshold parameters
  2. Add examples for key fields
  3. Add bounds for maxSegments
     maxSegments:
       title: Maxsegments
       type: integer
+      minimum: 1
+      maximum: 100
+      description: Maximum number of segments to retrieve from the library
+      example: 5
     retrievalSimilarityThreshold:
       title: Retrievalsimilaritythreshold
       maximum: 1.5
       minimum: 0.5
       type: number
+      description: Threshold for semantic similarity matching. Higher values require closer matches.
+      example: 0.8
     hybridSearchAlpha:
       title: Hybridsearchalpha
       maximum: 1.0
       minimum: 0.0
       type: number
+      description: Balance between semantic and keyword search. 1.0 is fully semantic, 0.0 is fully keyword-based.
+      example: 0.98

1422-1428: Add descriptions for enums and source document properties.

The supporting schemas need better documentation to guide API consumers:

   AnswerLength:
     title: AnswerLength
     enum:
       - short
       - medium
       - long
-    description: An enumeration.
+    description: |
+      Controls the length of the generated answer:
+      - short: Concise, to-the-point answers (1-2 sentences)
+      - medium: Balanced answers with some detail (2-4 sentences)
+      - long: Comprehensive answers with full context (4+ sentences)

   Mode:
     title: Mode
     enum:
       - flexible
       - strict
-    description: An enumeration.
+    description: |
+      Controls how strictly the answer adheres to the source documents:
+      - flexible: Allows some inference and combining information
+      - strict: Answers strictly based on explicit content in sources

   SourceDocument:
     title: SourceDocument
     required:
       - fileId
       - name
       - highlights
     type: object
     properties:
       fileId:
         title: Fileid
         type: string
+        description: Unique identifier of the source document
       name:
         title: Name
         type: string
+        description: Original filename of the source document
       highlights:
         title: Highlights
         type: array
         items:
           type: string
+        description: Relevant text segments from the document that support the answer

Also applies to: 2396-2401, 2583-2609

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c9e2c7b and 1161f5d.

⛔ Files ignored due to path filters (16)
  • src/libs/AI21/Generated/AI21.IRAGEngineClient.V1LibraryAnswer.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.AnswerLength.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.LibraryAnswerRequest.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.LibraryAnswerRequestLabelsFilterMode.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.LibraryAnswerResponse.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.Mode.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.SourceDocument.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.RAGEngineClient.V1LibraryAnswer.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.AnswerLength.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.AnswerLengthNullable.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.LibraryAnswerRequestLabelsFilterMode.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.LibraryAnswerRequestLabelsFilterModeNullable.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.Mode.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonConverters.ModeNullable.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonSerializerContext.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/JsonSerializerContextTypes.g.cs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • src/libs/AI21/openapi.yaml (5 hunks)

Comment on lines +2205 to +2226
LibraryAnswerResponse:
title: LibraryAnswerResponse
required:
- id
- answerInContext
type: object
properties:
id:
title: Id
type: string
description: "A unique ID for the request (not the message). Repeated identical requests\nget different IDs. However, for a streaming response, the ID will be the same\nfor all responses in the stream.\n"
answerInContext:
title: Answerincontext
type: boolean
answer:
title: Answer
type: string
sources:
title: Sources
type: array
items:
$ref: '#/components/schemas/SourceDocument'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve response schema consistency and documentation.

The LibraryAnswerResponse schema has potential logical inconsistencies:

  1. The answer field should be required when answerInContext is true
  2. The sources array lacks documentation
     answerInContext:
       title: Answerincontext
       type: boolean
+      description: Indicates whether an answer was found in the context
     answer:
       title: Answer
       type: string
+      description: The generated answer. Always present when answerInContext is true.
     sources:
       title: Sources
       type: array
+      description: List of source documents that contributed to the answer
       items:
         $ref: '#/components/schemas/SourceDocument'

Consider adding a schema validation rule to ensure answer is present when answerInContext is true.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LibraryAnswerResponse:
title: LibraryAnswerResponse
required:
- id
- answerInContext
type: object
properties:
id:
title: Id
type: string
description: "A unique ID for the request (not the message). Repeated identical requests\nget different IDs. However, for a streaming response, the ID will be the same\nfor all responses in the stream.\n"
answerInContext:
title: Answerincontext
type: boolean
answer:
title: Answer
type: string
sources:
title: Sources
type: array
items:
$ref: '#/components/schemas/SourceDocument'
LibraryAnswerResponse:
title: LibraryAnswerResponse
required:
- id
- answerInContext
type: object
properties:
id:
title: Id
type: string
description: "A unique ID for the request (not the message). Repeated identical requests\nget different IDs. However, for a streaming response, the ID will be the same\nfor all responses in the stream.\n"
answerInContext:
title: Answerincontext
type: boolean
description: Indicates whether an answer was found in the context
answer:
title: Answer
type: string
description: The generated answer. Always present when answerInContext is true.
sources:
title: Sources
type: array
description: List of source documents that contributed to the answer
items:
$ref: '#/components/schemas/SourceDocument'

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