Skip to content

Commit 8bce4a6

Browse files
committed
Updated examples and API
1 parent b36dead commit 8bce4a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2022
-728
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ dist
88
src/select_ai.egg-info
99
doc/.DS_Store
1010
doc/build
11+
doc/drawio
1112
**/__pycache__
1213
test.env

doc/source/image/classes.png

-602 KB
Binary file not shown.

doc/source/image/conversation.png

56.5 KB
Loading
273 KB
Loading

doc/source/image/vector_index.png

139 KB
Loading

doc/source/index.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,32 @@ Getting Started
2222
user_guide/installation.rst
2323
user_guide/connection.rst
2424

25-
Select AI classes
26-
=================
25+
AI Profile Object Model
26+
==============================
2727

2828
.. toctree::
2929
:numbered:
3030
:maxdepth: 3
3131

32-
user_guide/class_object_model.rst
32+
user_guide/profile_provider_class.rst
33+
34+
VectorIndex Object Model
35+
==================================
36+
37+
.. toctree::
38+
:numbered:
39+
:maxdepth: 3
40+
41+
user_guide/vector_index_class.rst
42+
43+
Conversation Object Model
44+
===================================
45+
46+
.. toctree::
47+
:numbered:
48+
:maxdepth: 3
49+
50+
user_guide/conversation_class.rst
3351

3452
Actions
3553
=======

doc/source/user_guide/actions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Supported AI Actions
66

77
Following list of actions can be performed using ``select_ai``
88

9-
- ``select_ai.Action.RUNSQL``
10-
- ``select_ai.Action.SHOWSQL``
9+
- ``select_ai.Action.CHAT``
1110
- ``select_ai.Action.EXPLAINSQL``
1211
- ``select_ai.Action.NARRATE``
13-
- ``select_ai.Action.CHAT``
12+
- ``select_ai.Action.RUNSQL``
1413
- ``select_ai.Action.SHOWPROMPT``
14+
- ``select_ai.Action.SHOWSQL``

doc/source/user_guide/async_profile.rst

Lines changed: 168 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,191 @@ used with ``await``.
1212
.. autoclass:: select_ai.AsyncProfile
1313
:members:
1414

15-
********************
16-
Async SQL generation
17-
********************
15+
***********************
16+
Async Profile creation
17+
***********************
18+
19+
.. literalinclude:: ../../../examples/async_examples/profile_create.py
20+
:language: python
21+
22+
output::
23+
24+
Profile attributes are: ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=[{'owner': 'SH'}], object_list_mode=None, provider=OCIGenAIProvider(embedding_model=None, model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='GENERIC', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name=None)
25+
Profile attributes as Python dict: {'annotations': None,
26+
'case_sensitive_values': None,
27+
'comments': None,
28+
'constraints': None,
29+
'conversation': None,
30+
'credential_name': 'my_oci_ai_profile_key',
31+
'enable_source_offsets': None,
32+
'enable_sources': None,
33+
'enforce_object_list': None,
34+
'max_tokens': 1024,
35+
'object_list': [{'owner': 'SH'}],
36+
'object_list_mode': None,
37+
'provider': OCIGenAIProvider(embedding_model=None,
38+
model=None,
39+
provider_name='oci',
40+
provider_endpoint=None,
41+
region='us-chicago-1',
42+
oci_apiformat='GENERIC',
43+
oci_compartment_id=None,
44+
oci_endpoint_id=None,
45+
oci_runtimetype=None),
46+
'seed': None,
47+
'stop_tokens': None,
48+
'streaming': None,
49+
'temperature': None,
50+
'vector_index_name': None}
51+
52+
53+
***********************
54+
Async explain SQL
55+
***********************
56+
57+
.. literalinclude:: ../../../examples/async_examples/profile_explain_sql.py
58+
:language: python
59+
60+
output::
61+
62+
To answer the question "How many promotions", we need to write a SQL query that counts the number of rows in the "PROMOTIONS" table. Here is the query:
63+
64+
```sql
65+
SELECT
66+
COUNT("p"."PROMO_ID") AS "Number of Promotions"
67+
FROM
68+
"SH"."PROMOTIONS" "p";
69+
```
70+
71+
Explanation:
72+
73+
* We use the `COUNT` function to count the number of rows in the table.
74+
* We use the table alias `"p"` to refer to the `"PROMOTIONS"` table.
75+
* We enclose the table name and column name in double quotes to make them case-sensitive.
76+
* We use the `AS` keyword to give an alias to the count column, making it easier to read.
77+
78+
This query will return the total number of promotions in the `"PROMOTIONS"` table.
79+
80+
81+
***********************
82+
Async run SQL
83+
***********************
84+
85+
.. literalinclude:: ../../../examples/async_examples/profile_run_sql.py
86+
:language: python
87+
88+
output::
89+
90+
PROMOTION_COUNT
91+
0 503
92+
93+
***********************
94+
Async show SQL
95+
***********************
96+
97+
.. literalinclude:: ../../../examples/async_examples/profile_show_sql.py
98+
:language: python
99+
100+
output::
101+
102+
SELECT COUNT("p"."PROMO_ID") AS "PROMOTION_COUNT" FROM "SH"."PROMOTIONS" "p"
18103

