Vancouver.Prompt behaviour (Vancouver v0.3.0)
View SourcePrompts 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:
send_audio/4
- sends an audio responsesend_image/4
- sends an image responsesend_text/3
- sends a text response
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
Callbacks
@callback arguments() :: [map()]
Schema defining the prompt's arguments.
@callback description() :: String.t()
Human readable description of what the prompt does.
@callback name() :: String.t()
Unique identifier for the prompt.
@callback run(conn :: Plug.Conn.t(), params :: map()) :: Plug.Conn.t()
Execute the prompt with the given arguments.
Functions
@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)
@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)
@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)