Find answers from the community

Updated last year

Few shot

Since functions are apparently prompts now, if this is useful to anyone, just made a cheeky wee few_shot decorator that allows you to define examples which get injected into your function's docstring: https://github.com/SlapDrone/few-shot

pip install few-shot

feedback/contribs welcome. tested it a bit with marvin. next: adapt to work with the likes of OpenAIPydanticProgram.
L
S
οΏ½
13 comments
Super cool! I wonder if this could work with our agent tool spec stuff too πŸ€”
Yeah, was thinking about that too! Can try sketching something out.😁
Nice one was actually thinking how to do few shot with function api yesterday
Was looking at this the other evening and came across this thread here:

https://community.openai.com/t/few-shot-and-function-calling/265908/15

basically, for doing few-shot with function-calling examples, we spoof prior prompt -> function call pairs in the chat history. doesn't seem too bad
what's clear though is that we'd need to write an abstraction layer for the few-shot decorator. the current implementation is just the "function docstring is a prompt, your examples go in prompt"
so basically, if we wrap an OpenAIPydanticProgram object, the __call__ implementation routes to a new piece of logic, that instead of modifying a function docstring, modifies the initial chat history that goes in to the openAI call
this is all kinda fine because the whole "implicit" function that's just generating something that fits the description/examples is very much a fire-and-forget operation that has no state, i.e. you can afford to just pad the chat history with a few examples that will make the chance that you get a good answer higher
a bit harder when thinking about the tool spec, since function tool calls happen in the middle of a conversation where prior context is important, and they can chain into each other
so maybe putting the examples in the function description is actually better/less messy for that use-case. but that feels a bit janky for some reason.
I think putting examples in the docstring makes sense!

We actually do that for some of the tools on llama-hub actually πŸ‘€
cool, know which ones off the top of your head? will take a look how it's formatted etc
For the first two I think the standard decorator should work as is. although interestingly, neither provide the outputs. Which means I should probably update the package to support input-only examples, right now it really expects input/output pairs πŸ˜„
Add a reply
Sign up and join the conversation on Discord