Skip to content

Enhance PromptRunner interface #1729

Description

@stefanks-px

Hello,

I have a simple use case where I want to use the PromptRunner interface to

  • Add a system message via template with substitutions
  • Add a user message
  • Convert the response to an object

I don't see how to do this with the Rendering or Creating builder. We need a strict separation of the system and user message to make use of prompt-caching. My workaround right now:

        String systemPrompt = templateRenderer.renderLoadedTemplate("ssystem-prompt",
                Map.of("ABC", "ABC")
        );
        List<Message> messages = Stream.concat(
                Stream.of(new SystemMessage(systemPrompt)),
                input.conversation().getMessages().stream()
        ).toList();

        return context.ai()
                .withLlm(llmOptions)
                .creating(ABC.class)
                .fromMessages(messages);

Is there an easier way to do this or is this still missing?

Pinned by igordayen

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions