Quick Start Conversation
A brief overview of the conversational flow
Introduction
This guide provides a concise overview of how to engage in a conversation with the Nutrition Advisor using the API. It includes code examples in Python to help you get started quickly.
This guide assumes you have read and executed the Authorization Process and Request Setup. All requests in code examples pass an undefined headers
which you can quickly build following the steps in the above guides.
The Response Object
All responses from the Nutrition Advisor will be returned in the AdvisorResponse
object format:
threadId
string
The unique identifier of the conversation thread.
messageId
string
The unique identifier of the advisor's response message.
content
string
The main content of the advisor's response. Empty if message has a dataRequest
or actionResponse
. Should be JSON decoded from string when received.
contentToolHints
[]string
An array of tool names (or empty) that the advisor has sensed could be useful to run on this response.
dataRequest
AdvisorDataRequest
If the advisor requires additional information, this field contains the details of the data request.
actionResponse
AdvisorActionResponse
If the advisor performs an action based on the message, this field contains the details of the action response.
usage
AdvisorResponseUsage
Information about the token usage for the response.
List Available Tools
To list the available tools, make a GET request to /v2/products/nutrition-advisor/tools
. The response will include an array of tool objects with the following fields:
name
string
The unique name of the tool.
displayName
string
The display name of the tool.
description
string
A brief description of what the tool does.
type
enum
The type of the tool: target
, inputsense
, or vision
.
Code Example
Start A Conversation Thread
To start a new conversation, make a POST request to /v2/products/nutrition-advisor/threads
. You can optionally include the ?plainText=true
query parameter to receive plain text responses without markdown formatting.
Code Example
Interraction Flow
When you receive an AdvisorResponse
back from the Nutrition Advisor, follow these steps:
1. Check if content
is non-empty (Lines 2-17)
content
is non-empty (Lines 2-17)If so, parse
contentToolHints
.If any tools are found, match them to the
name
field of a cached available tool.Use a switch statement based on the tool name to handle specific cases.
For example, if the tool name is "SearchIngredientMatches", make a call to the
target
tool type using the message.
2. Check if dataRequest
is not null (Lines 19-40)
dataRequest
is not null (Lines 19-40)If not null, parse the
name
field and use a switch statement to handle specific cases.For example, if the tool name is "DetectMealLogsRequired" and the
parameters
field containsdaysBack: 1
, respond to the data request with the appropriate meal log data.
3. Check if actionResponse
is not null (Lines 41-48)
actionResponse
is not null (Lines 41-48)If not null, parse the
name
field and use a switch statement to handle specific cases.For example, if the tool name is "SearchIngredientMatches", parse the
data
field as JSON to obtain an array of ingredient data.
Code Example
Last updated