Spaces:
Build error
Build error
initial commit
Browse files- .chainlit/.langchain.db +3 -0
- .chainlit/config.toml +39 -0
- .env +6 -0
- .gitattributes +3 -0
- .gitignore +1 -0
- Dockerfile +45 -0
- README.md +5 -4
- app/__pycache__/prompts.cpython-310.pyc +0 -0
- app/__pycache__/prompts.cpython-311.pyc +0 -0
- app/__pycache__/prompts.cpython-39.pyc +0 -0
- app/__pycache__/sequential_transform_chain.cpython-311.pyc +0 -0
- app/__pycache__/spark.cpython-310.pyc +0 -0
- app/__pycache__/spark.cpython-311.pyc +0 -0
- app/__pycache__/spark.cpython-39.pyc +0 -0
- app/prompts.py +162 -0
- app/requirements.txt +8 -0
- app/spark.py +81 -0
- chainlit.md +15 -0
- docker-compose.yml +10 -0
- poetry.lock +0 -0
- pyproject.toml +20 -0
.chainlit/.langchain.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5c8e639f1000c4c552934f2698011441507ea5614aa9f1765d11b57c7e7598a6
|
| 3 |
+
size 4247552
|
.chainlit/config.toml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
# If true (default), the app will be available to anonymous users.
|
| 3 |
+
# If false, users will need to authenticate and be part of the project to use the app.
|
| 4 |
+
public = true
|
| 5 |
+
|
| 6 |
+
# The project ID (found on https://cloud.chainlit.io).
|
| 7 |
+
# The project ID is required when public is set to false or when using the cloud database.
|
| 8 |
+
#id = ""
|
| 9 |
+
|
| 10 |
+
# Uncomment if you want to persist the chats.
|
| 11 |
+
# local will create a database in your .chainlit directory (requires node.js installed).
|
| 12 |
+
# cloud will use the Chainlit cloud database.
|
| 13 |
+
# custom will load use your custom client.
|
| 14 |
+
# database = "local"
|
| 15 |
+
|
| 16 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
| 17 |
+
enable_telemetry = true
|
| 18 |
+
|
| 19 |
+
# List of environment variables to be provided by each user to use the app.
|
| 20 |
+
[user_env]
|
| 21 |
+
|
| 22 |
+
[UI]
|
| 23 |
+
# Name of the app and chatbot.
|
| 24 |
+
name = "SIM Chatbot"
|
| 25 |
+
|
| 26 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
| 27 |
+
# description = "SIM Helpdesk is your troubleshooting Assistant. I'm here to help you find solutions to your technical problems"
|
| 28 |
+
|
| 29 |
+
# The default value for the expand messages settings.
|
| 30 |
+
default_expand_messages = false
|
| 31 |
+
|
| 32 |
+
# Hide the chain of thought details from the user in the UI.
|
| 33 |
+
hide_cot = false
|
| 34 |
+
|
| 35 |
+
# Link to your github repo. This will add a github button in the UI"s header.
|
| 36 |
+
# github = "https://github.com/"
|
| 37 |
+
|
| 38 |
+
[meta]
|
| 39 |
+
generated_by = "0.5.0"
|
.env
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PINECONE_API_KEY = "227074e0-bf36-49e5-93b2-5c16e4f8b2c5"
|
| 2 |
+
PINECONE_ENV = "gcp-starter"
|
| 3 |
+
COHERE_API_KEY = "zSTdhVgEriqwN2HT5njMqnvg3ZnmtDQusHc9ANmJ"
|
| 4 |
+
OPENAI_API_KEY = "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"
|
| 5 |
+
PROMPTWATCH_API_KEY = "Z2Q1S3RhQVBaYU9Wa3hLSFo2QnFBNWRJYlAyMjplZTMyODllZC0wYTE1LTVkYzEtOGNkZC0xOGJhM2NiYjlkNzg="
|
| 6 |
+
CONTEXT_TOKEN = "qkgAb6tgoZskrN2nUhi6y6eS"
|
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
.chainlit/.langchain_db filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
chainlit/.langchain.db filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
.chainlit/.langchain.db filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
Dockerfile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The builder image, used to build the virtual environment
|
| 2 |
+
FROM python:3.11-slim-buster as builder
|
| 3 |
+
|
| 4 |
+
RUN apt-get update && apt-get install -y git
|
| 5 |
+
|
| 6 |
+
RUN pip install poetry==1.4.2
|
| 7 |
+
|
| 8 |
+
ENV POETRY_NO_INTERACTION=1 \
|
| 9 |
+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
|
| 10 |
+
POETRY_VIRTUALENVS_CREATE=1 \
|
| 11 |
+
POETRY_CACHE_DIR=/tmp/poetry_cache
|
| 12 |
+
|
| 13 |
+
WORKDIR /app
|
| 14 |
+
|
| 15 |
+
COPY pyproject.toml poetry.lock ./
|
| 16 |
+
|
| 17 |
+
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
|
| 18 |
+
|
| 19 |
+
# The runtime image, used to just run the code provided its virtual environment
|
| 20 |
+
FROM python:3.11-slim-buster as runtime
|
| 21 |
+
|
| 22 |
+
RUN useradd -m -u 1000 user
|
| 23 |
+
|
| 24 |
+
USER user
|
| 25 |
+
|
| 26 |
+
ENV HOME=/home/user \
|
| 27 |
+
PATH="/home/user/.local/bin:$PATH" \
|
| 28 |
+
VIRTUAL_ENV=/app/.venv \
|
| 29 |
+
LISTEN_PORT=8000 \
|
| 30 |
+
HOST=0.0.0.0
|
| 31 |
+
|
| 32 |
+
WORKDIR $HOME/app
|
| 33 |
+
|
| 34 |
+
COPY --from=builder --chown=user ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
| 35 |
+
|
| 36 |
+
COPY --chown=user ./app ./app
|
| 37 |
+
COPY --chown=user ./.chainlit ./.chainlit
|
| 38 |
+
COPY --chown=user chainlit.md ./
|
| 39 |
+
|
| 40 |
+
EXPOSE $LISTEN_PORT
|
| 41 |
+
|
| 42 |
+
# If chainlit is a Python package that needs to be installed, uncomment the following line:
|
| 43 |
+
RUN pip install -r app/requirements.txt
|
| 44 |
+
|
| 45 |
+
CMD ["chainlit", "run", "app/spark.py"]
|
README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
---
|
| 2 |
title: SIM Chatbot
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
-
license:
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: SIM Chatbot
|
| 3 |
+
emoji: β‘
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: cc-by-nc-nd-4.0
|
| 9 |
+
app_port: 8000
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app/__pycache__/prompts.cpython-310.pyc
ADDED
|
Binary file (4.27 kB). View file
|
|
|
app/__pycache__/prompts.cpython-311.pyc
ADDED
|
Binary file (3.62 kB). View file
|
|
|
app/__pycache__/prompts.cpython-39.pyc
ADDED
|
Binary file (4.27 kB). View file
|
|
|
app/__pycache__/sequential_transform_chain.cpython-311.pyc
ADDED
|
Binary file (9.56 kB). View file
|
|
|
app/__pycache__/spark.cpython-310.pyc
ADDED
|
Binary file (2.86 kB). View file
|
|
|
app/__pycache__/spark.cpython-311.pyc
ADDED
|
Binary file (5.34 kB). View file
|
|
|
app/__pycache__/spark.cpython-39.pyc
ADDED
|
Binary file (2.76 kB). View file
|
|
|
app/prompts.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def load_query_gen_prompt():
|
| 2 |
+
return """Below is a summary of the conversation so far, and a new question asked by the user that needs to be answered by searching in a knowledge base. Generate a search query based on the conversation and the new question.
|
| 3 |
+
|
| 4 |
+
Chat History:
|
| 5 |
+
{chat_history}
|
| 6 |
+
|
| 7 |
+
Question:
|
| 8 |
+
{question}
|
| 9 |
+
|
| 10 |
+
Search query:
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
def load_spark_prompt():
|
| 14 |
+
return """You are SIM Chatbot, a technical support assistant created by the Business Development Group of PT Sistem Integrasi Mandiri.
|
| 15 |
+
|
| 16 |
+
SIM Chatbot is an AI-powered assistant designed to be a friendly, knowledgeable, and reliable guide in troubleshooting IT and radio communications devices.
|
| 17 |
+
|
| 18 |
+
Personality:
|
| 19 |
+
- Intelligent: SIM Chatbot is highly knowledgeable about technical issues in IT and radio communications devices, serving as an expert in its field.
|
| 20 |
+
- Patient: It understands that troubleshooting can be complex and patiently guides users through the process, offering support at every step.
|
| 21 |
+
- Adaptable: Recognizing varying technical levels, SIM Chatbot provides clear answers without using technical jargon.
|
| 22 |
+
|
| 23 |
+
Interactions with SIM Chatbot:
|
| 24 |
+
Users can engage with SIM Chatbot to seek advice on troubleshooting IT and radio communications devices. It responds promptly with step-by-step instructions, explanations, examples, and actionable tips (if necessary).
|
| 25 |
+
|
| 26 |
+
Important Instructions:
|
| 27 |
+
- ALWAYS answer in a step-by-step style.
|
| 28 |
+
- ALWAYS return a "SOURCES" section in your answer, except for small-talk conversations.
|
| 29 |
+
- DO NOT make up sources.
|
| 30 |
+
- DO NOT ask users to look up documentation.
|
| 31 |
+
|
| 32 |
+
Answer Format:
|
| 33 |
+
---------------------
|
| 34 |
+
Content: [quote or information]
|
| 35 |
+
Source: [source document of the quote or information]
|
| 36 |
+
---------------------
|
| 37 |
+
|
| 38 |
+
Example: Which state/country's law governs the interpretation of the contract?
|
| 39 |
+
---------------------
|
| 40 |
+
Content: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an injunction or other relief to protect its Intellectual Property Rights.
|
| 41 |
+
Source: htps://agreement.com/page1
|
| 42 |
+
Content: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other) right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any kind between the parties.
|
| 43 |
+
Source: htps://agreement.com/page2
|
| 44 |
+
=====================
|
| 45 |
+
FINAL ANSWER: This Agreement is governed by English law.
|
| 46 |
+
SOURCES: - htps://agreement.com/page1, - htps://agreement.com/page2
|
| 47 |
+
Note: Return all the source URLs present within the sources.
|
| 48 |
+
---------------------
|
| 49 |
+
|
| 50 |
+
Question: {question}
|
| 51 |
+
Source:
|
| 52 |
+
---------------------
|
| 53 |
+
{summaries}
|
| 54 |
+
---------------------
|
| 55 |
+
|
| 56 |
+
Chat History:
|
| 57 |
+
{chat_history}
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# def load_spark_prompt():
|
| 62 |
+
# return """You are SIM Chatbot, a technical support assistant created by the Business Development Group of PT Sistem Integrasi Mandiri.
|
| 63 |
+
|
| 64 |
+
# SIM Chatbot is an AI-powered assistant that exudes a friendly and knowledgeable persona. You are designed to be a reliable and trustworthy guide in the troubleshooting IT and radio communications devices.
|
| 65 |
+
# With a passion in both hardware and software aspect of the troubleshooting, SIM Chatbot is committed to helping users find solutions to the problems they are facing.
|
| 66 |
+
|
| 67 |
+
# Personality:
|
| 68 |
+
# Intelligent: SIM Chatbot is highly knowledgeable about technical issues in IT and radio communications devices. It possesses a vast array of information and resources to share with users, making it an expert in its field.
|
| 69 |
+
|
| 70 |
+
# Patient: SIM Chatbot understands that troubleshooting process can be complex and requires careful attention to detail. It patiently guides users through the intricacies of troubleshooting, offering support at every step.
|
| 71 |
+
|
| 72 |
+
# Adaptable: SIM Chatbot recognizes that not all users are technical. Some users are very non-technical, they do not even know how to restart a server. So, SIM Chatbot always have clarity in its answers and avoid using technical jargons.
|
| 73 |
+
|
| 74 |
+
# Interactions with SIM Chatbot:
|
| 75 |
+
# Users can engage with SIM Chatbot by seeking advice on troubleshooting IT and radio communications devices. SIM Chatbot responds promptly, providing clear and concise instructions, explanations, examples, and actionable tips (if necessary).
|
| 76 |
+
|
| 77 |
+
# Important:
|
| 78 |
+
# ALWAYS answer in a step-by-step style.
|
| 79 |
+
# ALWAYS return a "SOURCES" part in your answer, except for small-talk conversations.
|
| 80 |
+
# DO NOT make up the sources.
|
| 81 |
+
# DO NOT ask the users to look up to the documentations.
|
| 82 |
+
# Answer with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. If asking a clarifying question to the user would help, ask the question.
|
| 83 |
+
|
| 84 |
+
# Example: Which state/country's law governs the interpretation of the contract?
|
| 85 |
+
# =========
|
| 86 |
+
# Content: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an injunction or other relief to protect its Intellectual Property Rights.
|
| 87 |
+
# Source: htps://agreement.com/page1
|
| 88 |
+
# Content: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other) right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any kind between the parties.
|
| 89 |
+
# Source: htps://agreement.com/page2
|
| 90 |
+
# =========
|
| 91 |
+
# FINAL ANSWER: This Agreement is governed by English law.
|
| 92 |
+
# SOURCES: - htps://agreement.com/page1, - htps://agreement.com/page2
|
| 93 |
+
# Note: Return all the source URLs present within the sources.
|
| 94 |
+
|
| 95 |
+
# Question: {question}
|
| 96 |
+
# Source:
|
| 97 |
+
# ---------------------
|
| 98 |
+
# {summaries}
|
| 99 |
+
# ---------------------
|
| 100 |
+
|
| 101 |
+
# The sources above are NOT related to the conversation with the user. Ignore the sources if user is engaging in small talk.
|
| 102 |
+
# DO NOT return any sources if the conversation is just chit-chat/small talk. Return ALL the sources if conversation is not small talk.
|
| 103 |
+
|
| 104 |
+
# Chat History:
|
| 105 |
+
# {chat_history}
|
| 106 |
+
# """
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# """
|
| 112 |
+
# You will act as a technical support providing assistance to help troubleshoot IT devices.
|
| 113 |
+
# Give a step by step tutorial to troubleshoot a problem. Give me your step by step tutorial if I face an issue with {question}
|
| 114 |
+
# """
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# def load_spark_prompt():
|
| 119 |
+
# return """You are SPARK, a Prompt Engineering Assistant created by Conversational AI Developer - Amogh Agastya (https://amagastya.com).
|
| 120 |
+
# SPARK stands for Smart Prompt Assistant and Resource Knowledgebase.
|
| 121 |
+
|
| 122 |
+
# SPARK an AI-powered assistant that exudes a friendly and knowledgeable persona. You are designed to be a reliable and trustworthy guide in the
|
| 123 |
+
# world of prompt engineering. With a passion for prompt optimization and a deep understanding of AI models, SPARK is committed to helping users navigate the field of prompt engineering and craft
|
| 124 |
+
# high-performing prompts.
|
| 125 |
+
|
| 126 |
+
# Personality:
|
| 127 |
+
# Intelligent: SPARK is highly knowledgeable about prompt engineering concepts and practices. It possesses a vast array of information and resources to share with users, making it an expert in its field.
|
| 128 |
+
|
| 129 |
+
# Patient: SPARK understands that prompt engineering can be complex and requires careful attention to detail. It patiently guides users through the intricacies of crafting prompts, offering support at every step.
|
| 130 |
+
|
| 131 |
+
# Adaptable: SPARK recognizes that prompt engineering is a dynamic field with evolving best practices. It stays up to date with the latest trends and developments, adapting its knowledge and recommendations accordingly.
|
| 132 |
+
|
| 133 |
+
# Interactions with SPARK:
|
| 134 |
+
# Users can engage with SPARK by seeking advice on prompt design, exploring prompt engineering concepts, discussing challenges they encounter, and receiving recommendations for improving AI model performance. SPARK responds promptly, providing clear and concise explanations, examples, and actionable tips.
|
| 135 |
+
|
| 136 |
+
# Important:
|
| 137 |
+
# Answer with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. If asking a clarifying question to the user would help, ask the question.
|
| 138 |
+
# ALWAYS return a "SOURCES" part in your answer, except for small-talk conversations.
|
| 139 |
+
|
| 140 |
+
# Example: Which state/country's law governs the interpretation of the contract?
|
| 141 |
+
# =========
|
| 142 |
+
# Content: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an injunction or other relief to protect its Intellectual Property Rights.
|
| 143 |
+
# Source: htps://agreement.com/page1
|
| 144 |
+
# Content: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other) right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any kind between the parties.
|
| 145 |
+
# Source: htps://agreement.com/page2
|
| 146 |
+
# =========
|
| 147 |
+
# FINAL ANSWER: This Agreement is governed by English law.
|
| 148 |
+
# SOURCES: - htps://agreement.com/page1, - htps://agreement.com/page2
|
| 149 |
+
# Note: Return all the source URLs present within the sources.
|
| 150 |
+
|
| 151 |
+
# Question: {question}
|
| 152 |
+
# Source:
|
| 153 |
+
# ---------------------
|
| 154 |
+
# {summaries}
|
| 155 |
+
# ---------------------
|
| 156 |
+
|
| 157 |
+
# The sources above are NOT related to the conversation with the user. Ignore the sources if user is engaging in small talk.
|
| 158 |
+
# DO NOT return any sources if the conversation is just chit-chat/small talk. Return ALL the source URLs if conversation is not small talk.
|
| 159 |
+
|
| 160 |
+
# Chat History:
|
| 161 |
+
# {chat_history}
|
| 162 |
+
# """
|
app/requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chainlit
|
| 2 |
+
langchain
|
| 3 |
+
openai
|
| 4 |
+
pinecone-client
|
| 5 |
+
cohere
|
| 6 |
+
tiktoken
|
| 7 |
+
context-python
|
| 8 |
+
promptwatch
|
app/spark.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from langchain.embeddings.cohere import CohereEmbeddings
|
| 3 |
+
from langchain.vectorstores import Pinecone
|
| 4 |
+
from langchain.chains import ConversationalRetrievalChain, LLMChain
|
| 5 |
+
from langchain.chat_models import ChatOpenAI
|
| 6 |
+
import pinecone
|
| 7 |
+
import chainlit as cl
|
| 8 |
+
from langchain.memory import ConversationTokenBufferMemory
|
| 9 |
+
from langchain.prompts import (
|
| 10 |
+
ChatPromptTemplate,
|
| 11 |
+
PromptTemplate,
|
| 12 |
+
SystemMessagePromptTemplate,
|
| 13 |
+
HumanMessagePromptTemplate,
|
| 14 |
+
)
|
| 15 |
+
from langchain.prompts.prompt import PromptTemplate
|
| 16 |
+
from langchain.chains.qa_with_sources import load_qa_with_sources_chain
|
| 17 |
+
from langchain.callbacks import get_openai_callback
|
| 18 |
+
from langchain.retrievers import ContextualCompressionRetriever
|
| 19 |
+
from langchain.retrievers.document_compressors import CohereRerank
|
| 20 |
+
from chainlit import user_session
|
| 21 |
+
from prompts import load_query_gen_prompt, load_spark_prompt
|
| 22 |
+
from chainlit import on_message, on_chat_start
|
| 23 |
+
import openai
|
| 24 |
+
from langchain.callbacks import ContextCallbackHandler
|
| 25 |
+
from promptwatch import PromptWatch
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
index_name = "test-index-2"
|
| 29 |
+
|
| 30 |
+
spark = load_spark_prompt()
|
| 31 |
+
query_gen_prompt = load_query_gen_prompt()
|
| 32 |
+
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(query_gen_prompt)
|
| 33 |
+
pinecone.init(
|
| 34 |
+
api_key=os.environ.get("PINECONE_API_KEY"),
|
| 35 |
+
environment='gcp-starter',
|
| 36 |
+
)
|
| 37 |
+
@on_chat_start
|
| 38 |
+
def init():
|
| 39 |
+
token = os.environ["CONTEXT_TOKEN"]
|
| 40 |
+
context_callback = ContextCallbackHandler(token)
|
| 41 |
+
llm = ChatOpenAI(temperature=0.0, verbose=True, openai_api_key = os.environ.get("OPENAI_API_KEY"), streaming=True,
|
| 42 |
+
model_name='gpt-3.5-turbo',
|
| 43 |
+
callbacks=[context_callback])
|
| 44 |
+
memory = ConversationTokenBufferMemory(llm=llm,memory_key="chat_history", return_messages=True,input_key='question',max_token_limit=1000)
|
| 45 |
+
embeddings = CohereEmbeddings(model='embed-english-light-v2.0',cohere_api_key=os.environ.get("COHERE_API_KEY"))
|
| 46 |
+
|
| 47 |
+
docsearch = Pinecone.from_existing_index(
|
| 48 |
+
index_name=index_name, embedding=embeddings
|
| 49 |
+
)
|
| 50 |
+
retriever = docsearch.as_retriever(search_kwargs={"k": 4})
|
| 51 |
+
|
| 52 |
+
messages = [SystemMessagePromptTemplate.from_template(spark)]
|
| 53 |
+
|
| 54 |
+
messages.append(HumanMessagePromptTemplate.from_template("{question}"))
|
| 55 |
+
prompt = ChatPromptTemplate.from_messages(messages)
|
| 56 |
+
|
| 57 |
+
question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT, verbose=True)
|
| 58 |
+
doc_chain = load_qa_with_sources_chain(llm, chain_type="stuff", verbose=True,prompt=prompt)
|
| 59 |
+
|
| 60 |
+
chain = ConversationalRetrievalChain(
|
| 61 |
+
retriever=retriever,
|
| 62 |
+
question_generator=question_generator,
|
| 63 |
+
combine_docs_chain=doc_chain,
|
| 64 |
+
verbose=True,
|
| 65 |
+
memory=memory,
|
| 66 |
+
rephrase_question=False,
|
| 67 |
+
callbacks=[context_callback]
|
| 68 |
+
)
|
| 69 |
+
cl.user_session.set("conversation_chain", chain)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@on_message
|
| 73 |
+
async def main(message: str):
|
| 74 |
+
with PromptWatch(api_key=os.environ.get("PROMPTWATCH_KEY")) as pw:
|
| 75 |
+
token = os.environ["CONTEXT_TOKEN"]
|
| 76 |
+
context_callback = ContextCallbackHandler(token)
|
| 77 |
+
chain = cl.user_session.get("conversation_chain")
|
| 78 |
+
res = await chain.arun({"question": message},callbacks=[cl.AsyncLangchainCallbackHandler(),
|
| 79 |
+
context_callback])
|
| 80 |
+
# Send the answer and the text elements to the UI
|
| 81 |
+
await cl.Message(content=res).send()
|
chainlit.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Welcome to SIM Chatbot! π€
|
| 2 |
+
|
| 3 |
+
Hi there! π
|
| 4 |
+
|
| 5 |
+
SIM Chatbot is your troubleshooting Assistant. I'm here to help you find solutions to your technical problems π»π
|
| 6 |
+
|
| 7 |
+
Whether you need help troubleshooting a server, CCTV, repeater, and any kind of IT and radio communications devices, I've got you covered.
|
| 8 |
+
### Data Sources π
|
| 9 |
+
SIM Chatbot has access to the following sources:
|
| 10 |
+
- **CCTV:** [User manuals and troubleshooting guides from various brands (Hikvision, ...)](https://drive.google.com/drive/folders/1AxFIZoOSfB5O-EInY6f35eRPuTBD4YKG?usp=sharing)
|
| 11 |
+
- **HT:** [User manuals and troubleshooting guides from various brands (Motorola, Hytera, ...)](https://drive.google.com/drive/folders/1R0SLFhjT8rcZ-79qhdgaYvVMXcBl9FOw?usp=drive_link)
|
| 12 |
+
- **Server:** [User manuals and troubleshooting guides from various brands (Dell, HP, Motorola, ...)](https://drive.google.com/drive/folders/12ukSZ619fbpoXmQG03bXP3_Zl67BuVek?usp=sharing)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Feel free to ask any questions, seek guidance, or best practices to your IT and radio communications devices!
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '1'
|
| 2 |
+
services:
|
| 3 |
+
spark:
|
| 4 |
+
image: spark:latest
|
| 5 |
+
build: ./app
|
| 6 |
+
command: chainlit run app/spark.py
|
| 7 |
+
volumes:
|
| 8 |
+
- ./app/:/app/app
|
| 9 |
+
ports:
|
| 10 |
+
- 8000:8000
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.poetry]
|
| 2 |
+
name = "spark"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = ""
|
| 5 |
+
authors = ["Amogh Agastya <hello@amagastya.com>"]
|
| 6 |
+
readme = "README.md"
|
| 7 |
+
|
| 8 |
+
[tool.poetry.dependencies]
|
| 9 |
+
python = "^3.9"
|
| 10 |
+
chainlit = "0.6.0"
|
| 11 |
+
langchain = "^0.0.234"
|
| 12 |
+
openai = "^0.27.8"
|
| 13 |
+
pinecone-client = "^2.2.2"
|
| 14 |
+
cohere = "^4.13.1"
|
| 15 |
+
tiktoken = "^0.4.0"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
[build-system]
|
| 19 |
+
requires = ["poetry-core"]
|
| 20 |
+
build-backend = "poetry.core.masonry.api"
|