Skip to content

Commit 5270c82

Browse files
Merge branch 'main' into al3xne-patch-3
2 parents 3de92b4 + 72327c7 commit 5270c82

File tree

114 files changed

+3151
-850
lines changed

Some content is hidden

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

114 files changed

+3151
-850
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.AppleDouble
44
.LSOverride
55
.vscode
6+
.bak
67

78
# Icon must end with two \r
89
Icon

ai-and-app-modernisation/ai-services/generative-ai-service/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Reviewed: 30.01.2024
66

77
# Team Publications
88

9+
- [Enable a Low Code Modular LLM App Engine using Oracle Integration and OCI Generative AI](https://docs.oracle.com/en/solutions/oci-generative-ai-integration/index.html)
10+
- This reference architecture lets you understand the necessary considerations and recommendations to enable an AI-based, modular and event-driven LLM App Engine using a low-code approach with Oracle Integration as the LLM orchestrator, OCI Generative AI and other OCI services
11+
- Build enterprise-grade, modular, scalable, secure & maintainable LLM Apps
912
- [Oracle Generative AI webinar](https://go.oracle.com/LP=138234?elqCampaignId=489428&src1=:so:ch:or:dg::::&SC=:so:ch:or:dg::::&pcode=WWMK230822P00010)
1013
- Deep dive into Oracle Generative AI platform
1114
- [Creating a RAG (Retrieval-Augmented Generation) with Oracle Generative AI Service in just 21 lines of code](https://github.com/oracle-devrel/technology-engineering/tree/main/ai-and-app-modernisation/ai-services/generative-ai-service/rag-genai)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from langchain_community.embeddings import OCIGenAIEmbeddings
2+
from langchain.chains import RetrievalQA
3+
from langchain_community.vectorstores import Qdrant
4+
from langchain_core.prompts import PromptTemplate
5+
from langchain_community.llms import OCIGenAI
6+
from langchain_community.document_loaders import UnstructuredURLLoader
7+
compartment_id = "ocid1.compartment.oc1..aaaaaaaa7ggqkd4ptkeb7ugk6ipsl3gqjofhkr6yacluwj4fitf2ufrdm65q"
8+
embeddings = OCIGenAIEmbeddings(model_id="cohere.embed-english-light-v3.0",service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",compartment_id= compartment_id,)
9+
testurls = ['https://docs.oracle.com/iaas/odsaz/odsa-rotate-wallet.html', 'https://docs.oracle.com/iaas/odsaz/odsa-change-password.html', 'https://docs.oracle.com/iaas/odsaz/odsa-database-actions.html']
10+
loader = UnstructuredURLLoader(urls=testurls)
11+
docs = loader.load()
12+
vectorstore = Qdrant.from_documents(docs,embeddings,location=":memory:",prefer_grpc=False,collection_name="test_db")
13+
retriever = vectorstore.as_retriever()
14+
rag_prompt_template = """Answer the question based only on the following context:
15+
{context}
16+
Question: {question}"""
17+
rag_prompt = PromptTemplate.from_template(rag_prompt_template)
18+
llm = OCIGenAI(model_id="cohere.command",service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",compartment_id= compartment_id,model_kwargs={"temperature": 0, "max_tokens": 300})
19+
rag = RetrievalQA.from_chain_type(llm=llm,retriever=retriever,chain_type_kwargs={"prompt": rag_prompt,},)
20+
data = rag.invoke("What is rotate a wallet")
21+
print(data['result'])

ai-and-app-modernisation/ai-services/generative-ai-service/rag-genai/files/README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@
33
## Introduction
44
In this article, we'll explore how to create a Retrieval-Augmented Generation (RAG) model using Oracle Gen AI, llama index, Qdrant Vector Database, and SentenceTransformerEmbeddings. This 21-line code will allow you to scrape through web pages, use llama index for indexing, Oracle Generative AI Service for question generation, and Qdrant for vector indexing.
55

6+
Find below the code of building a RAG using llamaIndex with Oracle Generative AI Service.
7+
Also check the file LangChainRAG.py which allows you to create an application (implementing RAG) using Langchain and the file langChainRagWithUI.py which includes a UI build with Streamlit.
8+
69
<img src="./RagArchitecture.svg">
710
</img>
811

9-
## Limited Availability
10-
11-
Oracle Generative AI Service is in Limited Availability as of today when we are creating this repo.
12-
13-
Customers can easily enter in the LA programs. To test these functionalities you need to enrol in the LA programs and install the proper versions of software libraries.
14-
15-
Code and functionalities can change, as a result of changes and new features
16-
1712
## Prerequisites
1813

1914
Before getting started, make sure you have the following installed:
2015

2116
- Oracle Generative AI Service
22-
- llama index
23-
- qdrant client
17+
- Llama index
18+
- Langchain
19+
- Qdrant client
2420
- SentenceTransformerEmbeddings
2521

2622
## Setting up the Environment
2723
1. Install the required packages:
2824
```bash
29-
pip install oci==2.118.1+preview.1.1697 llama-index qdrant-client sentence-transformers
25+
pip install -U langchain oci
26+
pip install langchain llama-index qdrant-client sentence-transformers transformers
3027
```
3128

3229
## Loading data
@@ -41,26 +38,26 @@ sitemap used : https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/frpj5kvxry
4138
## Entire code
4239

4340
```bash
44-
from genai_langchain_integration.langchain_oci import OCIGenAI
4541
from llama_index import VectorStoreIndex
4642
from llama_index import ServiceContext
4743
from llama_index.vector_stores.qdrant import QdrantVectorStore
4844
from llama_index.storage.storage_context import StorageContext
4945
from qdrant_client import qdrant_client
50-
from langchain.embeddings import SentenceTransformerEmbeddings
46+
from langchain_community.embeddings import SentenceTransformerEmbeddings
5147
from llama_hub.web.sitemap import SitemapReader
48+
from langchain_community.llms import OCIGenAI
5249
loader = SitemapReader()
53-
documents = loader.load_data(sitemap_url='https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/frpj5kvxryk1/b/thisIsThePlace/o/combined.xml')
50+
documents = loader.load_data(sitemap_url='https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/frpj5kvxryk1/b/thisIsThePlace/o/latest.xml')
5451
client = qdrant_client.QdrantClient(location=":memory:")
5552
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
56-
llm = OCIGenAI(model_id="cohere.command",service_endpoint="https://generativeai.aiservice.us-chicago-1.oci.oraclecloud.com",compartment_id = "ocid1.tenancy.oc1..aaaaaaaa5hwtrus75rauufcfvtnjnz3mc4xm2bzibbigva2bw4ne7ezkvzha",temperature=0.0)
53+
llm = OCIGenAI(model_id="cohere.command",service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",model_kwargs={"temperature": 0.0, "max_tokens": 300},compartment_id = "ocid1.compartment.oc1..aaaaaaaa7ggqkd4ptkeb7ugk6ipsl3gqjofhkr6yacluwj4fitf2ufrdm65q")
5754
system_prompt="As a support engineer, your role is to leverage the information in the context provided. Your task is to respond to queries based strictly on the information available in the provided context. Do not create new information under any circumstances. Refrain from repeating yourself. Extract your response solely from the context mentioned above. If the context does not contain relevant information for the question, respond with 'How can I assist you with questions related to the document?"
5855
service_context = ServiceContext.from_defaults(llm=llm, chunk_size=1000, chunk_overlap=100, embed_model=embeddings,system_prompt=system_prompt)
5956
vector_store = QdrantVectorStore(client=client, collection_name="ansh")
6057
storage_context = StorageContext.from_defaults(vector_store=vector_store)
6158
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context, service_context=service_context)
6259
query_engine = index.as_query_engine()
63-
response = query_engine.query("can i use OCI document understanding for files in french ?")
60+
response = query_engine.query('What is activity auditing report?')
6461
print(response)
6562
```
6663

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import streamlit as st
2+
from langchain_community.embeddings import OCIGenAIEmbeddings
3+
from langchain.chains import RetrievalQA
4+
from langchain_community.vectorstores import Qdrant
5+
from langchain_core.prompts import PromptTemplate
6+
from langchain_community.llms import OCIGenAI
7+
from langchain_community.document_loaders import UnstructuredURLLoader
8+
st.title("Oracle QA Chatbot")
9+
st.text_input("Ask a question:", key="question") # Input field for questions
10+
# Data loading (outside any function)
11+
compartment_id = "ocid1.compartment.oc1..aaaaaaaa7ggqkd4ptkeb7ugk6ipsl3gqjofhkr6yacluwj4fitf2ufrdm65q"
12+
embeddings = OCIGenAIEmbeddings(model_id="cohere.embed-english-light-v3.0",service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",compartment_id=compartment_id,)
13+
testurls = ['https://docs.oracle.com/iaas/odsaz/odsa-rotate-wallet.html','https://docs.oracle.com/iaas/odsaz/odsa-change-password.html','https://docs.oracle.com/iaas/odsaz/odsa-database-actions.html',]
14+
# Cache the loaded documents (outside any function)
15+
@st.cache_data
16+
def load_documents():
17+
docs = UnstructuredURLLoader(urls=testurls).load()
18+
print("Loading data")
19+
print(docs)
20+
return docs # Return the loaded documents
21+
docs = load_documents()
22+
vectorstore = Qdrant.from_documents(docs, embeddings, location=":memory:", prefer_grpc=False, collection_name="test_db")
23+
retriever = vectorstore.as_retriever()
24+
rag_prompt_template = """Answer the question based only on the following context:
25+
{context}
26+
Question: {question}"""
27+
rag_prompt = PromptTemplate.from_template(rag_prompt_template)
28+
llm = OCIGenAI(
29+
model_id="cohere.command",
30+
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
31+
compartment_id=compartment_id,
32+
model_kwargs={"temperature": 0, "max_tokens": 300},
33+
)
34+
rag = RetrievalQA.from_chain_type(llm=llm, retriever=retriever, chain_type_kwargs={"prompt": rag_prompt})
35+
# Answer generation when a question is asked
36+
if st.button("Get Answer"):
37+
question = st.session_state.question
38+
# Ensure correct access to cached documents
39+
docs = load_documents() # Call the cached function to retrieve documents
40+
data = rag.invoke(question, context=docs) # Pass documents as context
41+
answer = data["result"]
42+
st.write("Answer:", answer)
Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,21 @@
1-
# Integrate OCI AI Speech Service and Generative AI Summarization in Visual Builder
2-
3-
# Introduction
4-
5-
OCI Speech is an AI service that applies automatic speech recognition technology to transform audio-based content into text. Generative AI, The Large Language Model (LLM) analyzes the text input and can generate, summarize, transform, and extract information. Using these AI capabilities, we built a low code application- “Integrate OCI AI Speech Service and Generative AI Summarization in Visual Builder " to invoke AI Speech REST API to convert audio files into text and then further invoke the Generative AI REST API to Summarize it.
1+
# Transcribe and summarize speech-to-text
2+
3+
OCI Speech is an AI service that applies automatic speech recognition technology to transform audio-based content into text. Generative AI, The Large Language Model (LLM) analyzes the text input and can generate, summarize, transform, and extract information. Using these AI capabilities, we built a low code application- “Integrate OCI AI Speech Service and Generative AI Service for Summarization in Visual Builder " to invoke AI Speech REST API to convert audio files into text and then further invoke the Generative AI REST API to Summarize it.
64

75
Reviewed: 20.02.2024
8-
9-
<img src="./files/AISpeechGenAISummary.png"></img>
10-
11-
# Prerequisites
12-
13-
Before getting started, make sure you have access to these services:
14-
15-
- Oracle Speech Service
16-
- Oracle Generative AI Service
17-
- Oracle Visual Builder Cloud Service
18-
- Oracle Visual Builder Service Connection
19-
20-
# AI Speech and OCI Generative AI Service Integration Architecture
21-
22-
1. AI Speech App using VBCS
23-
24-
- Oracle Visual Builder Cloud Service (VBCS) is a hosted environment for your application development infrastructure. It provides an open-source standards-based development service to create, collaborate on, and deploy applications within Oracle Cloud. This application is developed in VBCS.
25-
26-
2. Transcriptions with OCI AI Speech Service:
27-
- Speech harnesses the power of spoken language enabling you to easily convert media files containing human speech into highly exact text transcriptions.
28-
- Produces accurate and easy-to-use JSON and SubRip Subtitle (SRT) files written directly to the Object Storage bucket you choose.
29-
30-
3. Integration with OCI Generative AI Service:
31-
- The transcriptions (text) are sent to the OCI Generative AI Service for text summarization.
32-
33-
4. Integration with OCI AI Vision and OCI Generative AI Service using Visual Builder Service Endpoint:
34-
- Build a Service Connection Endpoint option is used to integrate the VBCS app and OCI Object Storage, OCI AI Speech Service, and Generative AI Summarization.
35-
36-
5. Summarization Process:
37-
- OCI Generative AI Service generates text using the keywords received from OCI Speech service, to create a concise summary of the audio or video.
38-
39-
40-
<img src="./files/AISpeechSummaryAppArch.svg"></img>
41-
42-
# Application Flow in Detail (VBCS, OCI Speech, OCI Generative AI Service)
43-
44-
In this application, the drag-and-drop component in VBCS allows the user to drop the audio or video.
45-
- Create a Service Endpoint connection in Visual Builder to handle the communication between Visual Builder and OCI Speech Service.
46-
- Pass the selected audio or video from Visual Builder to OCI Speech Service to convert it into text.
47-
- OCI Speech Service analyzes the media (audio or video) file and converts it into text.
48-
- The OCI Speech Service returns the transcription to the AI Speech Service Endpoint and returns the results to the Visual Builder app.
49-
- The transcription further passes to the Generative AI Service Endpoint and returns the Summarization results to the Visual Builder app.
50-
51-
User (Visual Builder) --> (Drag and Drop File) --> |Media File (adudio or video) --> (Service Endpoint) --> |OCI Speech Service| --> |Speech to Text| --> (Service Endpoint) --> |Result| --> (Visual Builder) --> (Gen AI Service Endpoint) --> |Result| --> (Visual Builder)
52-
53-
<img src="./files/AISpeechEngine.png"></img>
54-
55-
# Service Endpoint call - Invoke OCI Object Storage
56-
57-
uploadfile - /n/{namespaceName}/b/{bucketName}/o/{objectName}
58-
getObject - /n/{namespaceName}/b/{bucketName}/o/{outputFolderName}/{outputObjectName}
59-
60-
61-
# Service Endpoint call - Invoke AI Speech Service
62-
63-
create transcription - /transcriptionJobs
64-
get transcription - transcriptionJobs/{transcriptionJobId}
65-
66-
# Service Endpoint call - Invoke Generative AI Service
67-
68-
create summary - /20231130/actions/summarizeText
69-
70-
71-
# Conclusion
72-
73-
In this article, we've covered how to utilize Oracle AI Speech Service features to provide a transription and summarize using Generative AI service.
74-
75-
Feel free to modify and expand upon this template according to your specific use case and preferences.
76-
77-
6+
7+
# When to use this asset?
8+
9+
See the README document in the /files folder.
10+
11+
# How to use this asset?
12+
13+
See the README document in the /files folder.
14+
7815
# License
7916

8017
Copyright (c) 2024 Oracle and/or its affiliates.
8118

8219
Licensed under the Universal Permissive License (UPL), Version 1.0.
8320

8421
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
85-
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Integrate OCI AI Speech Service and Generative AI Summarization in Visual Builder
2+
3+
# Introduction
4+
5+
OCI Speech is an AI service that applies automatic speech recognition technology to transform audio-based content into text. Generative AI, The Large Language Model (LLM) analyzes the text input and can generate, summarize, transform, and extract information. Using these AI capabilities, we built a low code application- "Integrate OCI AI Speech Service and Generative AI Summarization in Visual Builder" to invoke AI Speech REST API to convert audio files into text and then further invoke the Generative AI REST API to Summarize it.
6+
7+
Reviewed: 20.02.2024
8+
9+
<img src="./files/AISpeechGenAISummary.png"></img>
10+
11+
# Prerequisites
12+
13+
Before getting started, make sure you have access to these services:
14+
15+
- Oracle Speech Service
16+
- Oracle Generative AI Service
17+
- Oracle Visual Builder Cloud Service
18+
- Oracle Visual Builder Service Connection
19+
20+
# AI Speech and OCI Generative AI Service Integration Architecture
21+
22+
1. AI Speech App using VBCS
23+
24+
- Oracle Visual Builder Cloud Service (VBCS) is a hosted environment for your application development infrastructure. It provides an open-source standards-based development service to create, collaborate on, and deploy applications within Oracle Cloud. This application is developed in VBCS.
25+
26+
2. Transcriptions with OCI AI Speech Service:
27+
- Speech harnesses the power of spoken language enabling you to easily convert media files containing human speech into highly exact text transcriptions.
28+
- Produces accurate and easy-to-use JSON and SubRip Subtitle (SRT) files written directly to the Object Storage bucket you choose.
29+
30+
3. Integration with OCI Generative AI Service:
31+
- The transcriptions (text) are sent to the OCI Generative AI Service for text summarization.
32+
33+
4. Integration with OCI AI Vision and OCI Generative AI Service using Visual Builder Service Endpoint:
34+
- Build a Service Connection Endpoint option is used to integrate the VBCS app and OCI Object Storage, OCI AI Speech Service, and Generative AI Summarization.
35+
36+
5. Summarization Process:
37+
- OCI Generative AI Service generates text using the keywords received from OCI Speech service, to create a concise summary of the audio or video.
38+
39+
40+
<img src="./files/AISpeechSummaryAppArch.svg"></img>
41+
42+
# Application Flow in Detail (VBCS, OCI Speech, OCI Generative AI Service)
43+
44+
In this application, the drag-and-drop component in VBCS allows the user to drop the audio or video.
45+
- Create a Service Endpoint connection in Visual Builder to handle the communication between Visual Builder and OCI Speech Service.
46+
- Pass the selected audio or video from Visual Builder to OCI Speech Service to convert it into text.
47+
- OCI Speech Service analyzes the media (audio or video) file and converts it into text.
48+
- The OCI Speech Service returns the transcription to the AI Speech Service Endpoint and returns the results to the Visual Builder app.
49+
- The transcription further passes to the Generative AI Service Endpoint and returns the Summarization results to the Visual Builder app.
50+
51+
User (Visual Builder) --> (Drag and Drop File) --> |Media File (adudio or video) --> (Service Endpoint) --> |OCI Speech Service| --> |Speech to Text| --> (Service Endpoint) --> |Result| --> (Visual Builder) --> (Gen AI Service Endpoint) --> |Result| --> (Visual Builder)
52+
53+
<img src="./files/AISpeechEngine.png"></img>
54+
55+
# Service Endpoint call - Invoke OCI Object Storage
56+
57+
uploadfile - /n/{namespaceName}/b/{bucketName}/o/{objectName}
58+
getObject - /n/{namespaceName}/b/{bucketName}/o/{outputFolderName}/{outputObjectName}
59+
60+
61+
# Service Endpoint call - Invoke AI Speech Service
62+
63+
create transcription - /transcriptionJobs
64+
get transcription - transcriptionJobs/{transcriptionJobId}
65+
66+
# Service Endpoint call - Invoke Generative AI Service
67+
68+
create summary - /20231130/actions/summarizeText
69+
70+
71+
# Conclusion
72+
73+
In this article, we've covered how to utilize Oracle AI Speech Service features to provide a transcription and summarize using Generative AI service.
74+
75+
Feel free to modify and expand upon this template according to your specific use case and preferences.
76+
77+
78+
# License
79+
80+
Copyright (c) 2024 Oracle and/or its affiliates.
81+
82+
Licensed under the Universal Permissive License (UPL), Version 1.0.
83+
84+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
85+

0 commit comments

Comments
 (0)