chatcraft.org icon indicating copy to clipboard operation
chatcraft.org copied to clipboard

replace functions in messages, not just detect em, add special function call message type

Open tarasglek opened this issue 1 year ago • 1 comments

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

  1. Once we invoke the function we show the following UI: image 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

tarasglek avatar Aug 12 '23 03:08 tarasglek

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:

  1. 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
  2. Find the function name for the given url (it will be the function object's id)
  3. 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)

humphd avatar Aug 12 '23 15:08 humphd