Create labels for the user input
(user_input, scope="USA", parent_id=None, session_id=None)
| 7 | from app.api.utils.table_selection.table_details import get_minimal_table_schemas |
| 8 | |
| 9 | async 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 | |
| 24 | Our schema has the following tables (here's parts of the script to create them): |
| 25 | --- |
| 26 | {table_prefix} |
| 27 | --- |
| 28 | |
| 29 | give 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 | }} |
| 37 | Thanks! 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 |
no test coverage detected