Skip to content

Commit

Permalink
feat: add expert references api + new attributes for boards of experts
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Dec 8, 2023
1 parent ac81102 commit c09c317
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import unansweredQuestions from './engine/unansweredQuestions';
import contextVars from './engine/contextVars';
import customDictionary from './engine/customDictionary';
import chatLogs from './engine/chatLogs';
import expertReferences from './engine/expertReferences';

export default (apiUrl: string) => ({
correlationPairs: correlationPairs(apiUrl),
Expand Down Expand Up @@ -48,4 +49,6 @@ export default (apiUrl: string) => ({
...customDictionary(apiUrl),
chatLogs: chatLogs(apiUrl),
...chatLogs(apiUrl),
expertReferences: expertReferences(apiUrl),
...expertReferences(apiUrl),
});
19 changes: 19 additions & 0 deletions src/engine/expertReferences.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import memori from '../index';

const client = memori('https://backend.memori.ai');

describe('engine/expertReferences api', () => {
it('works on expertReferences apis', async () => {
expect(
await client.expertReferences.getExpertReferences(
'768b9654-e781-4c3c-81fa-ae1529d1bfbe'
)
).not.toBeNull();
});

it('works on chatLogs apis with shorthand version', async () => {
expect(
await client.getExpertReferences('768b9654-e781-4c3c-81fa-ae1529d1bfbe')
).not.toBeNull();
});
});
120 changes: 120 additions & 0 deletions src/engine/expertReferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import type { ResponseSpec, ExpertReference } from '../types';
import { apiFetcher } from '../apiFetcher';

/************************
* *
* Expert References *
* *
************************/

export default (apiUrl: string) => ({
/**
* Lists all Expert Reference objects.
* @param {string} sessionId The session ID
*/
getExpertReferences: async (sessionId: string) =>
apiFetcher(`/ExpertReferences/${sessionId}`, {
method: 'GET',
apiUrl,
}) as Promise<
ResponseSpec & {
/**
* Total number of Expert Reference objects.
*/
count: number;
/**
* List of Expert Reference objects. May be empty.
*/
experts: ExpertReference[];
}
>,

/**
* Lists Expert Reference objects with pagination.
* @param {string} sessionId The session ID
* @param {number} from The 0-based index of the first Expert Reference object to list
* @param {number} howMany The number of the Expert Reference objects to list
*/
getExpertReferencesPaginated: async (
sessionId: string,
from: number,
howMany: number
) =>
apiFetcher(`/ExpertReferences/${sessionId}/${from}/${howMany}`, {
method: 'GET',
apiUrl,
}) as Promise<
ResponseSpec & {
/**
* Total number of Expert Reference objects.
*/
count: number;
/**
* List of Expert Reference objects. May be empty.
*/
experts: ExpertReference[];
}
>,

/**
* Gets the details of an Expert Reference object.
* @param {string} sessionId The session ID
* @param {string} expertID The Expert Reference object ID
*/
getExpertReference: async (sessionId: string, expertID: string) =>
apiFetcher(`/ExpertReference/${sessionId}/${expertID}`, {
method: 'GET',
apiUrl,
}) as Promise<
ResponseSpec & {
expert: ExpertReference;
}
>,

/**
* Updates an existing Expert Reference object.
* @param {string} sessionId The session ID
* @param {ExpertReference} expertReference The Expert Reference object
*/
updateExpertReference: async (
sessionId: string,
expertReference: Partial<ExpertReference> & {
expertID: ExpertReference['expertID'];
}
) =>
apiFetcher(`/ExpertReference/${sessionId}/${expertReference.expertID}`, {
method: 'PATCH',
apiUrl,
body: expertReference,
}) as Promise<ResponseSpec>,

/**
* Adds a new Expert Reference object.
* @param {string} sessionId The session ID
* @param {ExpertReference} expertReference The Expert Reference object
*/
createExpertReference: async (
sessionId: string,
expertReference: Omit<Partial<ExpertReference>, 'expertID'>
) =>
apiFetcher(`/ExpertReference/${sessionId}`, {
method: 'POST',
apiUrl,
body: expertReference,
}) as Promise<
ResponseSpec & {
expertID: ExpertReference['expertID'];
}
>,

/**
* Removes an existing Expert Reference object.
* @param {string} sessionId The session ID
* @param {string} expertID The Expert Reference object ID
*/
deleteExpertReference: async (sessionId: string, expertID: string) =>
apiFetcher(`/ExpertReference/${sessionId}/${expertID}`, {
method: 'DELETE',
apiUrl,
}) as Promise<ResponseSpec>,
});
8 changes: 4 additions & 4 deletions src/engine/memories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default (apiUrl: string) => ({
/**
* Lists all Memory objects.
* @param {string} sessionId The session ID
* @param {string=} type Optional type of the Memory objects to list: ALL, CONTENTS, DEFAULTS, DRAFTS
* @param {string=} type Optional type of the Memory objects to list: ALL, CONTENTS, DEFAULTS, DRAFTS, EXPERT_REFERENCES
*/
getMemories: async (
sessionId: string,
type?: 'ALL' | 'CONTENTS' | 'DEFAULTS' | 'DRAFTS'
type?: 'ALL' | 'CONTENTS' | 'DEFAULTS' | 'DRAFTS' | 'EXPERT_REFERENCES'
) =>
apiFetcher(`/Memories/${sessionId}${type ? `/${type}` : ''}`, {
method: 'GET',
Expand All @@ -31,13 +31,13 @@ export default (apiUrl: string) => ({
* @param {string} sessionId The session ID
* @param {number} from The starting index
* @param {number} howMany The number of items to return
* @param {string=} type Optional type of the Memory objects to list: ALL, CONTENTS, DEFAULTS, DRAFTS
* @param {string=} type Optional type of the Memory objects to list: ALL, CONTENTS, DEFAULTS, DRAFTS, EXPERT_REFERENCES
*/
getMemoriesPaginated: async (
sessionId: string,
from: number,
howMany: number,
type?: 'ALL' | 'CONTENTS' | 'DEFAULTS' | 'DRAFTS'
type?: 'ALL' | 'CONTENTS' | 'DEFAULTS' | 'DRAFTS' | 'EXPERT_REFERENCES'
) =>
apiFetcher(
`/Memories/${sessionId}/${from}/${howMany}${type ? `/${type}` : ''}`,
Expand Down
52 changes: 51 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export declare type DialogState = {
confidence?: number;
confidenceLevel?: 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH';
emission?: string;
emitter?: string;
completion?: boolean;
continuationEmitted?: boolean;
lastMatchedMemoryID?: string;
Expand Down Expand Up @@ -520,7 +521,12 @@ export declare type Answer = {

export declare type Memory = {
memoryID: string;
memoryType: string;
memoryType:
| 'Question'
| 'Story'
| 'Default'
| 'CompletionDraft'
| 'ExpertReference';
lastRead?: string;
readOccurrences?: number;
receiverID?: string;
Expand Down Expand Up @@ -584,6 +590,7 @@ export declare type Message = {
fromUser?: boolean;
media?: Medium[];
initial?: boolean;
emitter?: string;
timestamp?: string;
contextVars?: { [key: string]: string };
};
Expand Down Expand Up @@ -1075,3 +1082,46 @@ export interface Badge {
issuerEmail?: string;
issuerURL?: string;
}

export interface ExpertReference {
/**
* @type {string}
* Expert Reference object ID. Returned during Get operations. Ignored in other cases.
*/
expertID: string;
/**
* @type {string}
* Name of the expert. Returned during Get operations. Required during Add operations. Optional during Update operations.
*/
name: string;
/**
* @type {string}
* Description of the expert, i.e. a list of the expert's skills and knowledge. Returned during Get operations. Required during Add operations. Optional during Update operations.
*/
description: string;
/**
* @type {boolean}
* If True, this expert is used when no other expert is competent for the current question. Returned during Get operations. Optional during Add operations. Optional during Update operations.
*/
default?: boolean;
/**
* @type {string}
* ID of the expert Memori. Returned during Get operations. Required during Add operations. Optional during Update operations.
* NOTE: engine memroi ID
*/
expertMemoriID: string;
/**
* @type {string=}
* Password of the expert Memori. Required if the chained Memori is private or secret. Optional during Add operations and Update operations. Ignore in other cases.
*/
expertPassword?: string;
/**
* @type {string}
* Base URL of a chained Memori, typically https://engine.memori.ai/. Returned during Get operations. Required during Add operations. Optional during Update operations.
*/
expertBaseURL: string;
creationTimestamp?: string;
creationSessionID?: string;
lastChangeTimestamp?: string;
lastChangeSessionID?: string;
}

0 comments on commit c09c317

Please sign in to comment.