Skip to content

Commit e9d699b

Browse files
authored
[docs] adding docs for cerebras (#1952)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Add documentation for Cerebras integration and update prompt engineering examples and navigation. > > - **Documentation**: > - Adds `cerebras.mdx` to document Cerebras integration with OpenAI client using `openai-generic` provider. > - Updates `openai-generic.mdx` to include Cerebras in the list of supported providers. > - **Prompt Engineering**: > - Updates `tools.mdx` with examples for using BAML classes and functions in Python and TypeScript. > - **Navigation**: > - Updates `docs.yml` to include Cerebras in the navigation under LLM Client Providers. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for afc02f8. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent bd51c29 commit e9d699b

4 files changed

Lines changed: 112 additions & 2 deletions

File tree

fern/01-guide/06-prompt-engineering/tools.mdx

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ In BAML, you can get represent a `tool` or a `function` you want to call as a BA
2121

2222
```baml BAML
2323
class WeatherAPI {
24+
// we can use literals to denote the name of the tool
25+
// the field can be named anything we want! "api_name" "tool" "function_name"
26+
// whatever you feel the LLM would understand best
27+
api_name "weather_request"
2428
city string @description("the user's city")
2529
timeOfDay string @description("As an ISO8601 timestamp")
2630
}
@@ -397,11 +401,13 @@ This is what it looks in the BAML file:
397401

398402
``` Rust tools.baml
399403
class WeatherAPI {
404+
intent "weather_request"
400405
city string
401406
time string @description("Current time in ISO8601 format")
402407
}
403408

404409
class CalculatorAPI {
410+
intent "basic_calculator"
405411
operation "add" | "subtract" | "multiply" | "divide"
406412
numbers float[]
407413
}
@@ -418,11 +424,12 @@ function SelectTool(message: string) -> WeatherAPI | CalculatorAPI {
418424
}
419425
```
420426

421-
In our Python code, we'll:
427+
In our agent code, we'll:
422428
1. Implement our APIs
423429
2. Implement our Agent that continuously will use different tools
424430

425-
``` Python toolAgent.py
431+
<CodeGroup>
432+
```python toolAgent.py
426433
from baml_client import b
427434
from baml_client.types import WeatherAPI, CalculatorAPI
428435

@@ -471,6 +478,81 @@ if __name__ == "__main__":
471478
main()
472479
```
473480

481+
```typescript toolAgent.ts
482+
import { b } from "@/baml_client";
483+
import { WeatherAPI, CalculatorAPI } from "@/baml-client/types";
484+
485+
function handleWeather(weather: WeatherAPI): string {
486+
// Simulate weather API call
487+
return `The weather in ${weather.city} at ${weather.time} is sunny.`;
488+
}
489+
490+
function handleCalculator(calc: CalculatorAPI): string {
491+
const numbers = calc.numbers;
492+
let result: number;
493+
494+
switch (calc.operation) {
495+
case "add":
496+
result = numbers.reduce((a, b) => a + b, 0);
497+
break;
498+
case "subtract":
499+
result = numbers.slice(1).reduce((a, b) => a - b, numbers[0]);
500+
break;
501+
case "multiply":
502+
result = numbers.reduce((a, b) => a * b, 1);
503+
break;
504+
case "divide":
505+
result = numbers.slice(1).reduce((a, b) => a / b, numbers[0]);
506+
break;
507+
default:
508+
return "Unknown operation.";
509+
}
510+
511+
return `The result is ${result}`;
512+
}
513+
514+
async function main() {
515+
console.log("Agent started! Type 'exit' to quit.");
516+
517+
const readline = await import("readline");
518+
519+
const rl = readline.createInterface({
520+
input: process.stdin,
521+
output: process.stdout,
522+
});
523+
524+
rl.on("line", async (input) => {
525+
if (input.toLowerCase() === "exit") {
526+
rl.close();
527+
return;
528+
}
529+
530+
const toolResponse = await b.SelectTool(input);
531+
532+
switch (toolResponse.intent) {
533+
case "weather_request":
534+
const result = handleWeather(toolResponse as WeatherAPI);
535+
console.log(`Agent (Weather): ${result}`);
536+
}
537+
if () {
538+
const result = handleWeather(toolResponse as WeatherAPI);
539+
console.log(`Agent (Weather): ${result}`);
540+
} else if ("numbers" in toolResponse && "operation" in toolResponse) {
541+
const result = handleCalculator(toolResponse as CalculatorAPI);
542+
console.log(`Agent (Calculator): ${result}`);
543+
} else {
544+
console.log("Agent: Sorry, I couldn't handle that input.");
545+
}
546+
});
547+
}
548+
549+
main();
550+
551+
```
552+
553+
</CodeGroup>
554+
555+
474556
We can test this by asking things like:
475557
1. What is the weather in Seattle?
476558
2. What's 5+2?
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Cerebras
3+
---
4+
5+
[Cerebras](https://inference-docs.cerebras.ai/resources/openai) supports the OpenAI client, allowing you to use the
6+
[`openai-generic`](/ref/llm-client-providers/openai-generic) provider with an
7+
overridden `base_url`.
8+
9+
10+
See [OpenAI Generic](/ref/llm-client-providers/openai-generic) for more details about parameters.
11+
12+
13+
**Example:**
14+
15+
```baml BAML
16+
client<llm> CerebrasLlama {
17+
provider "openai-generic"
18+
options {
19+
base_url "https://api.cerebras.ai/v1"
20+
api_key env.CEREBRAS_API_KEY
21+
model "llama-3.3-70b"
22+
}
23+
}
24+
```

fern/03-reference/baml/clients/providers/openai-generic.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A non-exhaustive list of providers you can use with `openai-generic`:
2323
| Inference Provider | Docs |
2424
| -------------- | -------------- |
2525
| Azure AI Foundary | [Azure AI Foundary](/ref/llm-client-providers/azure-ai-foundary) |
26+
| Cerebras | [Cerebras](/ref/llm-client-providers/cerebras) |
2627
| Groq | [Groq](/ref/llm-client-providers/groq) |
2728
| Hugging Face | [Hugging Face](/ref/llm-client-providers/huggingface) |
2829
| Keywords AI | [Keywords AI](/ref/llm-client-providers/keywordsai) |

fern/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ navigation:
739739
- page: "Azure AI Foundary (openai-generic)"
740740
slug: azure-ai-foundary
741741
path: 03-reference/baml/clients/providers/azure-ai-foundary.mdx
742+
- page: "Cerebras (openai-generic)"
743+
slug: cerebras
744+
path: 03-reference/baml/clients/providers/cerebras.mdx
742745
- page: "Groq (openai-generic)"
743746
slug: groq
744747
path: 03-reference/baml/clients/providers/groq.mdx

0 commit comments

Comments
 (0)