From b0a2de336665cee8b28aa60055212a6c381ee4ed Mon Sep 17 00:00:00 2001 From: Ajeya Bhat Date: Tue, 29 Aug 2023 13:16:03 +0530 Subject: [PATCH 1/2] update: added return types for all the functions --- src/comet.ts | 47 ++++++++---------- src/types.ts | 138 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 127 insertions(+), 58 deletions(-) diff --git a/src/comet.ts b/src/comet.ts index 947c270..1da59be 100644 --- a/src/comet.ts +++ b/src/comet.ts @@ -1,16 +1,13 @@ import axios, { type AxiosInstance } from 'axios'; -import { API_V1_URL, PROMPT_STREAM_RESPONSE_PREFIX } from './constants'; -import { - type UpdateConfigPayload, - type PromptPayload, - type SetGenerationModelPayload, - type ListConversationsPayload, - type GetConversationPayload, - type GetMessagePayload, - type ProvideMessageFeedbackPayload, - type IComet, +import { API_V1_URL } from './constants'; +import type { + UpdateConfigPayload, + PromptPayload, + SetGenerationModelPayload, + ProvideMessageFeedbackPayload, + IComet, ListSessionsPayload, - GetSessionPayload, + ICometSession, } from './types'; import { streamPromptWithAxios, streamPromptWithNativeFetch } from 'helpers'; @@ -32,8 +29,8 @@ export class Comet implements IComet { }); } - async getCometInfo(): Promise { - const { data } = await this.cometAPI.get('/'); + async getCometInfo() { + const { data } = await this.cometAPI.get('/'); return data; } @@ -57,24 +54,20 @@ export class Comet implements IComet { await this.cometAPI.post(`/model`, payload); } - async listSessions(payload: ListSessionsPayload = {}): Promise { - const { data } = await this.cometAPI.get(`/sessions`, { + async listSessions(payload: ListSessionsPayload = {}) { + const { data } = await this.cometAPI.get(`/sessions`, { params: payload, }); return data; } - async getSession({ sessionId }: GetSessionPayload): Promise { - const { data } = await this.cometAPI.get(`/sessions/${sessionId}`); + async getSession({ sessionId }) { + const { data } = await this.cometAPI.get(`/sessions/${sessionId}`); return data; } - async listConversations({ - sessionId, - stats, - messages, - }: ListConversationsPayload): Promise { - const { data } = await this.cometAPI.get(`/sessions/${sessionId}/conversations`, { + async listConversations({ sessionId, stats, messages }) { + const { data } = await this.cometAPI.get(`/sessions/${sessionId}/conversations`, { params: { s: stats, m: messages, @@ -83,13 +76,13 @@ export class Comet implements IComet { return data; } - async getConversation({ conversationId }: GetConversationPayload): Promise { - const { data } = await this.cometAPI.get(`/conversations/${conversationId}`); + async getConversation({ conversationId }) { + const { data } = await this.cometAPI.get(`/conversations/${conversationId}`); return data; } - async getMessage({ messageId }: GetMessagePayload): Promise { - const { data } = await this.cometAPI.get(`/messages/${messageId}`); + async getMessage({ messageId }) { + const { data } = await this.cometAPI.get(`/messages/${messageId}`); return data; } diff --git a/src/types.ts b/src/types.ts index fc37d3d..8ede9c1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,18 +21,33 @@ export interface Memory { // Comet Client export interface IComet { - // index: (payload: IndexInput) => Promise prompt: ( payload: PromptPayload, handleNewText?: (data: string) => void | Promise ) => Promise; updateConfig: (payload: UpdateConfigPayload) => Promise; setGenerationModel: (payload: SetGenerationModelPayload) => Promise; - listConversations: (payload: ListConversationsPayload) => Promise; - getConversation: (payload: GetConversationPayload) => Promise; - getMessage: (payload: GetMessagePayload) => Promise; + getMessage: (payload: GetMessagePayload) => Promise; takeConversationFeedback: (payload: ProvideMessageFeedbackPayload) => Promise; deleteComet: () => Promise; + getCometInfo: () => Promise; + listSessions: (payload: ListSessionsPayload) => Promise; + getSession: (payload: GetSessionPayload) => Promise; + listConversations: ( + payload: ListConversationsPayload + ) => Promise< + Array< + ICometConversation & { + messages: M extends true ? ICometMessage[] : never; + stats: S extends true ? ICometConversationStats | null : never; + } + > + >; + getConversation: ( + payload: GetConversationPayload + ) => Promise< + ICometConversation & { messages: ICometMessage[]; stats: ICometConversationStats | null } + >; } export interface IndexInput { @@ -131,51 +146,112 @@ export interface SetGenerationModelPayload { vendor: 'openai'; } - export interface SearchPayload { - index: string - imageBase64?: string - imageUrl?: string - text?: string - embedding?: number[] - filters?: Filters + index: string; + imageBase64?: string; + imageUrl?: string; + text?: string; + embedding?: number[]; + filters?: Filters; } export interface TuningInput { - indexId?: string - idA: string - idB: string - label: -1 | 0 | 1 + indexId?: string; + idA: string; + idB: string; + label: -1 | 0 | 1; } export interface TuningPayload { - index: string - idA: string - idB: string - label: -1 | 0 | 1 + index: string; + idA: string; + idB: string; + label: -1 | 0 | 1; } export interface CreateResourcePayload { - indexId: string - fileName: string - fileType: string - fileSize: number + indexId: string; + fileName: string; + fileType: string; + fileSize: number; } export interface UploadFileToUrlPayload { - url: string - file: File | Buffer - fileType: string - fileSize: number + url: string; + file: File | Buffer; + fileType: string; + fileSize: number; } -export type UploadFilePayload = File | string +export type UploadFilePayload = File | string; export interface FilePayload { - fileName: string - fileType: string + fileName: string; + fileType: string; } export interface CreateFileResouceResponse { - url: string + url: string; +} + +export type CometAIModelType = 'text' | 'chat'; +export interface ICometInfo { + projectId: string; + id: string; + createdAt: string; + updatedAt: string; + creatorId: string; + thirdPartyKeyId: string | null; + confluxId: string | null; + name: string; + configs: Record | null; + whitelistedDomains: string[]; + promptVariables: Record; + promptTemplate: string | null; + promptTokenLimit: number | null; + sectionsMatchThreshold: number | null; + sectionMatchCount: number | null; + contextTokenCutoff: number | null; + model: string; + modelVendor: string; + modelType: CometAIModelType; + conversationHistoryCutoff?: string; +} + +export interface ICometSession { + id: string; + channel: string; + metadata: Record; + userId: string; + visitorId: string | null; + createdAt: string; + updatedAt: string; +} + +export interface ICometConversationStats { + id: string; + feedback: string | null; + noResponse: boolean; + upvoted: boolean; + updatedAt: string; + downvoted: boolean; + processed: boolean; } + +export interface ICometConversation { + id: string; + metadata: Record | null; + createdAt: string; + updatedAt: string; +} + +export type CometMessageAuthor = 'agent' | 'human' | 'system' | 'function'; + +export interface ICometMessage { + id: string; + text: string; + from: CometMessageAuthor; + meta: Record | null; + conversationId: string; + createdAt: string; +} \ No newline at end of file From d41f809bbbc42ea2bb2dd9a684ece64e7a990c60 Mon Sep 17 00:00:00 2001 From: Ajeya Bhat Date: Tue, 29 Aug 2023 13:17:13 +0530 Subject: [PATCH 2/2] changeset added. --- .changeset/brown-dogs-sing.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brown-dogs-sing.md diff --git a/.changeset/brown-dogs-sing.md b/.changeset/brown-dogs-sing.md new file mode 100644 index 0000000..db0cd8c --- /dev/null +++ b/.changeset/brown-dogs-sing.md @@ -0,0 +1,5 @@ +--- +'outpostkit': patch +--- + +added types for comet, conversation, session, message and conversation stats.