-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
WalkthroughThis pull request introduces a new endpoint to the AI21 Studio API, specifically the Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
/studio/v1/library/answer
endpoint to AI21 Studio API
There was a problem hiding this 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:
- Add descriptions for threshold parameters
- Add examples for key fields
- 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 answerAlso applies to: 2396-2401, 2583-2609
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ 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)
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' |
There was a problem hiding this comment.
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:
- The
answer
field should be required whenanswerInContext
is true - 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.
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' |
Summary by CodeRabbit
POST /studio/v1/library/answer
).