@or-sdk/qna
Advanced tools
Comparing version 3.0.0 to 3.1.0-beta.1534.0
@@ -219,12 +219,10 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var description, response; | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
description = params.description; | ||
return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId, "/documents/").concat(documentId), | ||
data: { description: description }, | ||
})]; | ||
case 0: return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId, "/documents/").concat(documentId), | ||
data: params, | ||
})]; | ||
case 1: | ||
@@ -239,14 +237,10 @@ response = _a.sent(); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var content, response; | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
content = params.content; | ||
return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId, "/passages/").concat(passageId), | ||
data: { | ||
content: content, | ||
}, | ||
})]; | ||
case 0: return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId, "/passages/").concat(passageId), | ||
data: params, | ||
})]; | ||
case 1: | ||
@@ -261,12 +255,10 @@ response = _a.sent(); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var description, response; | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
description = params.description; | ||
return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId), | ||
data: { description: description }, | ||
})]; | ||
case 0: return [4, this.callApiV2({ | ||
method: 'PUT', | ||
route: "collections/".concat(collectionId), | ||
data: params, | ||
})]; | ||
case 1: | ||
@@ -273,0 +265,0 @@ response = _a.sent(); |
@@ -115,7 +115,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { description } = params; | ||
const response = yield this.callApiV2({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}/documents/${documentId}`, | ||
data: { description }, | ||
data: params, | ||
}); | ||
@@ -127,9 +126,6 @@ return response; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { content } = params; | ||
const response = yield this.callApiV2({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}/passages/${passageId}`, | ||
data: { | ||
content, | ||
}, | ||
data: params, | ||
}); | ||
@@ -141,7 +137,6 @@ return response; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { description } = params; | ||
const response = yield this.callApiV2({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}`, | ||
data: { description }, | ||
data: params, | ||
}); | ||
@@ -148,0 +143,0 @@ return response; |
@@ -7,4 +7,4 @@ import { Base, List } from '@or-sdk/base'; | ||
createCollection(params: CreateCollection): Promise<Collection>; | ||
createPassage(collectionId: string, passage: CreatePassage): Promise<Passage>; | ||
createManyPassages(collectionId: string, passages: CreatePassage[]): Promise<void>; | ||
createPassage<T extends Record<string, unknown>>(collectionId: string, passage: CreatePassage<T>): Promise<Passage<T>>; | ||
createManyPassages<T extends Record<string, unknown>>(collectionId: string, passages: CreatePassage<T>[]): Promise<void>; | ||
deleteCollection(collectionId: string): Promise<Collection>; | ||
@@ -15,14 +15,14 @@ deletePassage(collectionId: string, passageId: string): Promise<DeletedPassage>; | ||
updateDocument(collectionId: string, documentId: string, params: UpdateDocument): Promise<Document>; | ||
updatePassage(collectionId: string, passageId: string, params: UpdatePassage): Promise<Passage>; | ||
updatePassage<T extends Record<string, unknown>>(collectionId: string, passageId: string, params: UpdatePassage<T>): Promise<Passage<T>>; | ||
updateCollection(collectionId: string, params: UpdateCollection): Promise<Collection>; | ||
getDocument(collectionId: string, documentId: string): Promise<Document>; | ||
getCollection(collectionId: string): Promise<Collection>; | ||
getPassage<T extends Record<string, unknown>>(collectionId: string, passageId: string): Promise<Passage & T>; | ||
getPassage<T extends Record<string, unknown>>(collectionId: string, passageId: string): Promise<Passage<T>>; | ||
addProperty(collectionId: string, property: Property): Promise<void>; | ||
listDocuments(collectionId: string, params?: Find): Promise<List<Document>>; | ||
listCollections(params?: Find): Promise<List<Collection>>; | ||
listPassages(collectionId: string, params?: Find): Promise<List<Passage>>; | ||
listPassagesInDocument(collectionId: string, documentId: string, find?: Find): Promise<List<Passage>>; | ||
listPassages<T extends Record<string, unknown>>(collectionId: string, params?: Find): Promise<List<Passage<T>>>; | ||
listPassagesInDocument<T extends Record<string, unknown>>(collectionId: string, documentId: string, find?: Find): Promise<List<Passage<T>>>; | ||
deleteDocument(collectionId: string, documentId: string): Promise<Document>; | ||
} | ||
//# sourceMappingURL=QnA.d.ts.map |
@@ -31,2 +31,3 @@ import { OrderOptions, PaginationOptions, Token } from '@or-sdk/base'; | ||
export type MessageRole = 'user' | 'assistant'; | ||
export type AskMode = 'conversation' | 'ask'; | ||
export type CompletionRequestMessage = { | ||
@@ -42,2 +43,10 @@ role: MessageRole; | ||
select?: string[]; | ||
mode?: AskMode; | ||
answerInstruction?: string; | ||
questionInstruction?: string; | ||
temperature?: number; | ||
maxTokens?: number; | ||
frequencyPenalty?: number; | ||
presencePenalty?: number; | ||
maxDistance?: number; | ||
}; | ||
@@ -97,8 +106,8 @@ export declare enum DocumentStatus { | ||
}; | ||
export type CreatePassage = { | ||
export type CreatePassage<T extends Record<string, unknown>> = { | ||
content: string; | ||
documentId: string; | ||
loaderMetadata?: Record<string, unknown>; | ||
} | Record<string, unknown>; | ||
export type Passage = { | ||
} & T; | ||
export type Passage<T extends Record<string, unknown>> = { | ||
id: string; | ||
@@ -108,6 +117,6 @@ content: string; | ||
updatedAt: string; | ||
}; | ||
export type UpdatePassage = { | ||
} & T; | ||
export type UpdatePassage<T extends Record<string, unknown>> = { | ||
content: string; | ||
}; | ||
} & T; | ||
export type DeletedPassage = { | ||
@@ -114,0 +123,0 @@ id: string; |
{ | ||
"name": "@or-sdk/qna", | ||
"version": "3.0.0", | ||
"version": "3.1.0-beta.1534.0", | ||
"main": "dist/cjs/index.js", | ||
@@ -30,4 +30,3 @@ "module": "dist/esm/index.js", | ||
"access": "public" | ||
}, | ||
"gitHead": "4fc69064846aca159c187b7e5ec9f32c8b3d7d63" | ||
} | ||
} |
@@ -355,15 +355,34 @@ # QnA SDK | ||
Asks a question and generates an answer based on the documents in a collection. This method accepts several parameters that can be used to filter, sort, and limit the results. | ||
Asks a question and generates an answer based on the documents in a collection. This method accepts a set of parameters to configure the question-answering process and to fine-tune the generated outputs. | ||
The `ask` method supports two modes: 'ask' and 'conversation'. Here are the details of each mode: | ||
1. 'ask' mode: | ||
This mode allows you to ask a direct, standalone question. In this mode, the processing of the question and the generation of the answer are not influenced by any prior context or conversation history. | ||
This mode is suitable for scenarios where a single question is to be answered independently, such as a search query or a factual question. | ||
2. 'conversation' mode: | ||
This mode allows you to ask questions in the context of a conversation. This means that prior messages from the conversation will be taken into account while processing the question and generating the answer. | ||
This mode is suitable for scenarios where a dialogue is happening, and the generation of an answer is dependent on the previous exchanges in the conversation. In this mode, you can supply previous conversation messages in the `messages` parameter, which accepts an array of message objects, each with a sender role ('assistant' or 'user') and the content of the message. | ||
Both modes use a language model to generate an answer given a question and a collection of documents. How the prior messages are used to influence the retrieval of information and the generation of responses differs based on the mode used. | ||
#### Params | ||
- question: `string` - The question to ask | ||
- messages: `CompletionRequestMessage[]` (optional) - An array of previous chat messages with roles 'user' and 'assistant' | ||
- limit: `number` (optional) - Limit the number of search results | ||
- messages: `CompletionRequestMessage[]` (optional) - An array of previous chat messages with roles 'user' and 'assistant'. Default is an empty array | ||
- limit: `number` (optional) - Limit the number of search results. Default is 5. Accepts values between 1 and 100 | ||
- where: `Record<string, unknown>` (optional) - Weaviate filter object for advanced filtering. For more details, visit https://weaviate.io/developers/weaviate/api/graphql/filters | ||
- select: `string[]` (optional) - An array of custom properties to include in the results | ||
- mode: `AskMode` (optional) - Question mode, can be either 'ask' or 'conversation'. Default is 'conversation' | ||
- temperature: `number` (optional) - Adjusts the randomness in the model's output. Default is 1. Accepts values between 0 and 2 | ||
- maxTokens: `number` (optional) - Maximum output length from the language model. Default is 1024. Accepts values between 128 and 2048 | ||
- frequencyPenalty: `number` (optional) - Penalizes new tokens based on their existing frequency in the text so far. Default is 0. Range accepted is -2 to 2 | ||
- presencePenalty: `number` (optional) - Penalizes new tokens based on whether they appear in the text so far. Default is 0. Range accepted is -2 to 2 | ||
- maxDistance: `number` (optional) - Filters out passages that are further than this value from the question or context. Measured by cosine metric. Default is 0. Range accepted is 0 to 1 | ||
#### Example | ||
The example below demonstrates a query with filtering and property selection options provided. The `where` parameter is used to filter the results based on the `publishDate` property, and the `select` parameter is used to include the `author` and `publishDate` properties of the selected passages in the response. | ||
```typescript | ||
@@ -394,3 +413,8 @@ const collectionId = 'a1b2c3d4-uuid'; | ||
}, | ||
select: ['author', 'publishDate'], | ||
mode: 'conversation', | ||
temperature: 0.8, | ||
maxTokens: 1500, | ||
frequencyPenalty: 0.5, | ||
presencePenalty: 0.5, | ||
maxDistance: 0.9, | ||
}); | ||
@@ -401,9 +425,12 @@ | ||
result: { role: 'assistant', content: 'The meaning of life is 42.' }, | ||
searchResult: { | ||
id: 'e5f6g7h8-uuid', | ||
distance: '0.1234', | ||
content: 'Found passage content', | ||
author: 'John Doe', | ||
publishDate: '2020-12-31', | ||
}, | ||
searchResult: [ | ||
{ | ||
id: 'e5f6g7h8-uuid', | ||
distance: '0.1234', | ||
content: 'Found passage content', | ||
author: 'John Doe', | ||
publishDate: '2020-12-31', | ||
}, | ||
// ... More results if available | ||
], | ||
} | ||
@@ -410,0 +437,0 @@ ``` |
@@ -58,4 +58,7 @@ import { Base, List, makeList } from '@or-sdk/base'; | ||
*/ | ||
async createPassage(collectionId: string, passage: CreatePassage): Promise<Passage> { | ||
const response = await this.callApiV2<Passage>({ | ||
async createPassage<T extends Record<string, unknown>>( | ||
collectionId: string, | ||
passage: CreatePassage<T>, | ||
): Promise<Passage<T>> { | ||
const response = await this.callApiV2<Passage<T>>({ | ||
method: 'POST', | ||
@@ -74,3 +77,6 @@ route: `collections/${collectionId}/passages`, | ||
*/ | ||
async createManyPassages(collectionId: string, passages: CreatePassage[]): Promise<void> { | ||
async createManyPassages<T extends Record<string, unknown>>( | ||
collectionId: string, | ||
passages: CreatePassage<T>[], | ||
): Promise<void> { | ||
await this.callApiV2({ | ||
@@ -166,7 +172,6 @@ method: 'POST', | ||
async updateDocument(collectionId: string, documentId: string, params: UpdateDocument): Promise<Document> { | ||
const { description } = params; | ||
const response = await this.callApiV2<Document>({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}/documents/${documentId}`, | ||
data: { description }, | ||
data: params, | ||
}); | ||
@@ -183,10 +188,11 @@ return response; | ||
*/ | ||
async updatePassage(collectionId: string, passageId: string, params: UpdatePassage): Promise<Passage> { | ||
const { content } = params; | ||
const response = await this.callApiV2<Passage>({ | ||
async updatePassage<T extends Record<string, unknown>>( | ||
collectionId: string, | ||
passageId: string, | ||
params: UpdatePassage<T>, | ||
): Promise<Passage<T>> { | ||
const response = await this.callApiV2<Passage<T>>({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}/passages/${passageId}`, | ||
data: { | ||
content, | ||
}, | ||
data: params, | ||
}); | ||
@@ -205,7 +211,6 @@ | ||
async updateCollection(collectionId: string, params: UpdateCollection): Promise<Collection> { | ||
const { description } = params; | ||
const response = await this.callApiV2<Collection>({ | ||
method: 'PUT', | ||
route: `collections/${collectionId}`, | ||
data: { description }, | ||
data: params, | ||
}); | ||
@@ -248,4 +253,4 @@ return response; | ||
*/ | ||
async getPassage<T extends Record<string, unknown>>(collectionId: string, passageId: string): Promise<Passage & T> { | ||
const response = await this.callApiV2<Passage & T>({ | ||
async getPassage<T extends Record<string, unknown>>(collectionId: string, passageId: string): Promise<Passage<T>> { | ||
const response = await this.callApiV2<Passage<T>>({ | ||
method: 'GET', | ||
@@ -318,7 +323,7 @@ route: `collections/${collectionId}/passages/${passageId}`, | ||
*/ | ||
async listPassages( | ||
async listPassages<T extends Record<string, unknown>>( | ||
collectionId: string, | ||
params: Find = {}, | ||
): Promise<List<Passage>> { | ||
const response = await this.callApiV2<Passage[]>({ | ||
): Promise<List<Passage<T>>> { | ||
const response = await this.callApiV2<Passage<T>[]>({ | ||
method: 'GET', | ||
@@ -339,8 +344,8 @@ route: `collections/${collectionId}/passages`, | ||
*/ | ||
async listPassagesInDocument( | ||
async listPassagesInDocument<T extends Record<string, unknown>>( | ||
collectionId: string, | ||
documentId: string, | ||
find: Find = {}, | ||
): Promise<List<Passage>> { | ||
const response = await this.callApiV2<Passage[]>({ | ||
): Promise<List<Passage<T>>> { | ||
const response = await this.callApiV2<Passage<T>[]>({ | ||
method: 'GET', | ||
@@ -347,0 +352,0 @@ route: `collections/${collectionId}/documents/${documentId}/passages`, |
@@ -114,2 +114,3 @@ import { OrderOptions, PaginationOptions, Token } from '@or-sdk/base'; | ||
export type MessageRole = 'user' | 'assistant'; | ||
export type AskMode = 'conversation' | 'ask'; | ||
@@ -142,2 +143,3 @@ /** | ||
* Previous chat messages | ||
* Default: [] | ||
*/ | ||
@@ -148,2 +150,4 @@ messages?: CompletionRequestMessage[]; | ||
* Limit the number of results. | ||
* Default: 5 | ||
* Range: 1 - 100 | ||
*/ | ||
@@ -154,2 +158,3 @@ limit?: number; | ||
* Weaviate where filter. See https://weaviate.io/developers/weaviate/api/graphql/filters | ||
* Optional | ||
*/ | ||
@@ -160,4 +165,61 @@ where?: Record<string, unknown>; | ||
* Array of the custom properties to select. | ||
* Optional | ||
*/ | ||
select?: string[]; | ||
/** | ||
* Question mode. | ||
* Default: 'conversation' | ||
* Values: 'conversation', 'ask' | ||
*/ | ||
mode?: AskMode; | ||
/** | ||
* A summarization instruction used to generate correct answer. | ||
* Maximum Length: 1000 characters | ||
* Optional | ||
*/ | ||
answerInstruction?: string; | ||
/** | ||
* A summarization instruction used to generate correct search term. | ||
* Maximum Length: 1000 characters | ||
* Optional | ||
*/ | ||
questionInstruction?: string; | ||
/** | ||
* What sampling temperature to use. | ||
* Default: 1 | ||
* Range: 0 - 2 | ||
*/ | ||
temperature?: number; | ||
/** | ||
* Maximum output length from the LLM | ||
* Default: 1024 | ||
* Range: 128 - 2048 | ||
*/ | ||
maxTokens?: number; | ||
/** | ||
* Positive values penalize new tokens based on their existing frequency in the text so far. | ||
* Default: 0 | ||
* Range: -2 - 2 | ||
*/ | ||
frequencyPenalty?: number; | ||
/** | ||
* Penalize new tokens based on whether they appear in the text so far. | ||
* Default: 0 | ||
* Range: -2 - 2 | ||
*/ | ||
presencePenalty?: number; | ||
/** | ||
* Filter out passages that are further than maxDistance from the question or context by cosine metric. | ||
* Default: 0 | ||
* Range: 0 - 1 | ||
*/ | ||
maxDistance?: number; | ||
}; | ||
@@ -392,3 +454,3 @@ | ||
*/ | ||
export type CreatePassage = { | ||
export type CreatePassage<T extends Record<string, unknown>> = { | ||
/** | ||
@@ -408,3 +470,3 @@ * Content of the passage | ||
loaderMetadata?: Record<string, unknown>; | ||
} | Record<string, unknown>; | ||
} & T; | ||
@@ -414,3 +476,3 @@ /** | ||
*/ | ||
export type Passage = { | ||
export type Passage<T extends Record<string, unknown>> = { | ||
/** | ||
@@ -435,3 +497,3 @@ * Passage ID | ||
updatedAt: string; | ||
}; | ||
} & T; | ||
@@ -442,3 +504,3 @@ | ||
*/ | ||
export type UpdatePassage = { | ||
export type UpdatePassage<T extends Record<string, unknown>> = { | ||
/** | ||
@@ -448,3 +510,3 @@ * Updated content of the passage | ||
content: string; | ||
}; | ||
} & T; | ||
@@ -451,0 +513,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
111328
1646
919
2