19-
.. literalinclude:: ../../../examples/async_examples/1_sql.py
104+
105+
***********************
106+
Async concurrent SQL
107+
***********************
108+
109+
.. literalinclude:: ../../../examples/async_examples/profile_sql_concurrent_tasks.py
20110
:language: python
21111

112+
output::
113+
114+
SELECT COUNT("c"."CUST_ID") AS "customer_count" FROM "SH"."CUSTOMERS" "c"
115+
116+
To answer the question "How many promotions", we need to write a SQL query that counts the number of rows in the "PROMOTIONS" table. Here is the query:
117+
118+
```sql
119+
SELECT
120+
COUNT("p"."PROMO_ID") AS "number_of_promotions"
121+
FROM
122+
"SH"."PROMOTIONS" "p";
123+
```
124+
125+
Explanation:
126+
127+
* We use the `COUNT` function to count the number of rows in the table.
128+
* We use the table alias `"p"` to refer to the `"PROMOTIONS"` table.
129+
* We specify the schema name `"SH"` to ensure that we are accessing the correct table.
130+
* We enclose the table name, schema name, and column name in double quotes to make them case-sensitive.
131+
* The `AS` keyword is used to give an alias to the calculated column, in this case, `"number_of_promotions"`.
132+
133+
This query will return the total number of promotions in the `"PROMOTIONS"` table.
134+
135+
PROMOTION_COUNT
136+
0 503
137+
22138
**********
23139
Async chat
24140
**********
25141

26-
.. literalinclude:: ../../../examples/async_examples/2_chat.py
142+
.. literalinclude:: ../../../examples/async_examples/profile_chat.py
27143
:language: python
28144

145+
output::
146+
147+
OCI stands for several things depending on the context:
148+
149+
1. **Oracle Cloud Infrastructure (OCI)**: This is a cloud computing service offered by Oracle Corporation. It provides a range of services including computing, storage, networking, database, and more, allowing businesses to build, deploy, and manage applications and services in a secure and scalable manner.
150+
151+
...
152+
..
153+
OML4PY provides a Python interface to OML, allowing users to create, manipulate, and analyze models using Python scripts. It enables users to leverage the power of OML and OMF from within Python, making it easier to integrate modeling and simulation into larger workflows and applications.
154+
...
155+
...
156+
157+
An Autonomous Database is a type of database that uses artificial intelligence (AI) and machine learning (ML) to automate many of the tasks typically performed by a database administrator (DBA)
158+
...
159+
...
160+
29161
*********************
30162
Async pipeline
31163
*********************
32164

33-
.. literalinclude:: ../../../examples/async_examples/3_pipeline.py
165+
.. literalinclude:: ../../../examples/async_examples/profile_pipeline.py
34166
:language: python
35167

168+
output::
169+
170+
Result 0 for prompt 'What is Oracle Autonomous Database?' is: Oracle Autonomous Database is a cloud-based database service that uses artificial intelligence (AI) and machine learning (ML) to automate many of the tasks associated with managing a database. It is a self-driving, self-securing, and self-repairing database that eliminates the need for manual database administration, allowing users to focus on higher-level tasks.
171+
172+
173+
Result 1 for prompt 'Generate SQL to list all customers?' is: SELECT "c"."CUST_ID" AS "Customer ID", "c"."CUST_FIRST_NAME" AS "First Name", "c"."CUST_LAST_NAME" AS "Last Name", "c"."CUST_EMAIL" AS "Email" FROM "SH"."CUSTOMERS" "c"
174+
175+
Result 2 for prompt 'Explain the query: SELECT * FROM sh.products' is: ```sql
176+
SELECT
177+
p.*
178+
FROM
179+
"SH"."PRODUCTS" p;
180+
```
181+
182+
**Explanation:**
183+
184+
This query is designed to retrieve all columns (`*`) from the `"SH"."PRODUCTS"` table.
185+
186+
Here's a breakdown of the query components:
187+
188+
189+
Result 3 for prompt 'Explain the query: SELECT * FROM sh.products' is: ORA-20000: Invalid action - INVALID ACTION
190+
36191
****************************
37192
List profiles asynchronously
38193
****************************
39194

40-
.. literalinclude:: ../../../examples/async_examples/5_list_profiles.py
195+
.. literalinclude:: ../../../examples/async_examples/profiles_list.py
41196
:language: python
197+
198+
output::
199+
200+
AsyncProfile(profile_name=OCI_VECTOR_AI_PROFILE, attributes=ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=None, object_list_mode=None, provider=OCIGenAIProvider(embedding_model=None, model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='GENERIC', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name='test_vector_index'), description=<oracledb.AsyncLOB object at 0x1056de150>)
201+
AsyncProfile(profile_name=OCI_GEN_AI_PROFILE, attributes=ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=None, object_list_mode=None, provider=OCIGenAIProvider(embedding_model=None, model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='COHERE', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name=None), description=<oracledb.AsyncLOB object at 0x104b1f170>)
202+
AsyncProfile(profile_name=OCI_AI_PROFILE, attributes=ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=[{'owner': 'SH'}], object_list_mode=None, provider=OCIGenAIProvider(embedding_model=None, model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='GENERIC', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name=None), description=<oracledb.AsyncLOB object at 0x102625940>)

