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

Function create_labels

api/app/api/utils/classification/input_classification.py:9–52  ·  view source on GitHub ↗

Create labels for the user input

(user_input, scope="USA", parent_id=None, session_id=None)

Source from the content-addressed store, hash-verified

7from app.api.utils.table_selection.table_details import get_minimal_table_schemas
8
9async def create_labels(user_input, scope="USA", parent_id=None, session_id=None) -> bool:
10 """
11 Create labels for the user input
12 """
13
14 if not EVENTS_ENGINE:
15 return None
16
17 table_prefix = get_minimal_table_schemas(scope)
18
19 user_message = f"""The user asked our database for:
20----
21{user_input}
22----
23
24Our schema has the following tables (here's parts of the script to create them):
25---
26{table_prefix}
27---
28
29give me a JSON object for classifying it in our database as well as if we have it. The object needs to consist of
30 {{
31 topics: str[],
32 categories: str[],
33 locations: str[],
34 relevant_tables_from_schema: str[],
35 has_relevant_table: bool,
36}}
37Thanks! Provide the JSON and only the JSON. Values should be in all lowercase."""
38
39 messages = [{"role": "user", "content": user_message}]
40
41 assistant_message = call_chat(messages, model="gpt-3.5-turbo", scope=scope, purpose="input_classification", session_id=session_id)
42
43 try:
44 parsed = json.loads(assistant_message)
45 except:
46 parsed = {}
47
48 generation_id = log_input_classification(scope, user_input, parsed, parent_id, session_id)
49
50 # is_relevant_query = parsed.get("has_relevant_table", False)
51
52 return generation_id

Callers 1

run_tasksFunction · 0.85

Calls 3

call_chatFunction · 0.90
log_input_classificationFunction · 0.90

Tested by

no test coverage detected