<commit_before>from __future__ import unicode_literals

from builtins import chr
import re

from util import hook, http


@hook.api_key("wolframalpha")
@hook.command("wa")
@hook.command
def wolframalpha(inp, api_key=None):
    ".wa/.wolframalpha <query> -- computes <query> using Wolfram Alpha"<commit_msg>Add conversation api support<commit_after>from __future__ import unicode_literals

from builtins import chr
import re
import urllib.parse

from util import hook, http


@hook.api_key("wolframalpha")
@hook.command("what")
@hook.command
def ask(inp, msg=None, nick=None, api_key=None):
    ".ask <query> -- ask wolfram a question, get an answer"

    if not inp:
        return

    base_url = "http://api.wolframalpha.com/v1/conversation.jsp"
    query = urllib.parse.quote_plus(inp)
    url = f"{base_url}?appid={api_key}&i={query}"

    response = http.get_json(url)
    result = response.get("result")

    if not result:
        return f"Sorry, I do not know how to answer that {nick}."

    return result


@hook.api_key("wolframalpha")
@hook.command("wa")
@hook.command
def wolframalpha(inp, api_key=None):
    ".wa/.wolframalpha <query> -- computes <query> using Wolfram Alpha"
{'fraction_non_alphanumeric': 0.12363330529857022, 'fraction_numerical': 0.0008410428931875525, 'mean_word_length': 4.288888888888889, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2723846', 'n_tokens_mistral': 428, 'n_tokens_neox': 414, 'n_words': 107}