<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stats(self, topic=None, channel=None, text=False):
 """Return internal instrumented statistics. :param topic: (optional) filter to topic :param channel: (optional) filter to channel :param text: return the stats as a string (default: ``False``) """

        if text:
            fields = {'format': 'text'}
        else:
            fields = {'format': 'json'}

        if topic:
            nsq.assert_valid_topic_name(topic)
            fields['topic'] = topic

        if channel:
            nsq.assert_valid_channel_name(channel)
            fields['channel'] = channel

        return self._request('GET', '/stats', fields=fields)