bananaproai-com
A helpful Elixir library for interacting with the Banana Pro AI inference platform. This package provides a streamlined interface for building and deploying machine learning models with ease.
Installation
To install bananaproai-com, add it as a dependency to your mix.exs file:
elixir
def deps do
[
{:bananaproai_com, "~> 0.1.0"} # Replace with the latest version] end
Then, run mix deps.get to fetch the dependency.
Usage
Before using the library, configure your API key. You can set it via application configuration: elixir config :bananaproai_com, api_key: "YOUR_API_KEY"
Or, set it as an environment variable BANANA_API_KEY.
Here are some examples of how to use the bananaproai-com library:
1. Invoking a model with input data: elixir alias BananaProAI.Client
input_data = %{ "prompt" => "Generate a picture of a cat wearing a hat" }
case Client.call("your-model-id", input_data) do {:ok, response} ->
IO.inspect(response) # Inspect the API response->
IO.puts("Error: #{error}")end
2. Handling different response types: elixir alias BananaProAI.Client
input_data = %{ "text" => "Translate to French: Hello world!" }
case Client.call("translation-model", input_data) do {:ok, %{"text" => translated_text}} ->
IO.puts("Translation: #{translated_text}")->
IO.puts("Unexpected response: #{inspect(response)}")->
IO.puts("Error: #{error}")end
3. Using with for cleaner error handling:
elixir
alias BananaProAI.Client
input_data = %{ "image_url" => "https://example.com/image.jpg" }
with {:ok, response} <- Client.call("image-processing-model", input_data),
{:ok, image_data} <- Map.fetch(response, "processed_image") doIO.puts("Processed image data: #{image_data}") else {:error, error} ->
IO.puts("Error: #{error}")_ ->
IO.puts("Unexpected error occurred.")end
4. Passing parameters and processing results within a pipe: elixir alias BananaProAI.Client
input_data = %{ "input_string" => "This is a test." }
input_data |> Client.call("string-analysis-model") |> case do {:ok, %{"sentiment" => sentiment}} ->
IO.puts("Sentiment: #{sentiment}")->
IO.puts("Unexpected response: #{inspect(response)}")->
IO.puts("Error: #{error}")end
5. Handling asynchronous calls (if the API supports it): elixir alias BananaProAI.Client
input_data = %{ "complex_task" => "Do something computationally intensive" }
case Client.call("long-running-model", input_data, async: true) do {:ok, %{"task_id" => task_id}} ->
IO.puts("Task submitted. Task ID: #{task_id}")
# Poll the API later using the task_id to get the result->
IO.puts("Error: #{error}")end
Features
- Easy integration with the Banana Pro AI platform.
- Simple function calls to run your models.
- Robust error handling.
- Support for synchronous and asynchronous calls.
- Flexible input and output data structures.
License
MIT
This package is part of the bananaproai-com ecosystem. For advanced features and enterprise-grade tools, visit: https://bananaproai.com/