| 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 EmbeddingCreate = EmbeddingCreate {}
- data Embedding = Embedding {
- eEmbedding :: Vector Double
- eIndex :: Int
- createEmbedding :: OpenAIClient -> EngineId -> EmbeddingCreate -> IO (Either ClientError (OpenAIList Embedding))
- newtype FineTuneId = FineTuneId {
- unFineTuneId :: Text
- data FineTuneCreate = FineTuneCreate {
- ftcTrainingFile :: FileId
- ftcValidationFile :: Maybe FileId
- ftcModel :: Maybe Text
- ftcBatchSize :: Maybe Int
- ftcNEpochs :: Maybe Text
- ftcLearningRateMultiplier :: Maybe Double
- ftcPromptLossWeight :: Maybe Double
- ftcComputeClassificationMetrics :: Maybe Bool
- ftcClassificationNClasses :: Maybe Int
- ftcClassificationPositiveClass :: Maybe Text
- defaultFineTuneCreate :: FileId -> FineTuneCreate
- data FineTune = FineTune {
- ftId :: FineTuneId
- ftModel :: Text
- ftCreatedAt :: Int
- ftEvents :: Vector FineTuneEvent
- ftTunedModel :: Maybe Text
- ftStatus :: Text
- data FineTuneEvent = FineTuneEvent {
- fteCreatedAt :: Int
- fteLevel :: Text
- fteMessage :: Text
- createFineTune :: OpenAIClient -> FineTuneCreate -> IO (Either ClientError FineTune)
- listFineTunes :: OpenAIClient -> IO (Either ClientError (OpenAIList FineTune))
- getFineTune :: OpenAIClient -> FineTuneId -> IO (Either ClientError FineTune)
- cancelFineTune :: OpenAIClient -> FineTuneId -> IO (Either ClientError FineTune)
- listFineTuneEvents :: OpenAIClient -> FineTuneId -> IO (Either ClientError (OpenAIList FineTuneEvent))
- data SearchResult = SearchResult {
- srDocument :: Int
- srScore :: Double
- srMetadata :: Maybe Text
- data SearchResultCreate = SearchResultCreate {}
- searchDocuments :: OpenAIClient -> EngineId -> SearchResultCreate -> IO (Either ClientError (OpenAIList SearchResult))
- data FileCreate = FileCreate {
- fcPurpose :: Text
- fcDocuments :: [FileHunk]
- data File = File {}
- newtype FileId = FileId {}
- data FileHunk
- data SearchHunk = SearchHunk {
- shText :: Text
- shMetadata :: Maybe Text
- data ClassificationHunk = ClassificationHunk {}
- data FineTuneHunk = FineTuneHunk {
- fthPrompt :: Text
- fthCompletion :: Text
- data FileDeleteConfirmation = FileDeleteConfirmation {}
- createFile :: OpenAIClient -> FileCreate -> IO (Either ClientError File)
- deleteFile :: OpenAIClient -> FileId -> IO (Either ClientError FileDeleteConfirmation)
- getAnswer :: OpenAIClient -> AnswerReq -> IO (Either ClientError AnswerResp)
- data AnswerReq = AnswerReq {
- arFile :: Maybe FileId
- arDocuments :: Maybe (Vector Text)
- arQuestion :: Text
- arSearchModel :: EngineId
- arModel :: EngineId
- arExamplesContext :: Text
- arExamples :: [[Text]]
- arReturnMetadata :: Bool
- data AnswerResp = AnswerResp {
- arsAnswers :: [Text]
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 #
Embeddings
data EmbeddingCreate #
Constructors
| EmbeddingCreate | |
Instances
| Eq EmbeddingCreate | |
Defined in OpenAI.Resources Methods (==) :: EmbeddingCreate -> EmbeddingCreate -> Bool # (/=) :: EmbeddingCreate -> EmbeddingCreate -> Bool # | |
| Show EmbeddingCreate | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> EmbeddingCreate -> ShowS # show :: EmbeddingCreate -> String # showList :: [EmbeddingCreate] -> ShowS # | |
| ToJSON EmbeddingCreate | |
Defined in OpenAI.Resources Methods toJSON :: EmbeddingCreate -> Value # toEncoding :: EmbeddingCreate -> Encoding # toJSONList :: [EmbeddingCreate] -> Value # toEncodingList :: [EmbeddingCreate] -> Encoding # | |
| FromJSON EmbeddingCreate | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser EmbeddingCreate # parseJSONList :: Value -> Parser [EmbeddingCreate] # | |
createEmbedding :: OpenAIClient -> EngineId -> EmbeddingCreate -> IO (Either ClientError (OpenAIList Embedding)) Source #
Fine tunes
newtype FineTuneId #
Constructors
| FineTuneId | |
Fields
| |
Instances
| Eq FineTuneId | |
Defined in OpenAI.Resources | |
| Show FineTuneId | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FineTuneId -> ShowS # show :: FineTuneId -> String # showList :: [FineTuneId] -> ShowS # | |
| ToJSON FineTuneId | |
Defined in OpenAI.Resources Methods toJSON :: FineTuneId -> Value # toEncoding :: FineTuneId -> Encoding # toJSONList :: [FineTuneId] -> Value # toEncodingList :: [FineTuneId] -> Encoding # | |
| FromJSON FineTuneId | |
Defined in OpenAI.Resources | |
| ToHttpApiData FineTuneId | |
Defined in OpenAI.Resources Methods toUrlPiece :: FineTuneId -> Text # toEncodedUrlPiece :: FineTuneId -> Builder # toHeader :: FineTuneId -> ByteString # toQueryParam :: FineTuneId -> Text # | |
data FineTuneCreate #
Constructors
Instances
| Eq FineTuneCreate | |
Defined in OpenAI.Resources Methods (==) :: FineTuneCreate -> FineTuneCreate -> Bool # (/=) :: FineTuneCreate -> FineTuneCreate -> Bool # | |
| Show FineTuneCreate | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FineTuneCreate -> ShowS # show :: FineTuneCreate -> String # showList :: [FineTuneCreate] -> ShowS # | |
| ToJSON FineTuneCreate | |
Defined in OpenAI.Resources Methods toJSON :: FineTuneCreate -> Value # toEncoding :: FineTuneCreate -> Encoding # toJSONList :: [FineTuneCreate] -> Value # toEncodingList :: [FineTuneCreate] -> Encoding # | |
| FromJSON FineTuneCreate | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser FineTuneCreate # parseJSONList :: Value -> Parser [FineTuneCreate] # | |
Constructors
| FineTune | |
Fields
| |
data FineTuneEvent #
Constructors
| FineTuneEvent | |
Fields
| |
Instances
| Eq FineTuneEvent | |
Defined in OpenAI.Resources Methods (==) :: FineTuneEvent -> FineTuneEvent -> Bool # (/=) :: FineTuneEvent -> FineTuneEvent -> Bool # | |
| Show FineTuneEvent | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FineTuneEvent -> ShowS # show :: FineTuneEvent -> String # showList :: [FineTuneEvent] -> ShowS # | |
| ToJSON FineTuneEvent | |
Defined in OpenAI.Resources Methods toJSON :: FineTuneEvent -> Value # toEncoding :: FineTuneEvent -> Encoding # toJSONList :: [FineTuneEvent] -> Value # toEncodingList :: [FineTuneEvent] -> Encoding # | |
| FromJSON FineTuneEvent | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser FineTuneEvent # parseJSONList :: Value -> Parser [FineTuneEvent] # | |
createFineTune :: OpenAIClient -> FineTuneCreate -> IO (Either ClientError FineTune) Source #
listFineTunes :: OpenAIClient -> IO (Either ClientError (OpenAIList FineTune)) Source #
getFineTune :: OpenAIClient -> FineTuneId -> IO (Either ClientError FineTune) Source #
cancelFineTune :: OpenAIClient -> FineTuneId -> IO (Either ClientError FineTune) Source #
listFineTuneEvents :: OpenAIClient -> FineTuneId -> IO (Either ClientError (OpenAIList FineTuneEvent)) 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 | |
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 #
File API
data FileCreate #
Constructors
| FileCreate | |
Fields
| |
Instances
| Eq FileCreate | |
Defined in OpenAI.Resources | |
| Show FileCreate | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FileCreate -> ShowS # show :: FileCreate -> String # showList :: [FileCreate] -> ShowS # | |
| ToMultipart Mem FileCreate | |
Defined in OpenAI.Resources Methods toMultipart :: FileCreate -> MultipartData Mem # | |
Instances
| Eq FileId | |
| Show FileId | |
| ToJSON FileId | |
Defined in OpenAI.Resources | |
| FromJSON FileId | |
| ToHttpApiData FileId | |
Defined in OpenAI.Resources Methods toUrlPiece :: FileId -> Text # toEncodedUrlPiece :: FileId -> Builder # toHeader :: FileId -> ByteString # toQueryParam :: FileId -> Text # | |
data SearchHunk #
Constructors
| SearchHunk | |
Fields
| |
Instances
| Eq SearchHunk | |
Defined in OpenAI.Resources | |
| Show SearchHunk | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> SearchHunk -> ShowS # show :: SearchHunk -> String # showList :: [SearchHunk] -> ShowS # | |
| ToJSON SearchHunk | |
Defined in OpenAI.Resources Methods toJSON :: SearchHunk -> Value # toEncoding :: SearchHunk -> Encoding # toJSONList :: [SearchHunk] -> Value # toEncodingList :: [SearchHunk] -> Encoding # | |
| FromJSON SearchHunk | |
Defined in OpenAI.Resources | |
data ClassificationHunk #
Constructors
| ClassificationHunk | |
Instances
| Eq ClassificationHunk | |
Defined in OpenAI.Resources Methods (==) :: ClassificationHunk -> ClassificationHunk -> Bool # (/=) :: ClassificationHunk -> ClassificationHunk -> Bool # | |
| Show ClassificationHunk | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> ClassificationHunk -> ShowS # show :: ClassificationHunk -> String # showList :: [ClassificationHunk] -> ShowS # | |
| ToJSON ClassificationHunk | |
Defined in OpenAI.Resources Methods toJSON :: ClassificationHunk -> Value # toEncoding :: ClassificationHunk -> Encoding # toJSONList :: [ClassificationHunk] -> Value # toEncodingList :: [ClassificationHunk] -> Encoding # | |
| FromJSON ClassificationHunk | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser ClassificationHunk # parseJSONList :: Value -> Parser [ClassificationHunk] # | |
data FineTuneHunk #
Constructors
| FineTuneHunk | |
Fields
| |
Instances
| Eq FineTuneHunk | |
Defined in OpenAI.Resources | |
| Show FineTuneHunk | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FineTuneHunk -> ShowS # show :: FineTuneHunk -> String # showList :: [FineTuneHunk] -> ShowS # | |
| ToJSON FineTuneHunk | |
Defined in OpenAI.Resources Methods toJSON :: FineTuneHunk -> Value # toEncoding :: FineTuneHunk -> Encoding # toJSONList :: [FineTuneHunk] -> Value # toEncodingList :: [FineTuneHunk] -> Encoding # | |
| FromJSON FineTuneHunk | |
Defined in OpenAI.Resources | |
data FileDeleteConfirmation #
Constructors
| FileDeleteConfirmation | |
Instances
| Eq FileDeleteConfirmation | |
Defined in OpenAI.Resources Methods (==) :: FileDeleteConfirmation -> FileDeleteConfirmation -> Bool # (/=) :: FileDeleteConfirmation -> FileDeleteConfirmation -> Bool # | |
| Show FileDeleteConfirmation | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> FileDeleteConfirmation -> ShowS # show :: FileDeleteConfirmation -> String # showList :: [FileDeleteConfirmation] -> ShowS # | |
| ToJSON FileDeleteConfirmation | |
Defined in OpenAI.Resources Methods toJSON :: FileDeleteConfirmation -> Value # toEncoding :: FileDeleteConfirmation -> Encoding # toJSONList :: [FileDeleteConfirmation] -> Value # | |
| FromJSON FileDeleteConfirmation | |
Defined in OpenAI.Resources Methods parseJSON :: Value -> Parser FileDeleteConfirmation # parseJSONList :: Value -> Parser [FileDeleteConfirmation] # | |
createFile :: OpenAIClient -> FileCreate -> IO (Either ClientError File) Source #
deleteFile :: OpenAIClient -> FileId -> IO (Either ClientError FileDeleteConfirmation) Source #
Answer API
getAnswer :: OpenAIClient -> AnswerReq -> IO (Either ClientError AnswerResp) Source #
Constructors
| AnswerReq | |
Fields
| |
data AnswerResp #
Constructors
| AnswerResp | |
Fields
| |
Instances
| Eq AnswerResp | |
Defined in OpenAI.Resources | |
| Show AnswerResp | |
Defined in OpenAI.Resources Methods showsPrec :: Int -> AnswerResp -> ShowS # show :: AnswerResp -> String # showList :: [AnswerResp] -> ShowS # | |
| ToJSON AnswerResp | |
Defined in OpenAI.Resources Methods toJSON :: AnswerResp -> Value # toEncoding :: AnswerResp -> Encoding # toJSONList :: [AnswerResp] -> Value # toEncodingList :: [AnswerResp] -> Encoding # | |
| FromJSON AnswerResp | |
Defined in OpenAI.Resources | |