View Source ExOpenAi.EmbeddingRequest (ex_open_ai v0.1.9)
Represents an embedding request to the OpenAI API.
Link to this section Summary
Functions
Builds the create embedding request and validates the required fields.
Deletes any fields that are not in the list of fields.
Builds the map by adding to the existing map and updates the map with the attributes passed in.
Ensures that the map has the required fields.
Prepares the map by removing any fields that are not in the list of fields. and ensures required fields are present.
Link to this section Functions
@spec create(params :: map()) :: {:ok, ExOpenAi.Embedding.t()} | {:error, map()}
Builds the create embedding request and validates the required fields.
Deletes any fields that are not in the list of fields.
examples
Examples
iex> params = %{
...> model: "text-model",
...> messages: [
...> %{content: "hello"}
...> ]
...> }
iex> Request.delete_invalid_fields(params, [:model, :messages])
%{model: "text-model", messages: [%{content: "hello"}]}
Builds the map by adding to the existing map and updates the map with the attributes passed in.
examples
Examples
iex> params = %{
...> model: "text-model",
...> messages: [
...> %{content: "hello"}
...> ]
...> }
iex> Request.do_change(params, promp: "this is a prompt")
%{model: "text-model", messages: [%{content: "hello"}], prompt: "this is a prompt"}
Ensures that the map has the required fields.
examples
Examples
iex> params = %{model: "text-model", messages: [%{content: "hello"}]}
iex> Request.has_required_fields?(params, [:model, :messages])
true
iex> params = %{model: "text-model"}
iex> Request.has_required_fields?(params, [:model, :messages])
false
Prepares the map by removing any fields that are not in the list of fields. and ensures required fields are present.
examples
Examples
iex> params = %{
...> model: "text-model",
...> messages: [
...> %{content: "hello"}
...> ]
...> }
iex> Request.prepare(params, [], [:model, :messages])
%{model: "text-model", messages: [%{content: "hello"}]}
iex> params = %{
...> model: "text-model",
...> messages: [
...> %{content: "hello"}
...> ]
...> }
iex> Request.prepare(params, [], [:model, :messages, :prompt])
** (RuntimeError) Required fields are missing