Skip to content

Commit

Permalink
Added manifests and updated app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AIWithShrey committed Aug 6, 2024
1 parent f01e399 commit c6a2d14
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import yaml
from yaml.loader import SafeLoader

from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
from urllib3.exceptions import ProtocolError

st.set_page_config(layout="wide", page_title="InSightful")

def authenticate():
Expand Down Expand Up @@ -144,9 +147,10 @@ def __init__(self, llm, embeddings, collection_name, db_client):
self.collection_name = collection_name
self.db_client = db_client

@retry(retry=retry_if_exception_type(ProtocolError), stop=stop_after_attempt(5), wait=wait_fixed(2))
def load_documents(self, doc, num_docs=250):
documents = []
for data in datasets.load_dataset(doc, split=f"train[:{num_docs}]").to_list():
for data in datasets.load_dataset(doc, split=f"train[:{num_docs}]", num_proc=10).to_list():
documents.append(
Document(
page_content=data["text"],
Expand Down Expand Up @@ -249,7 +253,7 @@ def setup_tools(_model, _client, _chroma_embedding_function, _embedder):
# embedder=_embedder,
#)

if os.getenv("USE_RERANKER", "False") == "True":
if os.getenv("USE_RERANKER", "False") == True:
retriever = create_reranker_retriever(
name="slack_conversations_retriever",
model=_model,
Expand Down Expand Up @@ -327,7 +331,7 @@ def main():
st.session_state["chat_history"] = chat_history

if __name__ == "__main__":
authenticator = authenticate()
if st.session_state['authentication_status']:
authenticator.logout()
#authenticator = authenticate()
#if st.session_state['authentication_status']:
# authenticator.logout()
main()
41 changes: 41 additions & 0 deletions k8s-manifests/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: restricted-view
rules:
- apiGroups: [""]
resources: ["configmaps", "pods", "services", "endpoints", "persistentvolumeclaims", "replicationcontrollers", "replicationcontrollers/scale"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: []
- apiGroups: ["apps"]
resources: ["daemonsets", "deployments", "replicasets", "statefulsets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["autoscaling"]
resources: ["horizontalpodautoscalers"]
verbs: ["get", "list", "watch"]
- apiGroups: ["batch"]
resources: ["cronjobs", "jobs"]
verbs: ["get", "list", "watch"]
- apiGroups: ["extensions"]
resources: ["daemonsets", "deployments", "replicasets", "replicationcontrollers/scale", "statefulsets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["networking.k8s.io"]
resources: ["networkpolicies"]
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses", "volumeattachments"]
verbs: ["get", "list", "watch"]
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["mutatingwebhookconfigurations", "validatingwebhookconfigurations"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apiregistration.k8s.io"]
resources: ["apiservices"]
verbs: ["get", "list", "watch"]
13 changes: 13 additions & 0 deletions k8s-manifests/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: restricted-view-binding
subjects:
- kind: User
name: sameer # Replace with the actual username
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: restricted-view
apiGroup: rbac.authorization.k8s.io

72 changes: 72 additions & 0 deletions k8s-manifests/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: insightful
name: insightful
namespace: ai-stack
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: insightful
strategy:
type: Recreate
template:
metadata:
labels:
app: insightful
spec:
containers:
- envFrom:
- configMapRef:
name: insightful-env
env:
- name: HUGGINGFACEHUB_API_TOKEN
valueFrom:
secretKeyRef:
name: tokens
key: HUGGINGFACEHUB_API_TOKEN
- name: STACK_OVERFLOW_API_KEY
valueFrom:
secretKeyRef:
name: tokens
key: STACK_OVERFLOW_API_KEY
- name: TAVILY_API_KEY
valueFrom:
secretKeyRef:
name: tokens
key: TAVILY_API_KEY
image: ghcr.io/infracloudio/insightful:latest
imagePullPolicy: Always
name: insightful
ports:
- containerPort: 8501
protocol: TCP
- containerPort: 3150
protocol: TCP
resources:
limits:
nvidia.com/gpu: "1"
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/secrets
name: secrets
readOnly: true
- name: empty
mountPath: /tmp/
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: secrets
secret:
defaultMode: 420
secretName: gh-pat
- name: empty
emptyDir: {}
20 changes: 20 additions & 0 deletions k8s-manifests/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: insightful-env
namespace: ai-stack
data:
TGI_HOST: "192.168.0.203"
TGI_PORT: "80"
TEI_HOST: "192.168.0.202"
TEI_PORT: "80"
RERANKER_HOST: "192.168.0.205"
RERANKER_PORT: "80"
VECTORDB_HOST: "192.168.0.204"
VECTORDB_PORT: "8000"
STOP_TOKEN: "<|endoftext|>"
PORTKEY_PROVIDER: "llm_provider_name"
PORTKEY_CUSTOM_HOST: "llm_provider_host_ip_and_port"
USE_PORTKEY: "0"
USE_RERANKER: "1"

10 changes: 10 additions & 0 deletions k8s-manifests/hf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: tokens
namespace: ai-stack
type: Opaque
data:
hf-token: "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"
tavily-token: "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"
stack-exchange-token: "z4v1VvgGdeTpBH2IefrTQg(("
8 changes: 8 additions & 0 deletions k8s-manifests/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
name: gh-pat
namespace: ai-stack
data:
gh-pat: Z2hwX3hjRXdyTzJKV1pvd214bFpZMm50YnhRUk13QU5wbTNkaEpZMgo=
44 changes: 44 additions & 0 deletions k8s-manifests/svc-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v1
kind: Service
metadata:
annotations:
meta.helm.sh/release-name: ai-stack
meta.helm.sh/release-namespace: ai-stack
metallb.universe.tf/ip-allocated-from-pool: ip-pool
creationTimestamp: "2024-07-27T04:34:16Z"
labels:
app.kubernetes.io/instance: ai-stack
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: tgi
app.kubernetes.io/version: 2.2.0
helm.sh/chart: tgi-0.1.5
name: ai-stack-tgi
namespace: ai-stack
resourceVersion: "7773298"
uid: d66fb7ac-ea08-48dc-9599-06ebea87e28b
spec:
allocateLoadBalancerNodePorts: true
clusterIP: 10.233.37.109
clusterIPs:
- 10.233.37.109
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 30175
port: 80
protocol: TCP
targetPort: http
selector:
app.kubernetes.io/instance: ai-stack
app.kubernetes.io/name: tgi
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.168.0.203
ipMode: VIP
32 changes: 32 additions & 0 deletions k8s-manifests/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: insightful
name: insightful
namespace: ai-stack
spec:
allocateLoadBalancerNodePorts: true
clusterIP: 10.233.39.226
clusterIPs:
- 10.233.39.226
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 30150
port: 80
protocol: TCP
targetPort: 8501
selector:
app: insightful
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.168.0.206
ipMode: VIP
Loading

0 comments on commit c6a2d14

Please sign in to comment.