| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
OpenAI.Client
Synopsis
- type ApiKey = Text
- data OpenAIClient
- makeOpenAIClient :: ApiKey -> Manager -> Int -> OpenAIClient
- data ClientError
- newtype TimeStamp = TimeStamp {}
- newtype OpenAIList a = OpenAIList {}
- newtype EngineId = EngineId {
- unEngineId :: Text
- data Engine = Engine {}
- listEngines :: OpenAIClient -> IO (Either ClientError (OpenAIList Engine))
- getEngine :: OpenAIClient -> EngineId -> IO (Either ClientError Engine)
- newtype TextCompletionId = TextCompletionId {}
- data TextCompletionChoice = TextCompletionChoice {
- tccText :: Text
- tccIndex :: Int
- tccLogProps :: Maybe Int
- tccFinishReason :: Text
- data TextCompletion = TextCompletion {}
- data TextCompletionCreate = TextCompletionCreate {}
- defaultTextCompletionCreate :: Text -> TextCompletionCreate
- completeText :: OpenAIClient -> EngineId -> TextCompletionCreate -> IO (Either ClientError TextCompletion)
- data SearchResult = SearchResult {
- srDocument :: Int
- srScore :: Double
- data SearchResultCreate = SearchResultCreate {
- sccrDocuments :: Vector Text
- sccrQuery :: Text
- searchDocuments :: OpenAIClient -> EngineId -> SearchResultCreate -> IO (Either ClientError (OpenAIList SearchResult))
Basics
Your OpenAI API key. Can be obtained from the OpenAI dashboard. Format: sk-redacted
data OpenAIClient Source #
Holds a Manager and your API key.
Arguments
| :: ApiKey | |
| -> Manager | |
| -> Int | Number of automatic retries the library should attempt. |
| -> OpenAIClient |
Construct a OpenAIClient. Note that the passed Manager must support https (e.g. via http-client-tls)
data ClientError #
A type representing possible errors in a request
Note that this type substantially changed in 0.12.
Constructors
| FailureResponse (RequestF () (BaseUrl, ByteString)) Response | The server returned an error response including the
failing request. |
| DecodeFailure Text Response | The body could not be decoded at the expected type |
| UnsupportedContentType MediaType Response | The content-type of the response is not supported |
| InvalidContentTypeHeader Response | The content-type header is invalid |
| ConnectionError SomeException | There was a connection error, and no response was received |
Instances
Helper types
A UTCTime wrapper that has unix timestamp JSON representation
Constructors
| TimeStamp | |
Fields | |
Instances
| Eq TimeStamp | |
| Show TimeStamp | |
| ToJSON TimeStamp | |
Defined in OpenAI.Resources | |
| FromJSON TimeStamp | |
| ToHttpApiData TimeStamp | |
Defined in OpenAI.Resources Methods toUrlPiece :: TimeStamp -> Text # toEncodedUrlPiece :: TimeStamp -> Builder # toHeader :: TimeStamp -> ByteString # toQueryParam :: TimeStamp -> Text # | |
newtype OpenAIList a #
A Vector wrapper.
Constructors
| OpenAIList | |
Instances
Engine
Constructors
| EngineId | |
Fields
| |
Instances
| Eq EngineId | |
| Show EngineId | |
| ToJSON EngineId | |
Defined in OpenAI.Resources | |
| FromJSON EngineId | |
| ToHttpApiData EngineId | |
Defined in OpenAI.Resources Methods toUrlPiece :: EngineId -> Text # toEncodedUrlPiece :: EngineId -> Builder # toHeader :: EngineId -> ByteString # toQueryParam :: EngineId -> Text # | |
listEngines :: OpenAIClient -> IO (Either ClientError (OpenAIList Engine)) Source #
getEngine :: OpenAIClient -> EngineId -> IO (Either ClientError Engine) Source #
Text completion
newtype TextCompletionId #
Constructors
| TextCompletionId | |
Fields | |
Instances
| Eq TextCompletionId | |
Defined in OpenAI.Resources Methods (==) :: TextCompletionId -> TextCompletionId -> Bool # (/=) :: TextCompletionId -> TextCompletionId -> Bool # | |
| Show TextCompletionId | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> TextCompletionId -> ShowS # show :: TextCompletionId -> String # showList :: [TextCompletionId] -> ShowS # | |
| ToJSON TextCompletionId | |
Defined in OpenAI.Resources Methods toJSON :: TextCompletionId -> Value # toEncoding :: TextCompletionId -> Encoding # toJSONList :: [TextCompletionId] -> Value # toEncodingList :: [TextCompletionId] -> Encoding # | |
| FromJSON TextCompletionId | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser TextCompletionId # parseJSONList :: Value -> Parser [TextCompletionId] # | |
| ToHttpApiData TextCompletionId | |
Defined in OpenAI.Resources Methods toUrlPiece :: TextCompletionId -> Text # toEncodedUrlPiece :: TextCompletionId -> Builder # toHeader :: TextCompletionId -> ByteString # toQueryParam :: TextCompletionId -> Text # | |
data TextCompletionChoice #
Constructors
| TextCompletionChoice | |
Fields
| |
Instances
| Eq TextCompletionChoice | |
Defined in OpenAI.Resources Methods (==) :: TextCompletionChoice -> TextCompletionChoice -> Bool # (/=) :: TextCompletionChoice -> TextCompletionChoice -> Bool # | |
| Show TextCompletionChoice | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> TextCompletionChoice -> ShowS # show :: TextCompletionChoice -> String # showList :: [TextCompletionChoice] -> ShowS # | |
| ToJSON TextCompletionChoice | |
Defined in OpenAI.Resources Methods toJSON :: TextCompletionChoice -> Value # toEncoding :: TextCompletionChoice -> Encoding # toJSONList :: [TextCompletionChoice] -> Value # toEncodingList :: [TextCompletionChoice] -> Encoding # | |
| FromJSON TextCompletionChoice | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser TextCompletionChoice # parseJSONList :: Value -> Parser [TextCompletionChoice] # | |
data TextCompletion #
Constructors
| TextCompletion | |
Fields | |
Instances
| Eq TextCompletion | |
Defined in OpenAI.Resources Methods (==) :: TextCompletion -> TextCompletion -> Bool # (/=) :: TextCompletion -> TextCompletion -> Bool # | |
| Show TextCompletion | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> TextCompletion -> ShowS # show :: TextCompletion -> String # showList :: [TextCompletion] -> ShowS # | |
| ToJSON TextCompletion | |
Defined in OpenAI.Resources Methods toJSON :: TextCompletion -> Value # toEncoding :: TextCompletion -> Encoding # toJSONList :: [TextCompletion] -> Value # toEncodingList :: [TextCompletion] -> Encoding # | |
| FromJSON TextCompletion | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser TextCompletion # parseJSONList :: Value -> Parser [TextCompletion] # | |
data TextCompletionCreate #
Constructors
| TextCompletionCreate | |
Fields
| |
Instances
| Eq TextCompletionCreate | |
Defined in OpenAI.Resources Methods (==) :: TextCompletionCreate -> TextCompletionCreate -> Bool # (/=) :: TextCompletionCreate -> TextCompletionCreate -> Bool # | |
| Show TextCompletionCreate | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> TextCompletionCreate -> ShowS # show :: TextCompletionCreate -> String # showList :: [TextCompletionCreate] -> ShowS # | |
| ToJSON TextCompletionCreate | |
Defined in OpenAI.Resources Methods toJSON :: TextCompletionCreate -> Value # toEncoding :: TextCompletionCreate -> Encoding # toJSONList :: [TextCompletionCreate] -> Value # toEncodingList :: [TextCompletionCreate] -> Encoding # | |
| FromJSON TextCompletionCreate | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser TextCompletionCreate # parseJSONList :: Value -> Parser [TextCompletionCreate] # | |
defaultTextCompletionCreate :: Text -> TextCompletionCreate #
Applies API defaults, only passing a prompt.
completeText :: OpenAIClient -> EngineId -> TextCompletionCreate -> IO (Either ClientError TextCompletion) Source #
Searching
data SearchResult #
Constructors
| SearchResult | |
Fields
| |
Instances
| Eq SearchResult | |
Defined in OpenAI.Resources | |
| Show SearchResult | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> SearchResult -> ShowS # show :: SearchResult -> String # showList :: [SearchResult] -> ShowS # | |
| ToJSON SearchResult | |
Defined in OpenAI.Resources Methods toJSON :: SearchResult -> Value # toEncoding :: SearchResult -> Encoding # toJSONList :: [SearchResult] -> Value # toEncodingList :: [SearchResult] -> Encoding # | |
| FromJSON SearchResult | |
Defined in OpenAI.Resources | |
data SearchResultCreate #
Constructors
| SearchResultCreate | |
Fields
| |
Instances
| Eq SearchResultCreate | |
Defined in OpenAI.Resources Methods (==) :: SearchResultCreate -> SearchResultCreate -> Bool # (/=) :: SearchResultCreate -> SearchResultCreate -> Bool # | |
| Show SearchResultCreate | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> SearchResultCreate -> ShowS # show :: SearchResultCreate -> String # showList :: [SearchResultCreate] -> ShowS # | |
| ToJSON SearchResultCreate | |
Defined in OpenAI.Resources Methods toJSON :: SearchResultCreate -> Value # toEncoding :: SearchResultCreate -> Encoding # toJSONList :: [SearchResultCreate] -> Value # toEncodingList :: [SearchResultCreate] -> Encoding # | |
| FromJSON SearchResultCreate | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser SearchResultCreate # parseJSONList :: Value -> Parser [SearchResultCreate] # | |
searchDocuments :: OpenAIClient -> EngineId -> SearchResultCreate -> IO (Either ClientError (OpenAIList SearchResult)) Source #