diff --git a/.gitea/workflows/deploy_via_docker_compose.yml b/.gitea/workflows/deploy_via_docker_compose.yml index 18ea502..bf83165 100644 --- a/.gitea/workflows/deploy_via_docker_compose.yml +++ b/.gitea/workflows/deploy_via_docker_compose.yml @@ -14,18 +14,18 @@ jobs: password: ${{ secrets.PASSWORD }} port: ${{ secrets.PORT }} #script_stop: true + #requires stored git password: git config credential.helper store script: | - whoami - ls cd Ollama-Bot/deployment docker-compose down git pull - echo "Git pull finishes!" + echo "============ Git pull finished! =========" docker-compose build - echo "Image build finishes!" + echo "============= Image build finishes! ==============" docker-compose push - echo "Image push finishes!" + echo "============== Image push finishes! ===============" docker-compose up -d - echo "Docker compose deployment finished!!" - + echo "========== Docker compose deployment finished! ==============" + docker rmi $(docker images -f "dangling=true" -q) + echo "========== Docker dangling images cleanup finished! ==============" diff --git a/README.md b/README.md index d6a3543..5793598 100644 --- a/README.md +++ b/README.md @@ -30,32 +30,8 @@ After deploy: ```bash docker login registry.tobiasweise.dev docker-compose push - -#sudo docker tag llm-python-backend nucberlin:5123/llm-python-backend -#sudo docker push nucberlin:5123/llm-python-backend ``` ----- - -## Ideas - -### Knowledge graph creation - -https://www.linkedin.com/posts/sivas-subramaniyan_microsoft-research-is-bullish-on-the-concept-activity-7194953376470638592-dQ-U/?utm_source=share&utm_medium=member_desktop - - -clean dangling images - -sudo docker rmi $(sudo docker images -f "dangling=true" -q) - - - - -Give just the translation of the given input to German and nothing else. - - - - diff --git a/architecture.html b/architecture.html new file mode 100644 index 0000000..712b8a8 --- /dev/null +++ b/architecture.html @@ -0,0 +1,34 @@ + + +
+ + + + + + + + diff --git a/backend/Dockerfile b/backend/Dockerfile index 2657393..38993dd 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,6 +4,7 @@ RUN apt-get update RUN apt-get install -y firefox-esr RUN apt-get install -y ffmpeg RUN apt-get install -y espeak +RUN apt-get install -y flite #RUN curl https://ollama.ai/install.sh | sh #RUN ollama run llama2 diff --git a/backend/app.py b/backend/app.py index 9776bc8..5dca864 100644 --- a/backend/app.py +++ b/backend/app.py @@ -28,10 +28,13 @@ from langchain.callbacks.base import BaseCallbackHandler, BaseCallbackManager from langchain.prompts import PromptTemplate from langchain_community.llms import Ollama -from langchain_community.vectorstores.elasticsearch import ElasticsearchStore from langchain_community.document_loaders import PyPDFLoader, Docx2txtLoader from langchain_community.embeddings import OllamaEmbeddings +#from langchain_community.vectorstores.elasticsearch import ElasticsearchStore #deprecated +from langchain_elasticsearch import ElasticsearchStore +from uuid import uuid4 + from elasticsearch import NotFoundError, Elasticsearch # for normal read/write without vectors from elasticsearch_dsl import Search, A, Document, Date, Integer, Keyword, Float, Long, Text, connections from elasticsearch.exceptions import ConnectionError @@ -53,13 +56,11 @@ from cryptography.fernet import Fernet from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC -import pyttsx3 - #----------home grown-------------- #from scraper import WebScraper from funcs import group_by from elastictools import get_by_id, update_by_id, delete_by_id -from models import QueryLog, Chatbot, User +from models import QueryLog, Chatbot, User, Text #LLM_PAYLOAD = int(os.getenv("LLM_PAYLOAD")) @@ -264,11 +265,6 @@ def handle_message(message): - -def create_embedding(): - pass - - def hash_password(s: str) -> str: return hashlib.md5(s.encode('utf-8')).hexdigest() @@ -333,57 +329,16 @@ def login(form: LoginRequest): #-----bot routes------ +from speech import text_to_speech + class GetSpeechRequest(BaseModel): text: str = Field(None, description="Some text to convert to mp3") @app.post('/text2speech', summary="", tags=[], security=security) -@uses_jwt() -def text2speech(form: GetSpeechRequest, decoded_jwt, user): - engine = pyttsx3.init() - - def get_voice(s): - for v in engine.getProperty("voices"): - if s == v.id: - return v - - def set_voice(v): - engine.setProperty("voice", v.id) - - def set_volume(n): - engine.setProperty('volume', engine.getProperty('volume') + n) - - def set_rate(n): - engine.setProperty('rate', engine.getProperty('rate') + n) - - #voices = engine.getProperty('voices') - #engine.setProperty('voice', voices[1].id) - set_voice(get_voice("english")) - set_volume(-5.0) - set_rate(-40) - - #espeak -v mb-en1 -s 120 "Hello world" - #sudo apt-get install mbrola mbrola-en1 - - unix_timestamp = datetime.now().timestamp() - file_name = f'speech_{unix_timestamp}.mp3' - file_path = f'./public/{file_name}' - - engine.save_to_file(form.text, file_path) - engine.runAndWait() - - timeout = 10 - t = 0 - step = 0.1 - while not os.path.isfile(file_path): - time.sleep(step) - t += step - if t > timeout: - raise Exception("Timeout(%s s) for creating speech.mp3!" % timeout) - - time.sleep(step) - +def text2speech(form: GetSpeechRequest): + file_name = text_to_speech(form.text) #return send_file(file_path, mimetype='audio/mpeg') #, attachment_filename= 'Audiofiles.zip', as_attachment = True) return jsonify({ @@ -393,9 +348,6 @@ def text2speech(form: GetSpeechRequest, decoded_jwt, user): - - - class GetBotRequest(BaseModel): id: str = Field(None, description="The bot's id") @@ -514,44 +466,154 @@ def update_bot(form: UpdateBotRequest, decoded_jwt, user): return "" + + class AskBotRequest(BaseModel): bot_id: str = Field(None, description="The bot's id") question: str = Field(None, description="The question the bot should answer") + + @app.get('/bot/ask', summary="", tags=[bot_tag], security=security) @uses_jwt() def query_bot(query: AskBotRequest, decoded_jwt, user): """ Asks a chatbot """ - r = "" - for chunk in ask_bot(question=query.question, bot_id=query.bot_id): - r += chunk + start = datetime.now().timestamp() + + bot_id = query.bot_id + prompt = query.question + + + history = "" + + system_prompt = "Antworte freundlich, mit einer ausführlichen Erklärung, sofern vorhanden auf Basis der folgenden Informationen. Please answer in the language of the question." + + + prompt_template = system_prompt +""" +