Skip to content

Commit

Permalink
Remove deprected edits API
Browse files Browse the repository at this point in the history
You should use the chat completions API instead according to OpenAI
https://platform.openai.com/docs/deprecations/edit-models-endpoint
  • Loading branch information
nickhs committed Mar 23, 2024
1 parent b534c50 commit aaacff0
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 73 deletions.
10 changes: 0 additions & 10 deletions openai-hs/src/OpenAI/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ module OpenAI.Client
defaultChatCompletionRequest,
completeChat,

-- * Edits
EditCreate (..),
EditChoice (..),
EditResponse (..),
createTextEdit,
defaultEditCreate,

-- * Images
ImageResponse (..),
ImageResponseData (..),
Expand Down Expand Up @@ -183,8 +176,6 @@ EP1 (completeText, CompletionCreate, CompletionResponse)

EP1 (completeChat, ChatCompletionRequest, ChatResponse)

EP1 (createTextEdit, EditCreate, EditResponse)

EP1 (generateImage, ImageCreate, ImageResponse)
EP1 (createImageEdit, ImageEditRequest, ImageResponse)
EP1 (createImageVariation, ImageVariationRequest, ImageResponse)
Expand Down Expand Up @@ -231,7 +222,6 @@ EP2 (engineCreateEmbedding, EngineId, EngineEmbeddingCreate, (OpenAIList EngineE
)
:<|> (completeText')
:<|> (completeChat')
:<|> (createTextEdit')
:<|> ( generateImage'
:<|> createImageEdit'
:<|> createImageVariation'
Expand Down
10 changes: 0 additions & 10 deletions openai-hs/test/ApiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ apiTests2023 =
res <- forceSuccess $ completeChat cli completion
chrChoices res `shouldNotBe` []

describe "edits api" $ do
it "create edit" $ \cli -> do
let edit =
(defaultEditCreate (ModelId "text-davinci-edit-001") "Fox" "Pluralize the word")
{ edcrN = Just 1
}
res <- forceSuccess $ createTextEdit cli edit
edrChoices res `shouldNotBe` []
edchText (head $ edrChoices res) `shouldBe` "Foxes\n"

-- TODO (2023.03.22): Create tests for images, audio APIs

describe "embeddings api" $ do
Expand Down
4 changes: 0 additions & 4 deletions openai-servant/src/OpenAI/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type OpenAIApiInternal =
"models" :> ModelsApi
:<|> "completions" :> CompletionsApi
:<|> "chat" :> ChatApi
:<|> "edits" :> EditsApi
:<|> "images" :> ImagesApi
:<|> "embeddings" :> EmbeddingsApi
:<|> "audio" :> AudioApi
Expand All @@ -34,9 +33,6 @@ type CompletionsApi =
type ChatApi =
OpenAIAuth :> "completions" :> ReqBody '[JSON] ChatCompletionRequest :> Post '[JSON] ChatResponse

type EditsApi =
OpenAIAuth :> ReqBody '[JSON] EditCreate :> Post '[JSON] EditResponse

type ImagesApi =
OpenAIAuth :> "generations" :> ReqBody '[JSON] ImageCreate :> Post '[JSON] ImageResponse
:<|> OpenAIAuth :> "edits" :> ReqBody '[JSON] ImageEditRequest :> Post '[JSON] ImageResponse
Expand Down
49 changes: 0 additions & 49 deletions openai-servant/src/OpenAI/Resources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ module OpenAI.Resources
ChatResponse (..),
defaultChatCompletionRequest,

-- * Edits
EditCreate (..),
EditChoice (..),
EditResponse (..),
defaultEditCreate,

-- * Images
ImageResponse (..),
ImageResponseData (..),
Expand Down Expand Up @@ -359,49 +353,6 @@ $(deriveJSON (jsonOpts 4) ''ChatCompletionRequest)
$(deriveJSON (jsonOpts 4) ''ChatChoice)
$(deriveJSON (jsonOpts 3) ''ChatResponse)

------------------------
------ Edits API
------------------------

data EditCreate = EditCreate
{ edcrModel :: ModelId,
edcrInput :: Maybe T.Text,
edcrInstruction :: T.Text,
edcrN :: Maybe Int,
edcrTemperature :: Maybe Double,
edcrTopP :: Maybe Double
}
deriving (Show, Eq)

defaultEditCreate :: ModelId -> T.Text -> T.Text -> EditCreate
defaultEditCreate model input instruction =
EditCreate
{ edcrModel = model,
edcrInput = Just input,
edcrInstruction = instruction,
edcrN = Nothing,
edcrTemperature = Nothing,
edcrTopP = Nothing
}

data EditChoice = EditChoice
{ edchText :: T.Text,
edchIndex :: Int
}
deriving (Show, Eq)

data EditResponse = EditResponse
{ edrObject :: T.Text,
edrCreated :: Int,
edrChoices :: [EditChoice],
edrUsage :: Usage
}
deriving (Show, Eq)

$(deriveJSON (jsonOpts 4) ''EditCreate)
$(deriveJSON (jsonOpts 4) ''EditChoice)
$(deriveJSON (jsonOpts 3) ''EditResponse)

------------------------
------ Images API
------------------------
Expand Down

0 comments on commit aaacff0

Please sign in to comment.