MCPcopy Create free account
hub / github.com/caesarHQ/textSQL / get_response

Function get_response

api/discordbot/responses.py:4–21  ·  view source on GitHub ↗
(message: str)

Source from the content-addressed store, hash-verified

2from tabulate import tabulate
3
4def get_response(message: str) -> str:
5 p_message = message.lower()
6
7 if p_message.startswith('!query'):
8 natural_language_query = p_message.split('!query ')[-1]
9 url = "https://text-sql-be.onrender.com/api/text_to_sql"
10
11 payload = {"natural_language_query": natural_language_query}
12 headers = {"Content-Type": "application/json"}
13
14 response = requests.post(url, json=payload, headers=headers)
15 if response.json()["result"] is None:
16 return "Sorry, I couldn't find any results for that query"
17 data = response.json()["result"]["results"]
18 headers = response.json()["result"]["column_names"]
19 table_data = [[d.get(header, "") for header in headers] for d in data]
20 table = tabulate(table_data, headers=headers)
21 return "```\n" + table + "\n```"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected