https://www.boundaryml.com logo
BAML extraction test (FastAPI) - Typebuilder synta...
# help
g
Following along with documentation and existing code to try out BAML generation based on custom documents/strings. I have a working FastAPI instance now. BAML generation and execution works on the Playground as expected. Went ahead and tested the extraction and generation POST requests on the Docs page - Generation works, but for some reason extraction does not. Any pointers?
Copy code
py
...
async def exec_baml(
    stream: bool,
    file: UploadFile = File(None),
    content: str = Form(None),
    url: str = Form(None),
    baml_code: str = Form(...),
    return_type: str = Form(...)
):
    final_content = await read_content(file, content, url)
    tb = TypeBuilder()
    try:
        tb.add_baml(f"""
        {baml_code}

        dynamic class Response {{
            data {return_type}
        }}
        """)
    except BamlError as e:
        raise HTTPException(status_code=400, detail={
            "error": "BamlError",
            "message": str(e),
        })
    if stream:
        stream = b.stream.ExecuteBAML(final_content, { "tb": tb })
        return handle_stream(stream, lambda x: x.data)
    else:
        response = await b.ExecuteBAML(final_content, { "tb": tb })
        return response.data
...
https://cdn.discordapp.com/attachments/1449701403693023293/1449701404406059018/image.png?ex=693fdb24&is=693e89a4&hm=c3ae1e6c8404533a6bf38197615153f2a09c79cee24a29aa5b615062ccd9efa4&
Also adding to this - PDFs did not work with generation, but strings do. Haven't tested URLs yet. " raise PDFInfoNotInstalledError( "Unable to get page count. Is poppler installed and in PATH?" ) pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?"
a
Hey @GR™, the problem with your screenshot (Syntax Error in type builder) happens because you set
baml_code=string
and then you call tb.add_baml with
string
. You end up with something like this:
Copy code
string

dynamic class Response {
    data string
}
And that's invalid syntax. You have to either skip the {baml_code} part if it''s just a type, or make it a class. One of these:
Copy code
dynamic class Response {
    data string
}
Or
Copy code
class WantThisData {
    name string
    skills string[]
}

dynamic class Response {
    data WantThisData
}
In the second case
baml_code
has to be the entire class definition and
return_type
has to be the class name.
Your second problem with the PDF seems like a missing package, not sure if that's a Baml dependency and somehow didn't get installed, I'll check tomorrow on my computer
I think you have to install [
poppler
](https://pypi.org/project/python-poppler/) to make it work.
g
Tried poppler, didn't work
Might help with further troubleshooting
a
python-poppler
I think that's what's missing
a
The example I'll take a look tomorrow
Do the
--frozen
thing it suggests
a
It's missing pkg-config and some other stuff
Copy code
bash
sudo apt update
sudo apt install -y \
  pkg-config \
  cmake \
  libpoppler-cpp-dev \
  build-essential
g
Build worked, but the same PDF2Image error pops up when I run a test gen_call
a
Try removing the .venv and doing the setup again installing all deps
g
Same error
Honestly sounds like I should research other dep combinations for processing PDFs into a BAML supported string
a
Wait what are you trying to do with pdfs
Baml does have a
pdf
type
g
The example processes a PDF/Image/Text String to generate BAML schema and then extract data in said BAML schema
At least that's what I understood from the description
a
Yeah the example was written before we added the
pdf
type I think
Seems complicated to run due to
pdf2image
I'll take a look see if I can port it to native
pdf
type
g
Any luck with this?
a
Sorry, I haven't tried yet, I'll do tomorrow (on Fridays we fix bugs/docs etc for next release)
Check the example again and see how it goes
g
Hey there - Sorry about the giant delay. Job change and move had me pre-occupied. I've restarted learning BAML.
I'm looking at the new folder structure, and have some questions about it
Running list of questions: 1. Why is baml-src outside backend? And what's the expected pathway to setting up
baml-cli init
? 2. What steps do you normally follow for updating projects that call an old BAML project version with newest VSCode extension? Feel like changing pyproject.toml and manually editing version on every generators file in the project would get old fast.
Confirmed fix
Sorry about that, accidental double ping.
Checking in once more. I know this ticket is old, just figured I'd try reaching out in case this was missed
a
There's no restriction on where
baml-src
can be, could be outside backend if you're sharing Baml types between frontend and backend, or you wanna generate those types for the frontend as well. In this particular example of
extract-anything
I don't think there's a reason it needs to be outside of
backend
. Steps to update, yes you have to manually update pyproject and generator, the extension only downloads the correct LSP version for you but it doesn't auto update generators and pyproject versions
g
Just spotted this for some reason - No idea why Discord didn't notify as unread by default. Noted on all counts. I think all that needs answering at this point is the PII question from earlier.
a
What's the PII question?
g
^ this one
a
Yes I think that's OpenAI filter. I am not sure if there are options to bypass that one