caesarHQ / textSQL

https://censusgpt.com
MIT License
1.54k stars 153 forks source link

[Feature Request] Implement Discord bot #50

Closed asaprahul closed 1 year ago

asaprahul commented 1 year ago

Perplexity and Midjourney have really cool discord bots for their discord servers, and we need one for CensusGPT. The backend API is implemented already (https://text-sql-be.onrender.com/api/text_to_sql), it takes only one param natural_language_query and returns the following schema:

{
    "result": {
        "column_names": [
            "city",
            "state",
            "male_to_female_ratio",
            "lat",
            "long"
        ],
        "results": [
            {
                "city": "Corona",
                "lat": 40.745288,
                "long": -73.861069,
                "male_to_female_ratio": 1.1319214365470154,
                "state": "NY"
            },
            {
                "city": "Norwalk",
                "lat": 33.90564,
                "long": -118.081767,
                "male_to_female_ratio": 1.0382917504237121,
                "state": "CA"
            },
            {
                "city": "Pittsburg",
                "lat": 38.016887,
                "long": -121.908178,
                "male_to_female_ratio": 1.0229007633587786,
                "state": "CA"
            },
        ]
    },
    "sql_query": "SELECT acs_census_data.city, acs_census_data.state, (SUM(male_population) / NULLIF(SUM(female_population), 0)) AS male_to_female_ratio\nFROM acs_census_data\nWHERE total_population > 100000\nGROUP BY acs_census_data.city, acs_census_data.state\nORDER BY male_to_female_ratio DESC\nLIMIT 10"
}

We need the discord bot to trigger the backend API with a natural language query from the user, then render the output in the discord channel. We can start with only rendering the 2-D table, and then figure out how to render the map (and / or other visualizations).

Perplexity bot:

Screenshot 2023-03-11 at 12 07 36 PM

Midjourney bot:

Screenshot 2023-03-11 at 12 08 36 PM
qyful commented 1 year ago

I presume you'd want it in JavaScript?

veerbia commented 1 year ago

I've created it so far in python, am able to get json response to send to discord channel. Now working on formatting.

veerbia commented 1 year ago

Done, will send PR in a sec