approximatelabs / sketch

AI code-writing assistant that understands data content
MIT License
2.23k stars 117 forks source link

Question : What is the use of to_b64() and from_b64() ? Why are they used? #19

Closed yzaparto closed 1 year ago

bluecoconut commented 1 year ago

to_b64 is "to base64", from_b64 is "from base64"

These, are helper utilities to convert a python dictionary object (well, anything that can be json.dumps) into a serialized string without special characters.

They are used to wrap the inputs to the "prompt" (lambdaprompt definition of prompt) that takes in a few inputs and provides completion.

See these lines for the prompt_kwargs creation https://github.com/approximatelabs/sketch/blob/b4d5f257e1d9d0da423562f0d80ac343624b7ede/sketch/pandas_extension.py#L152

This is now immediately usable by the requests lib, when calling a prompt remotely

response = requests.get(
    f"{url}/prompt/{prompt.name}",
    params=prompt_kwargs,
)

Because the fields in prompt_kwargs are processed to be strings using the to_b64 function, they now are able to be passed as params to the prompt completion endpoint without any messy serialization.

In summary: the point is to serialize and deserialize the information that is used by the prompt into a format that makes it possible to send over requests so that the prompt can be completed by the remote lambdaprompt server (when SKETCH_USE_REMOTE_LAMBDAPROMPT==True)