https://www.boundaryml.com logo
[context]
# suggestions
a
[context] My team is preparing a large-scale Q&A dataset (40M+ examples) for a custom LLM finetune. The 'Q' (question) part is the chat prompt. The 'A' (answer) part simulates a generated assistant message – 'simulates' because we can generate the message content deterministically from a template using known output values. Many of the question types in our Q&A dataset correspond to identical inference requests in production, where BAML gives us a nice efficiency boost. The same BAML chat prompt function used for inference in production can be used to generate the 'Q' part of training examples. We can't use BAML to template the the response part, though. For that we have to write separate Jinja templates. It feels slightly awkward mixing BAML and Jinja all over the place. A smart engineer wouldn't exactly be wrong to ask, 'Why not just do everything in Jinja and drop BAML?' I feel that if we could template both the prompt and the response in BAML, I'd be more confident about defending the choice for BAML. I've been thinking about what this might look like. Below are BAML and Python snippets that build on the resume parser example. The BAML snippet treats the response as a template string and connects it to the chat prompt function through a new attribute,
response_template
. The Python snippet demonstrates a 'builder' type API interaction to build the chat example. Further down, I've got another BAML snippet showing another syntax for linking the response template to the chat prompt function: using a Rust macro-like annotation. This represents a bigger syntactic change, though, so it's probably not worth the extra effort
v
This is actually possible today! You can use our modular api to get the training prompt out! https://docs.boundaryml.com/guide/baml-advanced/modular-api the idea is exactly as you stated. Even better you can use a different prompt for inference and yet a different one for training!
If it doesn’t seem direct how you would that, let me know and I’ll drop in a code snippet later in the day! (On mobile atm)
a
Hm, I'm probably missing something then. I've been studying the modular API as it evolves. In fact, we use it in places to extract the chat prompt from the request. But the chat prompt is just one half of the problem. We also need to render the response. Training example = (chat prompt, chat response). Here's why I'm confused about the Modular API - A BAML function is a chat prompt template, an LLM call, and a response handler in one. Its return type is the type of the parsed output. - By contrast, a function that renders response content doesn't have an LLM client, and its output type should be a list of Messages. The closest thing to it is the
template_string
type, but afaik that can't be invoked directly via the Modular API – or can it? (This would be an acceptable solution, actually.) There are all sorts of interactions between building a request and simulating/handling the response. Even if we could do both with separate BAML functions, it'd be handy if BAML made the relationship between the two explicit. Another random idea: if it were possible to mock BAML clients from Python, then we could create a mock 'simulated response client' that generates responses for training examples. However, implementing such a client would again mean defining templates in a separate templating framework, e.g. jinja.
v
oh i kind of see what you're saying! I was assuming if you had a very specific response format then one could do something like this:
Copy code
function ExtractResumeResponse(thinking: string, result: Resume) -> string {
   client "..."
   prompt #"
     <do whatever here>
   "#
}
then you could use modular API via:
Copy code
b.request.ExtractResume(params)
b.request.ExtractResumeResponse(thinking, result)
albiet this is kinda a workaround and really we should just expose template strings somehow :/
cause when i write that code,
client "..."
does feel "wrong" to write there
esp since its a function i never expect to actually call
at least in the sense of traditional baml functions
a
precisely! it just feels kind of wrong
also, the return type of a response template can actually be more than a string. I'd like to be alternate the roles just like in a prompt
allowing for the response to be not just a single message, but a continued chat thread
v
Yea I think this is the workaround for now. But if we expose the prompt template, we could fix this problem That needs a bit more design work cause the we do template_string atm is that it’s more like an object that can be given to a client, which then converts it to another object. And while we do have an interface for this, it’s just not one we have designed for public usage yet πŸ˜…
a
Yeah, i figured as much
What are we thinking? =p
Copy code
template = b.template_strings.ExtractResumeResponse
template.render(**kwargs)
or
Copy code
b.render_template('ExtractResumeResponse', **kwargs)
Anyway, would be happy to help out
v
it'll probably just be:
Copy code
b.ExtractResumeResponse()
but ExtractResumeResume would be defined as such:
Copy code
template_string ExtractResumeResume(params...) #"
   ...
"#
but honestly need a bit more time to define what the definition of a
#".."#
is formally πŸ˜…
for example, we do some URL resolving in there because not every model accepts media types as urls and some require base64. would need to determine if
template_string
does that or not.
a
it's the template string that resolves those, not the client? but yeah, that deos complicate things
v
Yea it’s kind of a mixture of both. Sadly
Which is why the real thing we need to do is just sit and decide what the boundary is
The actually work is easy
But definition it turns out is hard 🀣
a
and throwing multimodality in the mix doesn't help
v
Yep exactly haha
I think what I would do for now is use the workaround
And then as yall experience it
Share the feedback and perhaps we can codesign it
a
I'll try the workaround and see how we get on. It at least addresses one of the desiderata, namely, staying in BAML
But I'd def still push for exposing the template strings
Which, by the way, I'd recommend namespacing under a
templates
attribute. The semantics are different, so it might end up confusing users otherwise
By the way, how does BAML make design decisions? Many of the issues on Github are just links to Linear, which kind of makes progress hard to follow
g
How we make design decisions - it depends. For a feature that we're working on internally, we meet and hash things out in person, collaborating on an internal Notion doc. For features that are driven by a particular user (like you!) we discuss on discord, and if the feature is complex, we make an externally visible Notion doc. Would that be useful to you?