https://www.boundaryml.com logo
BAML with an existing project
# general
i
I want to use BAML on an existing project. But it won't work unless my "main" file is inside baml_src. Is it possible to export the result of BAML functions somehow so I can have my own separate src directory?
b
Hmm- BAML certainly isn't designed to require that.
By default all generated clients go into a
baml_client
whose location is controlled by the corresponding generator
Copy code
generator target {
    output_type "python/pydantic"

    // Where the generated code will be saved (relative to baml_src/)
    output_dir "../"
}
And then you can use that
baml_client
however you want
What are you seeing?
i
hmm, could i try the opposite and move all the files/nested directories inside baml_src?
The error looks like this:
Copy code
@MacBook-Air BAML % deno task test test/prompting.test.ts
Task test deno test --env=.env --allow-net --allow-read --allow-write --allow-env "test/prompting.test.ts"
Check file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/test/prompting.test.ts
TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/async_client'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/index.ts:44:19

TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/types'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/index.ts:46:15

TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/partial_types'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/index.ts:47:36

TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/tracing'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/index.ts:48:15

TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/events'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/index.ts:49:25

TS2307 [ERROR]: Cannot find module 'file:///Users/Documents/GitHub/proyecto-itera/sandbox/BAML/baml_client/globals'. Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///Users/Documents/GitHub/proyecto-
b
> could i try the opposite and move all the files/nested directories inside baml_src? Can you describe your project layout and what you want?
i
this is the layout:
Copy code
.
├── baml_client
├── baml_src
│   ├── PromptElaboration.baml
│   ├── clients.baml
│   ├── generators.baml
│   ├── main.ts
│   └── resume.baml
├── deno.json
├── deno.lock
├── edit.md
├── main.ts
├── node_modules
├── obsidian-itera-baml
│   ├── test.md
│   ├── the-digital-lighthouse.md
│   ├── the-garden-of-functions.md
│   └── the-last-commit.md
├── src
│   ├── routes
│   ├── third-party
│   └── utils
└── test
    └── prompting.test.ts
b
You can do something like
output_dir ../src/
to put
baml_client
in
src/
- or is there something different you're asking for?
i
oh let me try
not that would work
Okay. Yeah that worked. A little gotcha for deno - I ran the test task like this:
"test": "deno test --env=.env --unstable-sloppy-imports --allow-ffi --allow-net --allow-read --allow-write --allow-env",
--- For future reference, what I did was: 1.
baml_src
>
generators.baml
>
output_dir "../src/"
2.
deno task baml-generate
3. Import
b
at my file
prompting.test.ts
like this
import { b } from "../src/baml_client/index.ts";
(b has autocomplete - nice) 4. Ran
deno task test test/prompting.test.ts
That worked! Thank you again