Package config in Livebook notebook

Hi!

I was going to play with the package openai [1] in a livebook notebook.

In the setup I added:

Mix.install([
  {:openai, "~> 0.1.1"}
])

However, I don’t know how/where to add the config (API key):

use Mix.Config

config :openai,
  api_key: "your-api-key",
  organization_key: "your-organization-key

Where should I place the package config (API key) so I can use it in a livebook notebook?
Thanks!

[1] GitHub - mgallo/openai.ex: community-maintained OpenAI API Wrapper written in Elixir.

3 Likes

Mix — Mix v1.13.4 see the second example

7 Likes

I missed that, thank you @LostKobrakai!

As a reference, I added this and it worked:

Mix.install(
  [{:openai, "~> 0.1.1"}],
  config: [
    openai: [
      api_key: "...",
      organisation_key: "...",
    ]
  ]
)
7 Likes

thanks for the tip!

Just wondering how I’d do it for something like Snap, GitHub - breakroom/snap: An Elasticsearch client for Elixir

It’s looking for a module to be created that you reference in the config, but if the config is in the Mix.install, then you can’t have a module defined before that

To answer my own question :stuck_out_tongue:

Mix.install([
  {:snap, "~> 0.9.0"},
  {:kino, "~> 0.12.3"},
  {:finch, "~> 0.18.0"}
])

defmodule Elastic do
  use Snap.Cluster, otp_app: :snap
end

Kino.start_child!({Elastic, [url: "http://elastic.local:9200"]})

Snap.Search.search(Elastic, "products", %{query: %{match_all: %{}}})
1 Like