summaryrefslogtreecommitdiff
path: root/Omni/Agent/Provider.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent/Provider.hs')
-rw-r--r--Omni/Agent/Provider.hs14
1 files changed, 9 insertions, 5 deletions
diff --git a/Omni/Agent/Provider.hs b/Omni/Agent/Provider.hs
index a8a5381..2ad6ea8 100644
--- a/Omni/Agent/Provider.hs
+++ b/Omni/Agent/Provider.hs
@@ -200,7 +200,7 @@ instance Aeson.FromJSON FunctionCall where
parseJSON =
Aeson.withObject "FunctionCall" <| \v ->
(FunctionCall </ (v Aeson..: "name"))
- <*> (v Aeson..: "arguments")
+ <*> (v Aeson..:? "arguments" Aeson..!= "{}")
data Usage = Usage
{ usagePromptTokens :: Int,
@@ -322,14 +322,18 @@ chatOpenAI cfg tools messages = do
response <- HTTP.httpLBS req
let status = HTTP.getResponseStatusCode response
+ respBody = HTTP.getResponseBody response
+ cleanedBody = BL.dropWhile (\b -> b `elem` [0x0a, 0x0d, 0x20]) respBody
if status >= 200 && status < 300
- then case Aeson.decode (HTTP.getResponseBody response) of
- Just resp ->
+ then case Aeson.eitherDecode cleanedBody of
+ Right resp ->
case respChoices resp of
(c : _) -> pure (Right (ChatResult (choiceMessage c) (respUsage resp)))
[] -> pure (Left "No choices in response")
- Nothing -> pure (Left "Failed to parse response")
- else pure (Left ("HTTP error: " <> tshow status <> " - " <> TE.decodeUtf8 (BL.toStrict (HTTP.getResponseBody response))))
+ Left err -> do
+ let bodyPreview = TE.decodeUtf8 (BL.toStrict (BL.take 500 cleanedBody))
+ pure (Left ("Failed to parse response: " <> Text.pack err <> " | Body: " <> bodyPreview))
+ else pure (Left ("HTTP error: " <> tshow status <> " - " <> TE.decodeUtf8 (BL.toStrict respBody)))
chatOllama :: ProviderConfig -> [ToolApi] -> [Message] -> IO (Either Text ChatResult)
chatOllama cfg tools messages = do