Slop.Client (slop v0.1.0)
View SourceA client for consuming SLOP (Simple Language Open Protocol) APIs.
This module provides functions for interacting with SLOP servers, making it easy to send requests to the standard SLOP endpoints.
Usage
# Initialize a client
client = Slop.Client.new("https://my-slop-server.com")
# Get server information
{:ok, info} = Slop.Client.info(client)
# Send a chat message
{:ok, response} = Slop.Client.chat(client, [
%{role: "user", content: "Hello, how are you?"}
])
# List available tools
{:ok, tools} = Slop.Client.list_tools(client)
# Execute a tool
{:ok, result} = Slop.Client.execute_tool(client, "calculator", %{
expression: "2 + 2"
})
Summary
Functions
Sends a chat message to the SLOP server.
Executes a tool on the SLOP server.
Gets a specific resource from the SLOP server.
Gets information about the SLOP server.
Gets resources from the SLOP server.
Lists the tools available on the SLOP server.
Creates a new SLOP client.
Searches for resources on the SLOP server.
Types
Functions
Sends a chat message to the SLOP server.
Examples
{:ok, response} = Slop.Client.chat(client, [
%{role: "user", content: "Hello, how are you?"}
])
# response = %{
# "response" => "I'm doing well, thank you for asking!",
# "messages" => [
# %{"role" => "user", "content" => "Hello, how are you?"},
# %{"role" => "assistant", "content" => "I'm doing well, thank you for asking!"}
# ]
# }
Executes a tool on the SLOP server.
Examples
{:ok, result} = Slop.Client.execute_tool(client, "calculator", %{
expression: "2 + 2"
})
# result = %{
# "id" => "calculator",
# "result" => "The result is 4"
# }
Gets a specific resource from the SLOP server.
Examples
{:ok, %{"resource" => resource}} = Slop.Client.get_resource(client, "article-1")
# resource = %{
# "id" => "article-1",
# "title" => "Article 1",
# "content" => "...",
# ...
# }
Gets information about the SLOP server.
Examples
{:ok, info} = Slop.Client.info(client)
# info = %{
# "name" => "Example SLOP Server",
# "version" => "1.0.0",
# "endpoints" => ["chat", "info"],
# ...
# }
Gets resources from the SLOP server.
Examples
{:ok, %{"resources" => resources}} = Slop.Client.list_resources(client)
# resources = [
# %{
# "id" => "article-1",
# "title" => "Article 1",
# ...
# },
# ...
# ]
Lists the tools available on the SLOP server.
Examples
{:ok, %{"tools" => tools}} = Slop.Client.list_tools(client)
# tools = [
# %{
# "id" => "calculator",
# "name" => "Calculator",
# "description" => "Perform mathematical calculations",
# ...
# },
# ...
# ]
Creates a new SLOP client.
Options
:headers
- Additional headers to include in requests:http_client
- The HTTP client module to use (default:HTTPoison
)
Examples
# Basic client
client = Slop.Client.new("https://my-slop-server.com")
# Client with authentication
client = Slop.Client.new("https://my-slop-server.com",
headers: [{"Authorization", "Bearer my-token"}]
)
Searches for resources on the SLOP server.
Examples
{:ok, %{"results" => results}} = Slop.Client.search_resources(client, "example")
# results = [
# %{
# "id" => "article-1",
# "title" => "Example Article",
# "score" => 0.9,
# ...
# },
# ...
# ]