tawfik.gh commited on
Commit
ab1ac21
1 Parent(s): 0cbe9ff

connect oracle db

Browse files
Files changed (2) hide show
  1. app.py +3 -5
  2. chatbot_helper.py +21 -1
app.py CHANGED
@@ -2,9 +2,8 @@ import streamlit as st
2
  import os
3
  import getpass
4
  import time
5
- from chatbot_helper import generate, get_docs
6
  from llama_index.core.llms import ChatMessage
7
- # from groq import Groq
8
  from pinecone import Pinecone
9
  from llama_index.llms.groq import Groq
10
  from semantic_router.encoders import HuggingFaceEncoder
@@ -58,12 +57,11 @@ if prompt := st.chat_input("What is up?"):
58
  st.markdown(prompt)
59
 
60
  if not prompt.__contains__("Yes") or not prompt.__contains__("No"):
61
- docs = get_docs(prompt, 3,encoder, index)
62
- docs = [str(i) for i in docs]
63
 
64
  # result = generate(prompt, docs, groq_client, st.session_state.messages)
65
 
66
- docs = "\n---\n".join(docs)
67
 
68
  system_message =f'''
69
  You are a real state assistant act as that and help users find best properties in Dubai that fit there requirement using the
 
2
  import os
3
  import getpass
4
  import time
5
+ from chatbot_helper import oracle_db
6
  from llama_index.core.llms import ChatMessage
 
7
  from pinecone import Pinecone
8
  from llama_index.llms.groq import Groq
9
  from semantic_router.encoders import HuggingFaceEncoder
 
57
  st.markdown(prompt)
58
 
59
  if not prompt.__contains__("Yes") or not prompt.__contains__("No"):
60
+ docs = oracle_db(prompt, 5)
 
61
 
62
  # result = generate(prompt, docs, groq_client, st.session_state.messages)
63
 
64
+ docs = "\n---\n".join([str(i) for i in docs])
65
 
66
  system_message =f'''
67
  You are a real state assistant act as that and help users find best properties in Dubai that fit there requirement using the
chatbot_helper.py CHANGED
@@ -36,4 +36,24 @@ def generate(query: str, docs: list[str], groq_client, messages):
36
  print(chat_response)
37
  for chunk in chat_response:
38
  return chunk.choices[0].delta.content
39
- # return chat_response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  print(chat_response)
37
  for chunk in chat_response:
38
  return chunk.choices[0].delta.content
39
+ # return chat_response.choices[0].message.content
40
+
41
+ def oracle_db(query:str, top_k:int) -> list[dict]:
42
+ import oracledb
43
+ connection = oracledb.connect(user="ai", password="testtest",dsn="91.75.21.131:9522/FREEPDB1")
44
+ cursor = connection.cursor()
45
+ exist = cursor.execute("""SELECT v.id, prop.*, t.*,
46
+ VECTOR_DISTANCE(v.vector,TO_VECTOR(VECTOR_EMBEDDING(ALL_MINILM_L12_V2 USING :query as data)), COSINE) AS distance
47
+ FROM
48
+ ai.my_vectors v
49
+ JOIN ai.dld_property prop ON prop.property_id = v.id
50
+ JOIN ai.dld_trans t ON t.prop_id = v.id
51
+ ORDER BY distance ASC
52
+ FETCH FIRST :top_k ROWS ONLY""", query=query, top_k=top_k)
53
+ columns = [col[0] for col in cursor.description]
54
+ cursor.rowfactory = lambda *args: dict(zip(columns, args))
55
+ exist = cursor.fetchall()
56
+ print(query)
57
+ print(exist)
58
+ connection.close()
59
+ return exist