-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprofile_sql_concurrent_tasks.py
More file actions
42 lines (32 loc) · 1.32 KB
/
Copy pathprofile_sql_concurrent_tasks.py
File metadata and controls
42 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -----------------------------------------------------------------------------
# Copyright (c) 2025, Oracle and/or its affiliates.
#
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# async/profile_sql_concurrent_tasks.py
#
# Demonstrates sending multiple prompts concurrently using asyncio
# -----------------------------------------------------------------------------
import asyncio
import os
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
async def main():
await select_ai.async_connect(user=user, password=password, dsn=dsn)
async_profile = await select_ai.AsyncProfile(
profile_name="async_oci_ai_profile",
)
sql_tasks = [
async_profile.show_sql(prompt="How many customers?"),
async_profile.run_sql(prompt="How many promotions?"),
async_profile.explain_sql(prompt="How many promotions?"),
]
# Collect results from multiple asynchronous tasks
for sql_task in asyncio.as_completed(sql_tasks):
result = await sql_task
print(result)
asyncio.run(main())