Skip to content

Commit

Permalink
Merge pull request #17 from OutpostHQ/feat/types
Browse files Browse the repository at this point in the history
Feat/types
  • Loading branch information
aj-ya authored Aug 29, 2023
2 parents 1f4cbc0 + d41f809 commit a864ad2
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-dogs-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'outpostkit': patch
---

added types for comet, conversation, session, message and conversation stats.
47 changes: 20 additions & 27 deletions src/comet.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -32,8 +29,8 @@ export class Comet implements IComet {
});
}

async getCometInfo(): Promise<object> {
const { data } = await this.cometAPI.get<object>('/');
async getCometInfo() {
const { data } = await this.cometAPI.get('/');
return data;
}

Expand All @@ -57,24 +54,20 @@ export class Comet implements IComet {
await this.cometAPI.post(`/model`, payload);
}

async listSessions(payload: ListSessionsPayload = {}): Promise<object> {
const { data } = await this.cometAPI.get<object>(`/sessions`, {
async listSessions(payload: ListSessionsPayload = {}) {
const { data } = await this.cometAPI.get(`/sessions`, {
params: payload,
});
return data;
}

async getSession({ sessionId }: GetSessionPayload): Promise<object> {
const { data } = await this.cometAPI.get<object>(`/sessions/${sessionId}`);
async getSession({ sessionId }) {
const { data } = await this.cometAPI.get<ICometSession>(`/sessions/${sessionId}`);
return data;
}

async listConversations({
sessionId,
stats,
messages,
}: ListConversationsPayload): Promise<object> {
const { data } = await this.cometAPI.get<object>(`/sessions/${sessionId}/conversations`, {
async listConversations({ sessionId, stats, messages }) {
const { data } = await this.cometAPI.get(`/sessions/${sessionId}/conversations`, {
params: {
s: stats,
m: messages,
Expand All @@ -83,13 +76,13 @@ export class Comet implements IComet {
return data;
}

async getConversation({ conversationId }: GetConversationPayload): Promise<object> {
const { data } = await this.cometAPI.get<object>(`/conversations/${conversationId}`);
async getConversation({ conversationId }) {
const { data } = await this.cometAPI.get(`/conversations/${conversationId}`);
return data;
}

async getMessage({ messageId }: GetMessagePayload): Promise<object> {
const { data } = await this.cometAPI.get<object>(`/messages/${messageId}`);
async getMessage({ messageId }) {
const { data } = await this.cometAPI.get(`/messages/${messageId}`);
return data;
}

Expand Down
138 changes: 107 additions & 31 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,33 @@ export interface Memory {

// Comet Client
export interface IComet {
// index: (payload: IndexInput) => Promise<object>
prompt: (
payload: PromptPayload,
handleNewText?: (data: string) => void | Promise<void>
) => Promise<any>;
updateConfig: (payload: UpdateConfigPayload) => Promise<void>;
setGenerationModel: (payload: SetGenerationModelPayload) => Promise<void>;
listConversations: (payload: ListConversationsPayload) => Promise<object>;
getConversation: (payload: GetConversationPayload) => Promise<object>;
getMessage: (payload: GetMessagePayload) => Promise<object>;
getMessage: (payload: GetMessagePayload) => Promise<ICometMessage>;
takeConversationFeedback: (payload: ProvideMessageFeedbackPayload) => Promise<void>;
deleteComet: () => Promise<void>;
getCometInfo: () => Promise<ICometInfo>;
listSessions: (payload: ListSessionsPayload) => Promise<ICometSession[]>;
getSession: (payload: GetSessionPayload) => Promise<ICometSession>;
listConversations: <M extends boolean, S extends boolean>(
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 {
Expand Down Expand Up @@ -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<string, any> | null;
whitelistedDomains: string[];
promptVariables: Record<string, string>;
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<string, any>;
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<string, any> | null;
createdAt: string;
updatedAt: string;
}

export type CometMessageAuthor = 'agent' | 'human' | 'system' | 'function';

export interface ICometMessage {
id: string;
text: string;
from: CometMessageAuthor;
meta: Record<string, any> | null;
conversationId: string;
createdAt: string;
}

0 comments on commit a864ad2

Please sign in to comment.