ROS Package bob_nlp_tools
This ROS Package is part of Bob’s NLP and LLM tools. It provides high-level semantic analysis and routing capabilities using OpenAI-compatible APIs (OpenAI, LM Studio, Ollama, LocalAI).
NlpSemanticDriver (Library)
The package includes a standalone, ROS-free Python library NlpSemanticDriver that encapsulates the communication with the LLM API. It provides high-level methods for:
Semantic Routing: Matching content to a key based on descriptions.
Semantic Filtering: Boolean pass/fail based on a criterion.
Summarization: Context-aware text compression.
Normalization: Structured data extraction.
ROS Nodes
The package provides several ROS 2 nodes that leverage the semantic driver for high-level NLP tasks:
1. Semantic Router (router)
Categorizes incoming text messages and routes them to specialized output topics based on their intent.
Example:
ros2 run bob_nlp_tools router --ros-args \
-p targets:='{"MOV": "Movement commands", "SPE": "Speech requests"}' \
-p base_url:="http://localhost:1234/v1"
2. Semantic Filter (filter)
Filters incoming messages based on a natural language criterion. Messages meeting the criterion are published to topic_out, others to topic_rejected.
Example:
ros2 run bob_nlp_tools filter --ros-args \
-p criterion:='Handelt es sich um eine Frage zu Bobs Status?' \
-p base_url:="http://localhost:1234/v1"
3. Summarizer (summarizer)
Generates concise summaries of incoming messages based on a provided context.
Example:
ros2 run bob_nlp_tools summarizer --ros-args \
-p context:='Zusammenfassung der letzten Fehlermeldungen' \
-p max_words:=20
4. Normalizer (normalizer)
Transforms unstructured input text into a structured format (e.g., JSON) based on descriptive instructions.
Example:
ros2 run bob_nlp_tools normalizer --ros-args \
-p instructions:='Extrahiere Name und Alter als JSON: {"name": "", "age": 0}'
Configuration
Parameters
Name |
Type |
Nodes |
Description |
|---|---|---|---|
|
string |
all |
API key. |
|
string |
all |
API Base URL. |
|
string |
all |
Model name. |
|
string (JSON) |
router |
JSON dictionary mapping topic suffixes to intent descriptions: |
|
string |
router |
Suffix used for unrouted messages. |
|
string |
filter |
Natural language condition for filtering. |
|
string |
summarizer |
Context for the summarization task. |
|
int |
summarizer |
Word limit for the summary. |
|
string |
normalizer |
Descriptive instructions for normalization. |
[!NOTE]
<NODE>placeholder corresponds to the node/binary name in uppercase (ROUTER,FILTER,SUMMARIZER,NORMALIZER). Environment variables provide the default values for ROS parameters.
System Prompts
The NlpSemanticDriver uses system prompts to guide the LLM’s behavior. These can be overridden using environment variables. The prompts use placeholders in {} that are replaced by the driver during processing.
Variable |
Placeholders |
Description |
|---|---|---|
|
|
Used by the Router to categorize messages. |
|
|
Used by the Filter to evaluate criteria. |
|
|
Used by the Summarizer. |
|
|
Used by the Normalizer. |
Default Prompt Examples
If you override these, ensure you maintain the required placeholders for the dynamic functionality.
Semantic Router Default:
You are a semantic router. Analyze the user input and choose exactly ONE key from the following list that matches best. Respond ONLY with the raw key name, nothing else.
Available Keys:
{options}
Filter Default:
Analyze the following input. If it matches the criterion '{criterion}', respond with 'YES'. If it does not match, respond with 'NO'. Respond ONLY with 'YES' or 'NO'.
Summarizer Default:
Summarize the following content in the context of: {context}. The summary must be short, precise and not exceed {max_words} words.
Normalizer Default:
Normalize the input according to these instructions: {instructions}. Respond ONLY with the clean output, no conversational filler.
Topics
Name |
Type |
Nodes |
Description |
|---|---|---|---|
|
|
all |
Input topic for messages to be processed. |
|
|
filter, summarizer, normalizer |
Output topic for processed messages. |
|
|
filter |
Output topic for messages that did not meet the criterion. |
|
|
router |
Dynamically created output topics for each target key. |
|
|
router |
Fallback topic for messages that couldn’t be routed. |
Installation
1. Requirements
Ensure you have the requests library installed:
pip3 install requests
2. Build from Source
Clone the repository into your ROS 2 workspace and build it using colcon:
cd ~/ros2_ws/src
git clone https://github.com/bob-ros2/bob_nlp_tools.git
cd ..
colcon build --packages-select bob_nlp_tools
source install/setup.bash