doc/source/user_guide/class_object_model.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

doc/source/user_guide/conversation.rst

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
.. autoclass:: select_ai.Conversation
88
:members:
99

10-
*************************
11-
``VectorIndexAttributes``
12-
*************************
10+
*********************
11+
``AsyncConversation``
12+
*********************
13+
14+
.. autoclass:: select_ai.AsyncConversation
15+
:members:
16+
17+
**************************
18+
``ConversationAttributes``
19+
**************************
1320

1421
.. autoclass:: select_ai.ConversationAttributes
1522
:members:
@@ -18,12 +25,99 @@
1825
Conversation
1926
************
2027

21-
.. literalinclude:: ../../../examples/9_conversation.py
28+
Create conversion
29+
++++++++++++++++++
30+
31+
.. literalinclude:: ../../../examples/conversation_create.py
32+
:language: python
33+
34+
output::
35+
36+
Created conversation with conversation id: 380A1601-182D-F329-E063-D81A000A2C93
37+
38+
Chat session
39+
+++++++++++++
40+
41+
.. literalinclude:: ../../../examples/conversation_chat_session.py
42+
:language: python
43+
44+
output::
45+
46+
Conversation ID for this session is: 380A1910-5BF2-F7A1-E063-D81A000A3FDA
47+
48+
The importance of the history of science lies in its ability to provide a comprehensive understanding of the development of scientific knowledge and its impact on society. Here are some key reasons why the history of science is important:
49+
50+
1. **Contextualizing Scientific Discoveries**: The history of science helps us understand the context in which scientific discoveries were made, including the social, cultural, and intellectual climate of the time. This context is essential for appreciating the significance and relevance of scientific findings.
51+
52+
..
53+
..
54+
55+
The history of science is replete with examples of mistakes, errors, and misconceptions that have occurred over time. By studying these mistakes, scientists and researchers can gain valuable insights into the pitfalls and challenges that have shaped the development of scientific knowledge. Learning from past mistakes is essential for several reasons:
56+
...
57+
...
58+
59+
List conversations
60+
++++++++++++++++++
61+
62+
.. literalinclude:: ../../../examples/conversations_list.py
63+
:language: python
64+
65+
output::
66+
67+
5275A80-A290-DA17-E063-151B000AD3B4
68+
ConversationAttributes(title='History of Science', description="LLM's understanding of history of science", retention_days=7)
69+
70+
37DF777F-F3DA-F084-E063-D81A000A53BE
71+
ConversationAttributes(title='History of Science', description="LLM's understanding of history of science", retention_days=7)
72+
73+
74+
Delete conversation
75+
+++++++++++++++++++
76+
77+
.. literalinclude:: ../../../examples/conversation_delete.py
2278
:language: python
2379

80+
output::
81+
82+
Deleted conversation with conversation id: 37DDC22E-11C8-3D49-E063-D81A000A85FE
83+
84+
2485
*********************
2586
Async conversation
2687
*********************
2788

28-
.. literalinclude:: ../../../examples/async_examples/4_conversation.py
89+
90+
Chat Session
91+
+++++++++++++
92+
93+
.. literalinclude:: ../../../examples/async_examples/conversation_chat_session.py
94+
:language: python
95+
96+
output::
97+
98+
Conversation ID for this session is: 380A1910-5BF2-F7A1-E063-D81A000A3FDA
99+
100+
The importance of the history of science lies in its ability to provide a comprehensive understanding of the development of scientific knowledge and its impact on society. Here are some key reasons why the history of science is important:
101+
102+
1. **Contextualizing Scientific Discoveries**: The history of science helps us understand the context in which scientific discoveries were made, including the social, cultural, and intellectual climate of the time. This context is essential for appreciating the significance and relevance of scientific findings.
103+
104+
..
105+
..
106+
107+
The history of science is replete with examples of mistakes, errors, and misconceptions that have occurred over time. By studying these mistakes, scientists and researchers can gain valuable insights into the pitfalls and challenges that have shaped the development of scientific knowledge. Learning from past mistakes is essential for several reasons:
108+
...
109+
...
110+
111+
List conversations
112+
++++++++++++++++++
113+
114+
.. literalinclude:: ../../../examples/async_examples/conversations_list.py
29115
:language: python
116+
117+
output::
118+
119+
5275A80-A290-DA17-E063-151B000AD3B4
120+
ConversationAttributes(title='History of Science', description="LLM's understanding of history of science", retention_days=7)
121+
122+
37DF777F-F3DA-F084-E063-D81A000A53BE
123+
ConversationAttributes(title='History of Science', description="LLM's understanding of history of science", retention_days=7)

0 commit comments

Comments
 (0)