Vancouver.Prompt behaviour (Vancouver v0.3.0)

View Source

Prompts provide LLMs with autogenerated user/assistant prompts.

You can implement a prompt as follows:

defmodule MyApp.Prompts.CodeReview do
  use Vancouver.Prompt

  def name, do: "code_review"
  def description, do: "Asks the LLM to analyze code quality and suggest improvements"

  def arguments do
    [
      %{
        "name" => "code",
        "description" => "The code to review",
        "required" => true
      }
    ]
  end

  def run(conn, %{"code" => code}) do
    send_text(conn, "Please review this code: #{code}")
  end
end

Sending responses

Prompts provide helper functions to send valid MCP responses:

Summary

Callbacks

Schema defining the prompt's arguments.

Human readable description of what the prompt does.

Unique identifier for the prompt.

Execute the prompt with the given arguments.

Types

role()

@type role() :: :user | :assistant

Callbacks

arguments()

@callback arguments() :: [map()]

Schema defining the prompt's arguments.

description()

@callback description() :: String.t()

Human readable description of what the prompt does.

name()

@callback name() :: String.t()

Unique identifier for the prompt.

run(conn, params)

@callback run(conn :: Plug.Conn.t(), params :: map()) :: Plug.Conn.t()

Execute the prompt with the given arguments.

Functions

send_audio(conn, base64_data, mime_type, opts \\ [])

@spec send_audio(Plug.Conn.t(), binary(), binary(), Keyword.t()) :: Plug.Conn.t()

Sends audio response.

Accepts a :role option, which can be either :user or :assistant, defaulting to :user.

Examples

iex> send_audio(conn, "base64-encoded-audio-data", "audio/wav")

iex> send_audio(conn, "base64-encoded-audio-data", "audio/wav", role: :user)

iex> send_audio(conn, "base64-encoded-audio-data", "audio/wav", role: :assistant)

send_image(conn, base64_data, mime_type, opts \\ [])

@spec send_image(Plug.Conn.t(), binary(), binary(), Keyword.t()) :: Plug.Conn.t()

Sends image response.

Accepts a :role option, which can be either :user or :assistant, defaulting to :user.

Examples

iex> send_image(conn, "base64-encoded-data", "image/png")

iex> send_image(conn, "base64-encoded-data", "image/png", role: :user)

iex> send_image(conn, "base64-encoded-data", "image/png", role: :assistant)

send_text(conn, text, opts \\ [])

@spec send_text(Plug.Conn.t(), binary(), Keyword.t()) :: Plug.Conn.t()

Sends text response.

Accepts a :role option, which can be either :user or :assistant, defaulting to :user.

Examples

iex> send_text(conn, "hello")

iex> send_text(conn, "hello", role: :user)

iex> send_text(conn, "hello", role: :assistant)