Skip to content

Commit

Permalink
Temporary workaround for ChatObject not supporting multimodal content
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Nov 22, 2023
1 parent 8ef401c commit c3462d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ constructChatObject // beginDefinition;

(* cSpell: ignore bdprompt *)
constructChatObject[ messages_List ] :=
With[ { chat = Quiet[ chatObject @ standardizeMessageKeys @ messages, ChatObject::bdprompt ] },
With[ { chat = Quiet[ chatObject @ checkMultimodal @ standardizeMessageKeys @ messages, ChatObject::bdprompt ] },
chat /; MatchQ[ chat, _chatObject ]
];

Expand All @@ -648,6 +648,32 @@ constructChatObject // endDefinition;

chatObject := chatObject = Symbol[ "System`ChatObject" ];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*checkMultimodal*)
(* TODO: this is temporary until ChatObject supports multimodal content: *)
checkMultimodal // beginDefinition;
checkMultimodal[ messages_ ] := checkMultimodal[ messages, multimodalPacletsAvailable[ ] ];
checkMultimodal[ messages_, False ] := revertMultimodalContent @ messages;
checkMultimodal[ messages_, True ] := messages;
checkMultimodal // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*revertMultimodalContent*)
revertMultimodalContent // beginDefinition;

revertMultimodalContent[ messages_List ] :=
revertMultimodalContent /@ messages;

revertMultimodalContent[ as: KeyValuePattern[ "Content" -> content_List ] ] :=
<| as, "Content" -> StringJoin @ Select[ content, StringQ ] |>;

revertMultimodalContent[ as: KeyValuePattern[ "Content" -> _String ] ] :=
as;

revertMultimodalContent // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*standardizeMessageKeys*)
Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BeginPackage[ "Wolfram`Chatbook`SendChat`" ];

`$debugLog;
`makeOutputDingbat;
`multimodalPacletsAvailable;
`sendChat;
`toImageURI;
`toolsEnabledQ;
Expand Down

0 comments on commit c3462d7

Please sign in to comment.