Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions infra/aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module "aks" {
acr = azurerm_container_registry.acr.id
}

network_policy = "azure"
net_profile_dns_service_ip = "10.0.0.10"
net_profile_service_cidr = "10.0.0.0/16"
network_policy = "azure"
net_profile_dns_service_ip = "10.0.0.10"
net_profile_service_cidr = "10.0.0.0/16"

key_vault_secrets_provider_enabled = true
secret_rotation_enabled = true
Expand Down
2 changes: 1 addition & 1 deletion infra/identity.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource azurerm_user_assigned_identity chatbot {
resource "azurerm_user_assigned_identity" "chatbot" {
name = "chatbot"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
Expand Down
7 changes: 7 additions & 0 deletions infra/installation_script.tftpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash
az aks get-credentials --resource-group ${resourceGroup} --name ${aksName} --overwrite-existing

kubectl create namespace chatbot --dry-run=client -o yaml | kubectl apply -f -

helm repo add qdrant https://qdrant.github.io/qdrant-helm
helm repo update
helm upgrade --install --namespace chatbot --set image.tag=v1.11.3 chatbot qdrant/qdrant

az acr build --registry ${registry} --image chatbot:latest ./../sample-application

az identity federated-credential create --name chatbotfederatedidentity --identity-name chatbot --resource-group ${resourceGroup} --issuer ${oidc_url} --subject system:serviceaccount:chatbot:chatbot
Expand Down
4 changes: 2 additions & 2 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variable "chat_model_version" {
}

variable "scale_type" {
type = string
type = string
description = "values: GlobalStandard, Standard"
default = "GlobalStandard"
default = "GlobalStandard"
}
101 changes: 58 additions & 43 deletions sample-application/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
from langchain.chat_models import AzureChatOpenAI
from langchain.embeddings import AzureOpenAIEmbeddings
from azure.identity import ManagedIdentityCredential
import qdrant_client

import streamlit as st

from llama_index.vector_stores.qdrant import QdrantVectorStore
from llama_index.core import (
SimpleDirectoryReader,
GPTVectorStoreIndex,
VectorStoreIndex,
PromptHelper,
ServiceContext,
StorageContext,
load_index_from_storage,
Settings

)

from llama_index.llms.langchain import LangChainLLM
Expand All @@ -39,13 +40,26 @@

from dotenv import load_dotenv, dotenv_values


logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger("llama_index").setLevel(logging.DEBUG)

index = None
doc_path = "./data/"
index_file = "index.json"

client = qdrant_client.QdrantClient(
# you can use :memory: mode for fast and light-weight experiments,
# it does not require to have Qdrant deployed anywhere
# but requires qdrant-client >= 1.1.1
# location=":memory:"
# otherwise set Qdrant instance address with:
# url="http://<host>:<port>"
# otherwise set Qdrant instance with host and port:
host="chatbot-qdrant",
port=6333
# set API KEY for Qdrant Cloud
# api_key="<qdrant-api-key>",
)


if "config" not in st.session_state:
# Read the environment variables
Expand Down Expand Up @@ -119,47 +133,48 @@ def send_click():
)

if uploaded_file and uploaded_file.name != st.session_state.current_file:
# Ingest the document and create the index
with st.spinner('Ingesting the file..'):
doc_files = os.listdir(doc_path)
for doc_file in doc_files:
os.remove(doc_path + doc_file)

bytes_data = uploaded_file.read()
with open(f"{doc_path}{uploaded_file.name}", "wb") as f:
f.write(bytes_data)

loader = SimpleDirectoryReader(doc_path, recursive=True, exclude_hidden=True)
documents = loader.load_data()
sidebar_placeholder.header("Current Processing Document:")
sidebar_placeholder.subheader(uploaded_file.name)
sidebar_placeholder.write(documents[0].get_text()[:500] + "...")

index = GPTVectorStoreIndex.from_documents(
documents, service_context=service_context
)

index.set_index_id("vector_index")
index.storage_context.persist(index_file)
st.session_state.current_file = uploaded_file.name
st.session_state.response = "" # clean up the response when new file is uploaded
st.success('Done!')

elif os.path.exists(index_file):
# Read from storage context
storage_context = StorageContext.from_defaults(persist_dir=index_file)
index = load_index_from_storage(
storage_context, index_id="vector_index", service_context=service_context
st.session_state.current_file = uploaded_file.name
st.session_state.response = "" # clean up the response when new file is uploaded
if not client.collection_exists(collection_name=uploaded_file.name):
# Ingest the document and create the index
with st.spinner('Ingesting the file..'):
doc_files = os.listdir(doc_path)
for doc_file in doc_files:
os.remove(doc_path + doc_file)

bytes_data = uploaded_file.read()
with open(f"{doc_path}{uploaded_file.name}", "wb") as f:
f.write(bytes_data)

loader = SimpleDirectoryReader(doc_path, recursive=True, exclude_hidden=True)
documents = loader.load_data()
sidebar_placeholder.header("Current Processing Document:")
sidebar_placeholder.subheader(uploaded_file.name)

vector_store = QdrantVectorStore(client=client, collection_name=uploaded_file.name)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents,
service_context=service_context,
storage_context=storage_context,
)
index.set_index_id("vector_index")
st.success('Done!')

if st.session_state.current_file:
vector_store = QdrantVectorStore(client=client, collection_name=uploaded_file.name)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_vector_store(
vector_store=vector_store,
service_context=service_context,
storage_context=storage_context,
index_id="vector_index",
)

loader = SimpleDirectoryReader(doc_path, recursive=True, exclude_hidden=True)
documents = loader.load_data()
doc_filename = os.listdir(doc_path)[0]
doc_filename = st.session_state.current_file
sidebar_placeholder.header("Current Processing Document:")
sidebar_placeholder.subheader(doc_filename)
sidebar_placeholder.write(documents[0].get_text()[:500] + "...")
sidebar_placeholder.subheader(uploaded_file.name)

if index:
if index or st.session_state.response != "":
st.text_input("Ask something: ", key="prompt", on_change=send_click)
st.button("Send", on_click=send_click)
if st.session_state.response:
Expand Down
1 change: 1 addition & 0 deletions sample-application/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ python-dotenv==1.0.0
pypdf==4.1.0
azure-core==1.26.4
azure-identity==1.13.0
llama-index-vector-stores-qdrant==0.2.17