From 79e380371963f6714f673554df86f3258acdf89c Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Wed, 20 Mar 2024 08:44:19 +0100 Subject: [PATCH] feat: system prompt for playground page Signed-off-by: Philippe Martin --- .../src/managers/playgroundV2Manager.ts | 8 +- packages/backend/src/studio-api-impl.ts | 9 ++- packages/frontend/src/pages/Playground.svelte | 77 +++++++++++++------ packages/shared/src/StudioAPI.ts | 7 +- 4 files changed, 72 insertions(+), 29 deletions(-) diff --git a/packages/backend/src/managers/playgroundV2Manager.ts b/packages/backend/src/managers/playgroundV2Manager.ts index cf46e1475..c43ed32c9 100644 --- a/packages/backend/src/managers/playgroundV2Manager.ts +++ b/packages/backend/src/managers/playgroundV2Manager.ts @@ -87,7 +87,7 @@ export class PlaygroundV2Manager extends Publisher implements Di * @param userInput the user input * @param options the model configuration */ - async submit(playgroundId: string, userInput: string, options?: ModelOptions): Promise { + async submit(playgroundId: string, userInput: string, systemPrompt: string, options?: ModelOptions): Promise { const playground = this.#playgrounds.get(playgroundId); if (playground === undefined) throw new Error('Playground not found.'); @@ -122,8 +122,12 @@ export class PlaygroundV2Manager extends Publisher implements Di apiKey: 'dummy', }); + const messages = this.getFormattedMessages(playground.id); + if (systemPrompt) { + messages.push({ role: 'system', content: systemPrompt }); + } const response = await client.chat.completions.create({ - messages: this.getFormattedMessages(playground.id), + messages, stream: true, model: modelInfo.file.file, ...options, diff --git a/packages/backend/src/studio-api-impl.ts b/packages/backend/src/studio-api-impl.ts index 170b96313..fb93dd9f0 100644 --- a/packages/backend/src/studio-api-impl.ts +++ b/packages/backend/src/studio-api-impl.ts @@ -72,8 +72,13 @@ export class StudioApiImpl implements StudioAPI { return this.playgroundV2.getPlaygrounds(); } - submitPlaygroundMessage(containerId: string, userInput: string, options?: ModelOptions): Promise { - return this.playgroundV2.submit(containerId, userInput, options); + submitPlaygroundMessage( + containerId: string, + userInput: string, + systemPrompt: string, + options?: ModelOptions, + ): Promise { + return this.playgroundV2.submit(containerId, userInput, systemPrompt, options); } async getPlaygroundConversations(): Promise { diff --git a/packages/frontend/src/pages/Playground.svelte b/packages/frontend/src/pages/Playground.svelte index 3575bb787..cad1def13 100644 --- a/packages/frontend/src/pages/Playground.svelte +++ b/packages/frontend/src/pages/Playground.svelte @@ -14,6 +14,7 @@ import { playgrounds } from '../stores/playgrounds-v2'; import { catalog } from '../stores/catalog'; import Button from '../lib/button/Button.svelte'; import { afterUpdate } from 'svelte'; +import ContentDetailsLayout from '../lib/ContentDetailsLayout.svelte'; export let playgroundId: string; let prompt: string; @@ -22,6 +23,9 @@ let scrollable: Element; let lastIsUserMessage = false; let errorMsg = ''; +// settings +let systemPrompt: string = ''; + $: conversation = $conversations.find(conversation => conversation.id === playgroundId); $: playground = $playgrounds.find(playground => playground.id === playgroundId); $: model = $catalog.models.find(model => model.id === playground?.modelId); @@ -63,7 +67,7 @@ function getMessageParagraphs(message: ChatMessage): string[] { function askPlayground() { errorMsg = ''; sendEnabled = false; - studioClient.submitPlaygroundMessage(playgroundId, prompt).catch((err: unknown) => { + studioClient.submitPlaygroundMessage(playgroundId, prompt, systemPrompt, {}).catch((err: unknown) => { errorMsg = String(err); sendEnabled = true; }); @@ -101,30 +105,55 @@ function elapsedTime(msg: AssistantChat): string { {model?.name}
-
- {#if conversation?.messages} -
    - {#each conversation?.messages as message} -
  • -
    {roleNames[message.role]}
    -
    - {#each getMessageParagraphs(message) as paragraph} -

    {paragraph}

    - {/each} -
    - {#if isAssistantChat(message)} -
    {elapsedTime(message)} s
    +
    + + +
    +
    + {#if conversation?.messages} +
      + {#each conversation?.messages as message} +
    • +
      + {roleNames[message.role]} +
      +
      + {#each getMessageParagraphs(message) as paragraph} +

      {paragraph}

      + {/each} +
      + {#if isAssistantChat(message)} +
      + {elapsedTime(message)} s +
      + {/if} +
      +
    • + {/each} +
    {/if} -
    -
  • - {/each} -
- {/if} +
+
+
+ +
+
System Prompt
+
+ +
+
+
+ {#if errorMsg}
{errorMsg}
diff --git a/packages/shared/src/StudioAPI.ts b/packages/shared/src/StudioAPI.ts index 508fca256..356e97e7f 100644 --- a/packages/shared/src/StudioAPI.ts +++ b/packages/shared/src/StudioAPI.ts @@ -137,7 +137,12 @@ export abstract class StudioAPI { * @param userInput the user input, e.g. 'What is the capital of France ?' * @param options the options for the model, e.g. temperature */ - abstract submitPlaygroundMessage(containerId: string, userInput: string, options?: ModelOptions): Promise; + abstract submitPlaygroundMessage( + containerId: string, + userInput: string, + systemPrompt: string, + options?: ModelOptions, + ): Promise; /** * Return the conversations