LoslegenKostenlos loslegen

Stripping outputs of thoughts

One of the main strengths of reasoning models is their thought process, captured in their thinking tokens. However, storing and processing all of these extra tokens can become problematic in multi-turn conversations in chatbot applications.

One approach is to strip model outputs of their "thoughts" (the thinking content), which you can do with regular expressions (RegEx). Have a try doing this on an example response stored in the response_content string.

Diese Übung ist Teil des Kurses

Working with DeepSeek in Python

Kurs anzeigen

Anleitung zur Übung

  • Remove the thinking tokens and tags from the response_content string using the RegEx pattern provided.
  • Strip final_response of leading and trailing whitespace.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

import re

# Remove the thinking tokens and tags
final_response = re.____(r'[\s\S]*?<\/think>\s*', ____, ____, re.DOTALL)

# Strip final_response of whitespace
print(final_response.____())
Code bearbeiten und ausführen