summaryrefslogtreecommitdiff
path: root/Omni/Agent/Provider.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-13 00:35:24 -0500
committerBen Sima <ben@bensima.com>2025-12-13 00:35:24 -0500
commit4ff40843e7a6801b7785bfff7f4e9e8fff4e27d4 (patch)
tree6b41438d0726f96746697af0584ab2f2542ffabf /Omni/Agent/Provider.hs
parent817bdb1f33e9825946a2da2aa1ff8f91b6166366 (diff)
telegram: fix parsing, add webpage reader, use gemini
- Fix Provider.hs to strip leading whitespace from OpenRouter responses - Fix FunctionCall parser to handle missing 'arguments' field - Use eitherDecode for better error messages on parse failures - Switch to claude-sonnet-4.5 for main agent - Use gemini-2.0-flash for conversation summarization (cheaper) - Add read_webpage tool for fetching and summarizing URLs - Add tagsoup to Haskell deps (unused, kept for future)
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