An action in Select AI is a keyword that instructs Select AI to perform different behavior when acting on the prompt.
Most applications use the convenience methods on Profile or
AsyncProfile, such as show_sql(), run_sql(), narrate(), and
chat(). Use generate(..., action=...) when you want to choose the
action dynamically at runtime.
The default action for generate() is select_ai.Action.RUNSQL.
1. Supported Actions¶
The following actions can be performed using select_ai:
Action |
Enum |
Description |
|---|---|---|
chat |
|
Enables general conversations with the LLM, potentially for clarifying prompts, exploring data, or generating content. |
explainsql |
|
Explains the generated SQL query. |
narrate |
|
Executes generated SQL and explains the output in natural language. |
runsql |
|
Executes SQL generated from a natural language prompt. This is the
default action for |
showprompt |
|
Shows the prompt sent to the LLM. |
showsql |
|
Displays the generated SQL statement without executing it. |
summarize |
|
Generates a summary of inline content or content referenced by a URI. |
feedback |
|
Provides feedback to improve the accuracy of generated SQL. |
translate |
|
Translates text from one language to another. |
1.1. Action methods¶
Action |
Convenience method |
Return type |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.2. Choosing an action¶
Use show_sql before run_sql when you want to inspect generated SQL
before executing it. Use run_sql when the application should return a
tabular result. Use narrate when users need a natural language answer
instead of a table. Use explain_sql and show_prompt when tuning profile
attributes, object lists, comments, constraints, or feedback.
1.3. Examples¶
Use a convenience method:
profile = select_ai.Profile(profile_name="oci_ai_profile")
sql = profile.show_sql(prompt="How many promotions?")
Use generate with an explicit action:
profile = select_ai.Profile(profile_name="oci_ai_profile")
sql = profile.generate(
prompt="How many promotions?",
action=select_ai.Action.SHOWSQL,
)
df = profile.generate(
prompt="How many promotions?",
action=select_ai.Action.RUNSQL,
)
Use an action selected at runtime:
action = select_ai.Action("showsql")
result = profile.generate(
prompt="How many promotions?",
action=action,
)
1.4. Streaming¶
Streaming is supported for text-returning generation actions:
CHAT, NARRATE, EXPLAINSQL, SHOWSQL, and SHOWPROMPT.
Streaming is not supported for RUNSQL because it returns a
pandas.DataFrame.
for chunk in profile.generate(
prompt="What is OCI?",
action=select_ai.Action.CHAT,
stream=True,
chunk_size=4096,
):
print(chunk, end="")