Grok 4.1 Fast· xai
Frontier Reasoning Traces
Write a Python program to detect language of a given text.
- User
Write a Python program to detect language of a given text.
- Assistant
#!/usr/bin/env python3 """ A simple Python program to detect the language of a given text. Requires: pip install langdetect """ import sys from langdetect import detect, LangDetectException def detect_language(text: str) -> str: """ Detects the language of the input text. Args: text (str): The text to analyze. Returns: str: The detected language code (e.g., 'en', 'fr') or 'unknown'. """ if not text.strip(): return "unknown (empty text)" try: return detect(text) except LangDetectException: return "unknown" def main(): # Get text from command-line arguments or stdin if len(sys.argv) > 1: text = ' '.join(sys.argv[1:]) else: print("Enter text (or Ctrl+D/Ctrl+Z to finish):", file=sys.stderr) text = sys.stdin.read().strip() lang = detect_language(text) print(f"Detected language: {lang}") if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.