From cfeb12fcb3bba86aa744240485f4e3354a6d402a Mon Sep 17 00:00:00 2001 From: niltonheck Date: Fri, 13 Sep 2024 00:10:34 -0300 Subject: [PATCH] feat: add custom prompt configuration --- src/answerSession.ts | 5 +++++ src/client.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/answerSession.ts b/src/answerSession.ts index 6c8237c..bf12a8a 100644 --- a/src/answerSession.ts +++ b/src/answerSession.ts @@ -192,6 +192,11 @@ export class AnswerSession { requestBody.append('interactionId', interactionId) requestBody.append('alias', this.oramaClient.getAlias() ?? '') + const systemPromptConfiguration = this.oramaClient.getSystemPromptConfiguration() + if (systemPromptConfiguration) { + requestBody.append('systemPrompts', JSON.stringify(systemPromptConfiguration)) + } + if (this.userContext) { requestBody.append('userContext', serializeUserContext(this.userContext)) } diff --git a/src/client.ts b/src/client.ts index 9552d01..5a640e3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -69,6 +69,7 @@ export class OramaClient { private readonly collector?: Collector private readonly cache?: Cache> private readonly profile: Profile + private systemPrompts?: string[] private searchDebounceTimer?: any // NodeJS.Timer private searchRequestCounter = 0 private blockSearchTillAuth = false @@ -430,4 +431,21 @@ export class OramaClient { public reset(): void { this.profile.reset() } + + /** + * Methods associated with custom system prompts + */ + public setSystemPromptConfiguration(config: { systemPrompts: string[] }): void { + if (Array.isArray(config.systemPrompts)) { + if (!config.systemPrompts.every((prompt) => typeof prompt === 'string')) { + throw new Error('Invalid system prompt configuration') + } + + this.systemPrompts = config.systemPrompts + } + } + + public getSystemPromptConfiguration(): string[] | undefined { + return this.systemPrompts + } }