diff --git a/etc/chat-core.api.md b/etc/chat-core.api.md index c564c98..450a373 100644 --- a/etc/chat-core.api.md +++ b/etc/chat-core.api.md @@ -55,7 +55,7 @@ export enum Environment { // // @internal export interface InternalConfig { - // (undocumented) + aiMode?: string; promptPackage?: ChatPrompt; } @@ -83,8 +83,6 @@ export interface MessageRequest { conversationId?: string; messages: Message[]; notes?: MessageNotes; - // @internal - promptPackage?: ChatPrompt; } // @public diff --git a/package-lock.json b/package-lock.json index fec474f..4eadbbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/chat-core", - "version": "0.7.0", + "version": "0.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@yext/chat-core", - "version": "0.7.0", + "version": "0.7.1", "license": "BSD-3-Clause", "dependencies": { "cross-fetch": "^3.1.5" diff --git a/package.json b/package.json index dbdc19d..4e86a38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/chat-core", - "version": "0.7.0", + "version": "0.7.1", "description": "Typescript Networking Library for the Yext Chat API", "main": "./dist/commonjs/index.js", "module": "./dist/esm/index.mjs", diff --git a/src/infra/ChatCoreImpl.ts b/src/infra/ChatCoreImpl.ts index 1d44141..60e797b 100644 --- a/src/infra/ChatCoreImpl.ts +++ b/src/infra/ChatCoreImpl.ts @@ -9,7 +9,6 @@ import { MessageRequest, MessageResponse, Endpoints, - ChatPrompt, } from "../models"; import { ApiMessageRequest } from "../models/endpoints/MessageRequest"; import { ApiResponse } from "../models/http/ApiResponse"; @@ -25,14 +24,13 @@ export class ChatCoreImpl implements ChatCore { private chatConfig: ChatConfig; private httpService: HttpService; private endpoints: Endpoints; - private promptPackage: ChatPrompt; + private internalConfig: InternalConfig; - constructor(chatConfig: ChatConfig, internalConfig?: InternalConfig) { + constructor(chatConfig: ChatConfig, internalConfig: InternalConfig = {}) { this.chatConfig = chatConfig; this.httpService = new HttpServiceImpl(); - this.endpoints = - chatConfig.endpoints ?? EndpointsFactory.getEndpoints(this.chatConfig); - this.promptPackage = internalConfig?.promptPackage ?? "stable"; + this.endpoints = chatConfig.endpoints ?? EndpointsFactory.getEndpoints(this.chatConfig); + this.internalConfig = internalConfig } async getNextMessage(request: MessageRequest): Promise { @@ -40,7 +38,8 @@ export class ChatCoreImpl implements ChatCore { const body: ApiMessageRequest = { ...request, version: this.chatConfig.version, - promptPackage: this.promptPackage, + promptPackage: this.internalConfig.promptPackage, + aiMode: this.internalConfig.aiMode }; const rawResponse = await this.httpService.post( this.endpoints.chat, @@ -74,7 +73,8 @@ export class ChatCoreImpl implements ChatCore { const body: ApiMessageRequest = { ...request, version: this.chatConfig.version, - promptPackage: this.promptPackage, + promptPackage: this.internalConfig.promptPackage, + aiMode: this.internalConfig.aiMode }; const rawResponse = await this.httpService.post( this.endpoints.chatStream, diff --git a/src/models/InternalConfig.ts b/src/models/InternalConfig.ts index 7a6286a..e7b8e52 100644 --- a/src/models/InternalConfig.ts +++ b/src/models/InternalConfig.ts @@ -14,5 +14,21 @@ export type ChatPrompt = "stable" | "nightly"; * @internal */ export interface InternalConfig { + /** + * promptPackage corresponds to the package of prompts which will be used + * to carry out the instruction steps. When set to "nightly", the bot will + * use the most recent updates to the prompts, which may include experimental + * changes. + * It is STRONGLY recommended to use the default "stable" for your bot. + * + * @remarks + * The set of prompts which will be used by the bot's instruction steps. + * Defaults to "stable", which is the set of tested and verified prompts. + */ promptPackage?: ChatPrompt; + /** + * Modes to determine types of models to use when sending requests the bot's + * instruction steps. + */ + aiMode?: string; } diff --git a/src/models/endpoints/MessageRequest.ts b/src/models/endpoints/MessageRequest.ts index 81eb4d2..d48a6b8 100644 --- a/src/models/endpoints/MessageRequest.ts +++ b/src/models/endpoints/MessageRequest.ts @@ -40,19 +40,6 @@ export interface MessageRequest { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any context?: any; - /** - * promptPackage corresponds to the package of prompts which will be used - * to carry out the instruction steps. When set to "nightly", the bot will - * use the most recent updates to the prompts, which may include experimental - * changes. - * It is STRONGLY recommended to use the default "stable" for your bot. - * - * @remarks - * The set of prompts which will be used by the bot's instruction steps. - * Defaults to "stable", which is the set of tested and verified prompts. - * @internal - */ - promptPackage?: ChatPrompt; } /** @@ -69,6 +56,8 @@ export interface ApiMessageRequest { messages: Message[]; /** {@inheritDoc MessageNotes} */ notes?: MessageNotes; - /** {@inheritdoc MessageRequest.promptPackage} */ + /** {@inheritDoc InternalConfig.promptPackage} */ promptPackage?: ChatPrompt; + /** {@inheritDoc InternalConfig.aiMode} */ + aiMode?: string; } diff --git a/test-node-cjs/node.ts b/test-node-cjs/node.ts index a20890f..0128f7b 100644 --- a/test-node-cjs/node.ts +++ b/test-node-cjs/node.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import http from "http"; -import { ChatConfig, StreamEventName, provideChatCore } from "@yext/chat-core"; +import { ChatConfig, InternalConfig, MessageRequest, StreamEventName, provideChatCoreInternal } from "@yext/chat-core"; import dotenv from "dotenv"; dotenv.config(); @@ -14,17 +14,21 @@ const config: ChatConfig = { }, }; +const internalConfig: InternalConfig = { /** for testing pursposes */} + +const request: MessageRequest = { + messages: [ + { + timestamp: "2023-05-17T19:21:21.915Z", + source: "USER", + text: "How do I send an email?", + } + ] +} + async function stream(res: any) { - const chatCore = provideChatCore(config); - const stream = await chatCore.streamNextMessage({ - messages: [ - { - timestamp: "2023-05-17T19:21:21.915Z", - source: "USER", - text: "How do I send an email?", - }, - ], - }); + const chatCore = provideChatCoreInternal(config, internalConfig); + const stream = await chatCore.streamNextMessage(request); Object.values(StreamEventName).forEach((eventName) => { stream.addEventListener(eventName, (event) => { console.log(`${eventName}:`, event.data); @@ -42,10 +46,8 @@ const server = http.createServer(async (req: any, res: any) => { if (req.url === "/streaming") { stream(res); } else { - const chatCore = provideChatCore(config); - const reply = await chatCore.getNextMessage({ - messages: [], - }); + const chatCore = provideChatCoreInternal(config, internalConfig); + const reply = await chatCore.getNextMessage(request); res.end(JSON.stringify(reply, null, 2)); } }); diff --git a/test-node-cjs/package-lock.json b/test-node-cjs/package-lock.json index eba6870..32480f7 100644 --- a/test-node-cjs/package-lock.json +++ b/test-node-cjs/package-lock.json @@ -19,7 +19,7 @@ }, "..": { "name": "@yext/chat-core", - "version": "0.7.0", + "version": "0.7.1", "license": "BSD-3-Clause", "dependencies": { "cross-fetch": "^3.1.5" diff --git a/tests/ChatCore.test.ts b/tests/ChatCore.test.ts index e3069ff..e51c84f 100644 --- a/tests/ChatCore.test.ts +++ b/tests/ChatCore.test.ts @@ -14,7 +14,6 @@ const mockedMessageRequest: MessageRequest = { foo: "bar", }, messages: [], - promptPackage: "stable", }; const defaultConfig: ChatConfig = { @@ -131,7 +130,7 @@ describe("URL and http request construction", () => { foo: "bar", }, messages: [], - promptPackage: "stable", + }, "my-api-key" ); @@ -150,7 +149,6 @@ describe("URL and http request construction", () => { foo: "bar", }, messages: [], - promptPackage: "stable", }, "my-api-key" ); @@ -175,7 +173,6 @@ describe("URL and http request construction", () => { foo: "bar", }, messages: [], - promptPackage: "stable", }, "my-api-key" ); @@ -195,7 +192,6 @@ describe("URL and http request construction", () => { foo: "bar", }, messages: [], - promptPackage: "stable", }, "my-api-key" );