Skip to content

Commit 304e423

Browse files
Merge pull request #39 from paulparkinson/main
2 parents 2eb2923 + 1f93eb1 commit 304e423

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
FROM maven:3.6.3-openjdk-11 AS maven_build
1+
FROM maven:3.8.4-openjdk-17 AS maven_build
22
COPY pom.xml /tmp/pom.xml
33
COPY env.properties /tmp/env.properties
44
COPY src /tmp/src
5-
COPY lib /tmp/lib
6-
COPY lib/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar /tmp/lib/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar
75
WORKDIR /tmp/
86

9-
RUN mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=/tmp/lib/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar
107
RUN mvn -f /tmp/pom.xml clean package
118

12-
FROM openjdk
9+
FROM openjdk:17
1310
EXPOSE 8080
1411

1512
CMD ls /tmp

python-rag-chatbot/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
## TODO instructions
1111

1212
- setup ~/.oci/config
13-
- set yourcompartmentid
13+
- oci session authenticate and make sure authentication is successful
14+
- use region where the OCI gen AI is available. Currently we are using chicago region.
15+
- run pip install -r requirements.txt
16+
- check you config_rag.py file and make sure your api endpoint belong to chicago region and db which you want to use like chroma db or oracle db
17+
- set your compartment_id ocid inside the file i.e. init_rag_streamlit_exp.py and init_rag.py file
18+
- Changing the db type you need to modify at config file and you see the logic inside create_vector_store
1419
- podman run -d --name 23ai -p 1521:1521 -e ORACLE_PWD=<password> -v oracle-volume:/Users/pparkins/oradata container-registry.oracle.com/database/free:latest
1520
- create/config vector tablespace and user
1621
- add oracle database info for use in init_rag_streamlit.py / init_rag_streamlit_exp.py
17-
- run run_oracle_bot.sh /run_oracle_bot_exp.sh
22+
- run ./run_oracle_bot_exp.sh
1823

1924

2025
## Documentation

python-rag-chatbot/config_rag.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
DEBUG = False
55

66
# book to use for augmentation
7-
# BOOK1 = "APISpec.pdf"
7+
88
BOOK1 = "pdfFiles/sharding-adg-addshard-cookbook-3610618.pdf"
99
BOOK2 = "pdfFiles/globally-distributed-autonomous-database.pdf"
10-
# BOOK4 = "OnBoardingGuide.pdf"
11-
# BOOK5 = "CreateWorkFlow.pdf"
12-
# BOOK6 = "Team Onboarding.pdf"
13-
# BOOK7 = "workflow.pdf"
1410
BOOK3 = "pdfFiles/oracle-database-23c.pdf"
1511
BOOK4 = "pdfFiles/oracle-globally-distributed-database-guide.pdf"
1612
BOOK5 = "pdfFiles/Oracle True cache.pdf"
1713
BOOK6 = "pdfFiles/Trobleshooting.pdf"
18-
# BOOK12 = "OsdCode.pdf"
14+
1915

2016
BOOK_LIST = [BOOK1, BOOK2, BOOK3, BOOK4, BOOK5, BOOK6]
2117

python-rag-chatbot/init_rag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
# private configs
5151
CONFIG_PROFILE = "DEFAULT"
52-
COMPARTMENT_OCID = "ocid1.compartment.oc1..yourcompartmentid"
52+
COMPARTMENT_OCID = "ocid1.compartment.yourcomparmentid"
5353
oci_config = oci.config.from_file("~/.oci/config", CONFIG_PROFILE)
5454
COHERE_API_KEY = oci_config['security_token_file']
5555
DEBUG = True
@@ -155,7 +155,7 @@ def initialize_rag_chain():
155155

156156
llm = OCIGenAI(
157157
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
158-
compartment_id="ocid1.compartment.oc1..yourcompartmentid",
158+
compartment_id="ocid1.compartment.oc1..yourcompartment",
159159
model_kwargs={"max_tokens": 1000},
160160
auth_type='SECURITY_TOKEN',
161161
)

