Prompt
The prompt module contains functions and types for needed to interact with the OpenRouter API using basic prompt strings. In addition to functions for creating and handling API requests, the module includes functions for formatting prompts for models with Llama-style fine-tuning.
Client : Client.Client
PromptRequestBody
The structure of the request body to be sent in the Http request
PromptResponseBody
The structure of the JSON response body received from the OpenRouter API
new_client
Initialize the OpenRouter API client with the required API key. All parameters besides apiKey are completely optional, and may be set during initialization, assigned later, or left as their defaults.
client = Chat.initClient { apiKey: "your_openrouter_api_key" }
Same as Client.init
.
build_http_request : Client, Str -> RequestObject
Create a request object to be sent with basic-cli's Http.send using a prompt string
build_request_body : Client, Str -> PromptRequestBody
Build the request body to be sent in the Http request using a prompt string
encode_request_body : PromptRequestBody -> List U8
Encode the request body to be sent in the Http request
decode_response : List U8 -> Result PromptResponseBody
Decode the JSON response to a prompt string request
decode_top_text_choice :
List U8
-> Result Str
[
ApiError ApiError,
DecodingError,
NoChoices,
BadJson Str
]
Decode the JSON response body to the first message in the list of choices
decode_error_response
Decode the JSON response body of an API error message
format_llama_prompt :
{
prompt : Str,
sys_message ? Str
}
-> Str
Format the prompt and system message into a Llama-style prompt string.
[INST] <<SYS>> system message here <<SYS>> prompt here [/INST]
format_llama_prompt_with_history : Str, Str -> Str
Format the prompt and conversation history into a Llama-style conversation history string.
<s>1st exchange</s> <s>...</s> <s>Nth exchange</s> <s>[INST] <<SYS>> system message here <<SYS>> prompt here [/INST]
update_llama_conversation_history :
{
prompt_str : Str,
bot_reply : Str,
conversation_history ? Str
}
-> Str
Format the most recent prompt and bot reply, and optionally the previous conversation history, into a Llama-style conversation history string.
<s>[INST] <<SYS>> system message here <<SYS>> first prompt here [/INST]first bot reply here</s> <s>2nd exchange</s> <s>...</s> <s>Nth exchange</s>