choonkeat/elm-openai/1.0.0

NOTE: the latest version is 3.0.0

OpenAI.Completion

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

See https://beta.openai.com/docs/api-reference/completions

create : Input -> TaskInput (Error String) Output

https://beta.openai.com/docs/api-reference/completions/create

create
    { model = OpenAI.ModelID.TextDavinci003
    , prompt = "If I were a farmer's son"
    , suffix = Nothing
    , max_tokens = Nothing
    , temperature = Nothing
    , top_p = Nothing
    , n = Nothing
    , stream = Nothing
    , logprobs = Nothing
    , echo = Nothing
    , stop = Nothing
    , presence_penalty = Nothing
    , frequency_penalty = Nothing
    , best_of = Nothing
    , logit_bias = Nothing
    , user = Nothing
    }
    |> OpenAI.withConfig cfg
    |> Http.task
--> Task.succeed
-->     { choices =
-->         [ { finish_reason = "length"
-->           , index = 0
-->           , logprobs = Nothing
-->           , text = "\n\nIf I were a farmer's son
-->           , I would rise early each morning"
-->           }
-->         ]
-->     , created = Posix ...
-->     , id = "cmpl-..."
-->     , model = TextDavinci003
-->     , object = "text_completion"
-->     , usage =
-->         { completion_tokens = 16
-->         , prompt_tokens = 7
-->         , total_tokens = 23
-->         }
-->     }
type alias Input =
{ model : ModelID
, prompt : String
, suffix : Maybe String
, max_tokens : Maybe Int
, temperature : Maybe Float
, top_p : Maybe Float
, n : Maybe Int
, stream : Maybe Bool
, logprobs : Maybe Int
, echo : Maybe Bool
, stop : Maybe (List String)
, presence_penalty : Maybe Float
, frequency_penalty : Maybe Float
, best_of : Maybe Int
, logit_bias : Maybe (Dict String Int)
, user : Maybe String
}
type alias Output =
{ id : String
, object : String
, created : Posix
, model : ModelID
, choices : List Choice
, usage : Usage
}
type alias Choice =
{ text : String
, index : Int
, logprobs : Maybe Logprob
, finish_reason : String
}
type alias Logprob =
{ tokens : List String
, token_logprobs : List Float
, top_logprobs : Dict String Float
, text_offset : List Int
}