python-rag-chatbot/init_rag_streamlit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
# private configs
6464
CONFIG_PROFILE = "DEFAULT"
65-
COMPARTMENT_OCID = "ocid1.compartment.oc1..aaaaaaaajdyhd7dqnix2avhlckbhhkkcl3cujzyuz6jzyzonadca3i66pqjq"
65+
COMPARTMENT_OCID = "ocid1.compartment.oc1..yourcompartment"
6666
oci_config = oci.config.from_file("~/.oci/config", CONFIG_PROFILE)
6767
COHERE_API_KEY = oci_config['key_file']
6868
#

python-rag-chatbot/init_rag_streamlit_exp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
# private configs
6565
CONFIG_PROFILE = "DEFAULT"
66-
COMPARTMENT_OCID = "ocid1.compartment.oc1..yourcompartmentid"
66+
COMPARTMENT_OCID = "ocid1.compartment.oc1..yourcompartment"
6767
oci_config = oci.config.from_file("~/.oci/config", CONFIG_PROFILE)
6868
COHERE_API_KEY = oci_config['security_token_file']
6969

@@ -134,6 +134,7 @@ def split_in_chunks(all_pages):
134134
splits = post_process(splits)
135135

136136
print(f"Splitted the pdf in {len(splits)} chunks...")
137+
print("Size of splits: " + str(text_splitter.__sizeof__()) + "bytes")
137138

138139
return splits
139140

@@ -252,7 +253,7 @@ def build_llm(llm_type):
252253
llm = OCIGenAI(
253254
model_id="cohere.command",
254255
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
255-
compartment_id="ocid1.compartment.oc1..yourcompartmentid",
256+
compartment_id="ocid1.compartment.oc1..yourCompartment",
256257
model_kwargs={"max_tokens": 200},
257258
auth_type='SECURITY_TOKEN',
258259
)
@@ -284,13 +285,14 @@ def initialize_rag_chain():
284285

285286
# 3. Load embeddings model
286287
embedder = create_cached_embedder()
287-
288+
print("Size of splits---: " + str(document_splits.__sizeof__()) + "bytes")
288289
# 4. Create a Vectore Store and store embeddings
289290
vectorstore = create_vector_store(VECTOR_STORE_NAME, document_splits, embedder)
290291

291292
# 5. Create a retriever
292293
# increased num. of docs to 5 (default to 4)
293294
# added optionally a reranker
295+
294296
retriever = create_retriever(vectorstore)
295297

296298
# 6. Build the LLM

python-rag-chatbot/oracle_bot_exp.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import streamlit as st
2-
import time
32
import traceback
43
import sys
5-
64
from init_rag_streamlit_exp import initialize_rag_chain, get_answer
7-
85
from streamlit_feedback import streamlit_feedback
96

107
def process_feedback(feedback_value):
11-
st.write("Feedback value:", feedback_value)
12-
with open("feedback.txt", "a", encoding="utf-8") as f:
13-
f.write(f"{feedback_value}\n")
8+
st.write("Processing feedback value:", feedback_value) # Debugging output
9+
try:
10+
with open("feedback.txt", "a", encoding="utf-8") as f:
11+
f.write(f"{feedback_value}\n")
12+
st.write("Feedback successfully written to file.") # Debugging output
13+
except Exception as e:
14+
st.error(f"Error writing to file: {e}")
15+
traceback.print_exc()
1416

1517
def reset_conversation():
1618
st.session_state.messages = []
@@ -53,6 +55,7 @@ def reset_conversation():
5355
if not st.session_state.feedback_rendered:
5456
def _submit_feedback(feedback_value, *args, **kwargs):
5557
print("Feedback submitted:", feedback_value, file=sys.stderr) # Redirect to stderr
58+
st.write("Feedback value received for submission:", feedback_value) # Debugging output
5659
process_feedback(feedback_value)
5760
st.session_state.feedback_rendered = False
5861

0 commit comments

Comments
 (0)