chatcraft.org
chatcraft.org copied to clipboard
replace functions in messages, not just detect em, add special function call message type
We currently scan messages for @fn-url:..
to identify function calls...
We should replace the url with function name when we serialize msgs to send to openai. It's not at all helpful to the model to see those urls, and it costs us tokens
- Once we invoke the function we show the following UI:
This has a few problems:
a) we send this message back to openai, which we shouldn't. it's only helpful to user
b) the message doesn't have a special icon, which lets gpt impersonate function calls as described here
Adding some notes for anyone interested in doing this work.
Fixing this would require modifications to https://github.com/tarasglek/chatcraft.org/blob/bb69c02a989246e0a4922f6666af5090b8137723/src/lib/ai.ts#L175-L186
We receive a list of messages
and possibly functions
. When we get functions
, we'd have to:
- Loop over all
message.text
and look for@fn-url
. There is already code to do this https://github.com/tarasglek/chatcraft.org/blob/bb69c02a989246e0a4922f6666af5090b8137723/src/lib/ChatCraftFunction.ts#L25-L57 - Find the function
name
for the givenurl
(it will be the function object'sid
) - Replace the
@fn-url: <url>
with the function's name in the content we send to the LLM (i.e., don't modify the original message content and lose the@fn-url: <url>
syntax)