@@ -1,20 +1,34 @@
|
||||
-- OCI GenAI chat extraction. This function returns JSON only; it never chooses tables.
|
||||
-- One short OCI Chat call extracts game-name mentions. Identity resolution is
|
||||
-- performed later by catalog vector score, not by another LLM call.
|
||||
CREATE OR REPLACE FUNCTION sg_game_extract_mentions(p_question IN CLOB)
|
||||
RETURN CLOB AUTHID DEFINER
|
||||
IS
|
||||
v_prompt CLOB;
|
||||
v_result CLOB;
|
||||
v_extract JSON_OBJECT_T;
|
||||
BEGIN
|
||||
v_prompt := 'Extract only game-name mentions from the user question. '
|
||||
|| 'Metrics, acronyms, dates, filters, and database object or column names are not game names unless they are themselves an explicit game title. '
|
||||
|| 'When a title-like noun directly qualifies a game data request such as user master, character, sales, AU, NRU, server, or game log, preserve that noun as a game-name mention even when it is not in a catalog. '
|
||||
|| 'Do not discard an unknown title merely because it cannot be resolved. General scope words such as common, overall, all, total, or every are not game-name mentions unless they are part of an explicit title. '
|
||||
|| 'Return exactly one JSON object with keys game_mentions (array of strings) '
|
||||
|| 'and scope_hint (GLOBAL, SINGLE_GAME, MULTI_GAME, ALL_GAMES, UNKNOWN). '
|
||||
|| 'Do not resolve names to IDs and do not generate SQL. Question: '
|
||||
|| 'Do not resolve names to IDs and do not generate SQL. '
|
||||
|| 'Return raw JSON only: no prose, no Markdown, and no code fence. Question: '
|
||||
|| DBMS_LOB.SUBSTR(p_question, 4000, 1);
|
||||
|
||||
v_result := DBMS_CLOUD_AI.GENERATE(
|
||||
prompt => v_prompt,
|
||||
profile_name => 'SGMP_POC_OCI_GPT54MINI',
|
||||
profile_name => 'SGMP_POC_OCI_COHERE_COMMAND',
|
||||
action => 'chat'
|
||||
);
|
||||
v_extract := JSON_OBJECT_T.parse(v_result);
|
||||
IF NOT v_extract.has('game_mentions') OR NOT v_extract.has('scope_hint') THEN
|
||||
RAISE_APPLICATION_ERROR(
|
||||
-20091,
|
||||
'Game mention extraction must return game_mentions and scope_hint JSON keys.'
|
||||
);
|
||||
END IF;
|
||||
RETURN v_result;
|
||||
END;
|
||||
/
|
||||
|
||||
Reference in New Issue
Block a user