Skip to content

Commit

Permalink
Merge pull request #34 from agrafix/nhs/rename-responseformat
Browse files Browse the repository at this point in the history
Rename ResponseFormat to ChatResponseFormat
  • Loading branch information
nickhs authored Jul 13, 2024
2 parents 85dea7b + e55628b commit 7048304
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openai-hs/src/OpenAI/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module OpenAI.Client
ChatCompletionRequest (..),
ChatChoice (..),
ChatResponse (..),
ResponseFormat(..),
ChatResponseFormat(..),
defaultChatCompletionRequest,
completeChat,

Expand Down
14 changes: 7 additions & 7 deletions openai-servant/src/OpenAI/Resources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module OpenAI.Resources
ChatCompletionRequest (..),
ChatChoice (..),
ChatResponse (..),
ResponseFormat(..),
ChatResponseFormat(..),
defaultChatCompletionRequest,

-- * Edits
Expand Down Expand Up @@ -309,33 +309,33 @@ data ChatCompletionRequest = ChatCompletionRequest
chcrStop :: Maybe (V.Vector T.Text),
chcrMaxTokens :: Maybe Int,
chcrPresencePenalty :: Maybe Double,
chcrResponseFormat :: Maybe ResponseFormat,
chcrResponseFormat :: Maybe ChatResponseFormat,
chcrFrequencyPenalty :: Maybe Double,
chcrLogitBias :: Maybe (V.Vector Double),
chcrUser :: Maybe String
}
deriving (Show, Eq)

data ResponseFormat
data ChatResponseFormat
= RF_text
| RF_json_object
deriving (Show, Eq)

instance ToJSON ResponseFormat where
instance ToJSON ChatResponseFormat where
toJSON = \case
RF_text -> A.object [ "type" A..= A.String "text" ]
RF_json_object -> A.object [ "type" A..= A.String "json_object" ]

instance FromJSON ResponseFormat where
parseJSON = A.withObject "ResponseFormat" $ \o -> do
instance FromJSON ChatResponseFormat where
parseJSON = A.withObject "ChatResponseFormat" $ \o -> do
rt <- o A..: "type"
case rt of
"text"
-> pure RF_text
"json_object"
-> pure RF_json_object
xs
-> fail $ "ResponseFormat unexpected type: " <> T.unpack xs
-> fail $ "ChatResponseFormat unexpected type: " <> T.unpack xs

defaultChatCompletionRequest :: ModelId -> [ChatMessage] -> ChatCompletionRequest
defaultChatCompletionRequest model messages =
Expand Down

0 comments on commit 7048304

Please sign in to comment.