From b256052705df81fc6f97c4819b063d929180dac7 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sun, 16 Apr 2023 11:12:04 +0800 Subject: [PATCH] Minor refactor Remove message and combine types to chat. Also use correct package name. --- package.json | 4 ++-- src/platforms/openai/chat.ts | 14 +++++++++++++- src/platforms/openai/features/chat-completion.ts | 3 +-- src/platforms/openai/index.ts | 2 +- src/platforms/openai/message.ts | 12 ------------ 5 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 src/platforms/openai/message.ts diff --git a/package.json b/package.json index cbbf297..7f05561 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "openai-utils", + "name": "@modal-sh/mio-ai", "version": "0.0.0", "files": [ "dist", @@ -34,7 +34,7 @@ "test": "vitest" }, "private": false, - "description": "Custom wrapper for OpenAI API.", + "description": "Many-in-one AI client.", "repository": { "url": "https://code.modal.sh/modal-soft/openai-utils", "type": "git" diff --git a/src/platforms/openai/chat.ts b/src/platforms/openai/chat.ts index 50fd960..bbc96f6 100644 --- a/src/platforms/openai/chat.ts +++ b/src/platforms/openai/chat.ts @@ -1,5 +1,17 @@ import Handlebars from 'handlebars'; -import { Message, MessageRole } from './message'; + +export enum MessageRole { + SYSTEM = 'system', + USER = 'user', + ASSISTANT = 'assistant', +} + +export interface MessageObject { + role: MessageRole; + content: string; +} + +export type Message = string | MessageObject; const isValidMessageObject = (maybeMessage: unknown): maybeMessage is Message => { if (typeof maybeMessage !== 'object') { diff --git a/src/platforms/openai/features/chat-completion.ts b/src/platforms/openai/features/chat-completion.ts index 66e92a3..f33275d 100644 --- a/src/platforms/openai/features/chat-completion.ts +++ b/src/platforms/openai/features/chat-completion.ts @@ -7,9 +7,8 @@ import { PlatformResponse, UsageMetadata, } from '../common'; -import { Message, MessageObject } from '../message'; import { ChatCompletionModel } from '../models'; -import { normalizeChatMessage } from '../chat'; +import { normalizeChatMessage, Message, MessageObject } from '../chat'; export interface CreateChatCompletionParams { messages: Message | Message[]; diff --git a/src/platforms/openai/index.ts b/src/platforms/openai/index.ts index 5b87ccb..49b9ef4 100644 --- a/src/platforms/openai/index.ts +++ b/src/platforms/openai/index.ts @@ -1,6 +1,6 @@ import { Configuration } from './common'; -export * from './message'; +export * from './chat'; export * from './models'; export * from './common'; export { PlatformEventEmitter, PlatformEventEmitterImpl } from './events'; diff --git a/src/platforms/openai/message.ts b/src/platforms/openai/message.ts deleted file mode 100644 index f5150ef..0000000 --- a/src/platforms/openai/message.ts +++ /dev/null @@ -1,12 +0,0 @@ -export enum MessageRole { - SYSTEM = 'system', - USER = 'user', - ASSISTANT = 'assistant', -} - -export interface MessageObject { - role: MessageRole; - content: string; -} - -export type Message = string | MessageObject;