BAML
QuickstartPodcastTeamChangelogagent tries baml
DiscordGitHub8,423Learn BAML
Learn BAMLQuickstartPodcastTeamChangelogagent tries baml
DiscordGitHub8,423
Tutorialsover 1 year ago1 min read

Structured outputs with Deepseek R1

How to do tool-calling or function-calling with Deepseek R1

Vaibhav Gupta

Vaibhav Gupta

LinkedIn

Deepseek has recently released Deepseek R1, a reasoning model that can match the performance of OpenAI's o1 model at some tasks, at 1/50th of the cost (as of January 2025).

Our prompting framework, BAML, lets you do function-calling / tool-use with DeepseekR1 even when it is not officially supported.

Let's look at an interactive example!

Classication with Deepseek R1 and BAML

First we write some BAML code to classify messages. Here we write a function that takes a message and returns a category, that will be executed by an LLM. BAML will parse the result for you into the right enum type.

You can run this in python like this:

from baml_client import b
response = b.ClassifySupport(message="The app keeps crashing when I try to upload files")
print(f"Category: {response.category}")
print(f"Priority: {response.priority}")

Tool calling with Deepseek R1 and BAML

BAML lets you write tools like normal Unions of types. Here's another example where we have two tools, one that searches products, and one that schedules appointments.

You can call this in python like this (we also support other languages!):

from baml_client import b
from baml_client.types import ProductSearch, ScheduleAppointment
response = b.ChooseOneTool(user_message="Find me running shoes under $100 in the sports category")
print(response)

if isinstance(response, ProductSearch):
    print(f"Product Search called:")
    print(f"Query: {response.query}")
    print(f"Max Price: ${response.maxPrice}")
    print(f"Category: {response.category}")
elif isinstance(response, ScheduleAppointment):
    print(f"Schedule Appointment called:")
    print(f"Customer: {response.customerName}")
    print(f"Service: {response.serviceType}")
    print(f"Date: {response.preferredDate}")
    print(f"Duration: {response.duration} minutes")

Boundary

The programming language for agents.

  • Company
  • About Us
  • Why BAML?
  • Privacy Policy
  • Terms of Service
  • Resources
  • Changelog
  • Docs
  • Jobs
  • Blog
  • Pricing
  • Social
  • GitHub
  • Twitter
  • Discord
  • LinkedIn
  • YouTube