@@ -70,9 +70,18 @@ you can get a client library for free.
70
70
</Tab >
71
71
72
72
<Tab title = " Windows" >
73
- To install ` npx ` , use the [ Node.js installer] ( https://nodejs.org/en/download/prebuilt-installer ) .
73
+ To install ` npx ` and ` java ` :
74
+
75
+ 1 . Use the [ Node.js installer] ( https://nodejs.org/en/download/prebuilt-installer ) to install ` npx ` (default installer settings are fine).
76
+ 2. Run ` npm install -g npm@latest ` to update ` npx ` (there is currently an [ issue] [ npx-windows-issue ] with the default install of ` npx ` on Windows where it doesn't work out of the box).
77
+ 3. Run the [ Adoptium OpenJDK ` .msi ` installer] ( https://adoptium.net/temurin/releases/?os=windows ) (install the JDK; default installer settings are fine).
74
78
75
- To install ` java ` , use the [ Adoptium OpenJDK ` .msi ` installer] ( https://adoptium.net/temurin/releases/?os=windows ) .
79
+ You can verify that ` npx ` and ` java ` are installed by running:
80
+
81
+ ``` powershell
82
+ npx -version
83
+ java -version
84
+ ```
76
85
</Tab >
77
86
78
87
<Tab title = " Other" >
@@ -89,10 +98,17 @@ you can get a client library for free.
89
98
on your needs, we can also provide a static binary for using BAML.
90
99
</Note >
91
100
92
-
101
+ [ npx-windows-issue ] : https://github.com/nodejs/node/issues/53538
102
+
93
103
### Create a new BAML project
94
104
95
- This will give you some starter BAML code in a ` baml_src ` directory.
105
+ This will give you some starter BAML code in a ` baml_src ` directory, and also
106
+ set up ` generator.baml ` based on ` --openapi-client-type ` , so that BAML will:
107
+
108
+ - compile your BAML functions into an OpenAPI specification, and
109
+ - configure ` on_generate ` to generate an OpenAPI client in the language of your choosing
110
+
111
+ <p ></p >
96
112
97
113
<Tabs >
98
114
@@ -122,10 +138,23 @@ you can get a client library for free.
122
138
</Tab >
123
139
124
140
<Tab title = " Java" >
141
+
125
142
``` bash
126
143
npx @boundaryml/baml init \
127
144
--client-type rest/openapi --openapi-client-type java
128
145
```
146
+
147
+ Notice that ` on_generate ` has been initialized for you to:
148
+
149
+ - run the OpenAPI generator to generate a Java client library, and _ also_
150
+ - run ` mvn clean install ` to install the generated client library to your
151
+ local Maven repository
152
+
153
+ <Warning >
154
+ If you only use Maven through an IDE (e.g. IntelliJ IDEA), you should
155
+ remove ` && mvn clean install ` from the generated ` on_generate ` command.
156
+ </Warning >
157
+
129
158
</Tab >
130
159
131
160
<Tab title = " PHP" >
@@ -135,6 +164,13 @@ you can get a client library for free.
135
164
```
136
165
</Tab >
137
166
167
+ <Tab title = " Ruby" >
168
+ ``` bash
169
+ npx @boundaryml/baml init \
170
+ --client-type rest/openapi --openapi-client-type ruby
171
+ ```
172
+ </Tab >
173
+
138
174
<Tab title = " Rust" >
139
175
``` bash
140
176
npx @boundaryml/baml init \
@@ -225,17 +261,114 @@ func main() {
225
261
</Tab >
226
262
227
263
<Tab title = " Java" >
228
- <Warning >
229
- The README that the Java OpenAPI generator generates will have one mistake: it
230
- will suggest importing from ` baml_client.models.* ` , but the correct
231
- package to import from is ` baml_client.model.* ` . The OpenAPI team
232
- will [ fix this
233
- soon] ( https://github.com/OpenAPITools/openapi-generator/issues/19431 ) .
234
- </Warning >
264
+ First, add the OpenAPI-generated client to your project.
265
+
266
+ <AccordionGroup >
267
+
268
+ <Accordion title = " If you have 'mvn' in your PATH" >
269
+
270
+ You can use the default ` on_generate ` command, which will tell ` baml dev ` to
271
+ install the OpenAPI-generated client into your local Maven repository by running
272
+ ` mvn clean install ` every time you save a change to a BAML file.
273
+
274
+ To depend on the client in your local Maven repo, you can use these configs:
275
+
276
+ <CodeGroup >
277
+ ``` xml pom.xml
278
+ <dependency >
279
+ <groupId >org.openapitools</groupId >
280
+ <artifactId >openapi-java-client</artifactId >
281
+ <version >0.1.0</version >
282
+ <scope >compile</scope >
283
+ </dependency >
284
+ ```
285
+
286
+ ``` kotlin settings.gradle.kts
287
+ repositories {
288
+ mavenCentral()
289
+ mavenLocal()
290
+ }
291
+
292
+ dependencies {
293
+ implementation(" org.openapitools:openapi-java-client:0.1.0" )
294
+ }
295
+ ```
296
+ </CodeGroup >
297
+
298
+ </Accordion >
299
+
300
+ <Accordion title = " If you don't have 'mvn' in your PATH" >
301
+
302
+ You'll probably want to comment out ` on_generate ` and instead use either the [ OpenAPI Maven plugin] or [ OpenAPI Gradle plugin] to build your OpenAPI client.
303
+
304
+ [ OpenAPI Maven plugin ] : https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin
305
+ [ OpenAPI Gradle plugin ] : https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin
306
+
307
+ <CodeGroup >
308
+ ``` xml pom.xml
309
+ <build >
310
+ <plugins >
311
+ <plugin >
312
+ <groupId >org.openapitools</groupId >
313
+ <artifactId >openapi-generator-maven-plugin</artifactId >
314
+ <version >7.8.0</version > <!-- Use the latest stable version -->
315
+ <executions >
316
+ <execution >
317
+ <goals >
318
+ <goal >generate</goal >
319
+ </goals >
320
+ <configuration >
321
+ <inputSpec >${project.basedir}/baml_client/openapi.yaml</inputSpec >
322
+ <generatorName >baml</generatorName > <!-- or another generator name, e.g. 'kotlin' or 'spring' -->
323
+ <output >${project.build.directory}/generated-sources/openapi</output >
324
+ <apiPackage >com.boundaryml.baml_client.api</apiPackage >
325
+ <modelPackage >com.boundaryml.baml_client.model</modelPackage >
326
+ <invokerPackage >com.boundaryml.baml_client</invokerPackage >
327
+ <java8 >true</java8 >
328
+ </configuration >
329
+ </execution >
330
+ </executions >
331
+ </plugin >
332
+ </plugins >
333
+ </build >
334
+ ```
335
+
336
+ ``` kotlin settings.gradle.kts
337
+ plugins {
338
+ id(" org.openapi.generator" ) version " 7.8.0"
339
+ }
340
+
341
+ openApiGenerate {
342
+ generatorName.set(" java" ) // Change to 'kotlin', 'spring', etc. if needed
343
+ inputSpec.set(" ${projectDir} /baml_client/openapi.yaml" )
344
+ outputDir.set(" $buildDir /generated-sources/openapi" )
345
+ apiPackage.set(" com.boundaryml.baml_client.api" )
346
+ modelPackage.set(" com.boundaryml.baml_client.model" )
347
+ invokerPackage.set(" com.boundaryml.baml_client" )
348
+ additionalProperties.set(mapOf (" java8" to " true" ))
349
+ }
350
+
351
+ sourceSets[" main" ].java {
352
+ srcDir(" $buildDir /generated-sources/openapi/src/main/java" )
353
+ }
354
+
355
+ tasks.named(" compileJava" ) {
356
+ dependsOn(" openApiGenerate" )
357
+ }
358
+ ```
359
+ </CodeGroup >
360
+
361
+ </Accordion >
362
+ </AccordionGroup >
363
+
364
+ Then, copy this code into wherever your ` main ` function is:
365
+
235
366
``` Java
236
367
import com.boundaryml.baml_client.ApiClient ;
237
368
import com.boundaryml.baml_client.ApiException ;
238
369
import com.boundaryml.baml_client.Configuration ;
370
+ // NOTE: baml_client/README.md will suggest importing from models.* - that is wrong.
371
+ // See https://github.com/OpenAPITools/openapi-generator/issues/19431 for more details.
239
372
import com.boundaryml.baml_client.model.* ;
240
373
import com.boundaryml.baml_client.api.DefaultApi ;
241
374
@@ -268,6 +401,8 @@ public class Example {
268
401
you, and you need help working around it.
269
402
</Warning >
270
403
404
+ First, add the OpenAPI-generated client to your project:
405
+
271
406
``` json composer.json
272
407
"repositories" : [
273
408
{
@@ -280,6 +415,8 @@ public class Example {
280
415
}
281
416
```
282
417
418
+ You can now use this code to call a BAML function:
419
+
283
420
``` PHP
284
421
<?php
285
422
require_once(__DIR__ . '/vendor/autoload.php');
@@ -350,11 +487,15 @@ end
350
487
```
351
488
</Tip >
352
489
490
+ First, add the OpenAPI-generated client to your project:
491
+
353
492
``` toml Cargo.toml
354
493
[dependencies ]
355
494
baml-client = { path = " ./baml_client" }
356
495
```
357
496
497
+ You can now use ` cargo run ` :
498
+
358
499
``` rust
359
500
use baml_client :: models :: ExtractResumeRequest ;
360
501
use baml_client :: apis :: default_api as b;
0 commit comments