first try to integrate frontend with backend

This commit is contained in:
Adrian Charkiewicz 2023-05-22 23:05:09 +02:00
parent 0d3b7d0a31
commit 1fd23bcf82
5 changed files with 46 additions and 109 deletions

View File

@ -1,35 +0,0 @@
# .coveragerc to control coverage.py
[run]
branch = False
source = src
omit =
*/tests/*
*/assets/*
*/src/styles/*
*/__init__.py
disable_warnings = include-ignored
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
def __str__
def main
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
show_missing = True

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "AMUseBot"]
path = AMUseBot
url = https://git.wmi.amu.edu.pl/s478831/AMUseBot

View File

@ -1,74 +0,0 @@
default_language_version:
python: python3.10.10
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: [ ]
submodules: false
default_stages: [ commit, push ]
files: ^(ai_talks/)
exclude_types: [ css, toml, template ]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: detect-private-key
- id: requirements-txt-fixer
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-toml
- id: check-xml
- id: debug-statements
- id: destroyed-symlinks
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: name-tests-test
- id: check-docstring-first
- id: check-json
- id: check-yaml
args: [ --unsafe ]
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.262
hooks:
- id: ruff
exclude: ^tests/
# args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.2
hooks:
- id: validate-pyproject
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-mock-methods
- id: python-use-type-annotations
- id: python-check-blanket-noqa
- id: python-use-type-annotations
- id: text-unicode-replacement-char
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.2.0
# hooks:
# - id: mypy
# additional_dependencies: [ types-PyYAML==6.0.10, types_requests==2.28.8, types-ujson==5.6.0 ]
# args: [ --ignore-missing-imports, --warn-no-return, --warn-redundant-casts, --disallow-incomplete-defs ]
# exclude: ^setup.py

1
AMUseBot Submodule

@ -0,0 +1 @@
Subproject commit 01d547dc221b2bd81ccbe24da37b792e9b176b37

View File

@ -4,10 +4,18 @@ from random import randrange, choices
import streamlit as st import streamlit as st
from openai.error import InvalidRequestError, OpenAIError from openai.error import InvalidRequestError, OpenAIError
from streamlit_chat import message from streamlit_chat import message
from AMUseBot.src.DP.dp import DP
from AMUseBot.src.DST.dst import DST
from AMUseBot.src.NLU.nlu import NLU
from .agi.chat_gpt import create_gpt_completion from .agi.chat_gpt import create_gpt_completion
from .stt import show_voice_input from .stt import show_voice_input
from .tts import show_audio_player from .tts import show_audio_player
import os
absolute_path = os.path.dirname(__file__)
def clear_chat() -> None: def clear_chat() -> None:
st.session_state.generated = [] st.session_state.generated = []
@ -55,6 +63,40 @@ def show_chat(ai_content: str, user_text: str) -> None:
message(st.session_state.generated[i], key=str(i), seed=st.session_state.seed) message(st.session_state.generated[i], key=str(i), seed=st.session_state.seed)
def amuseAPI():
recipe_path = os.path.join(absolute_path, "recipe")
dialog_path = os.path.join(absolute_path, "dialog")
# initial modules
dst = DST(recipe_path=recipe_path, dialog_path=dialog_path)
dp = DP(dst=dst)
nlu = NLU(intent_dict_path=os.path.join(absolute_path, 'utils/intent_dict.json'),
model_identifier_path=os.path.join(absolute_path, 'models/NLU/roberta-base-cookdial.txt'))
intent = None
system_message = None
dst.restart()
system_message = dp.generate_response(intent)
user_message = input()
if "restart" == user_message.lower():
break
intents = nlu.predict(user_message)
# print("intent ", intent)
dst.update_dialog_history(
system_message=system_message,
user_message=user_message,
intents=intents,
)
system_message = dp.generate_response(intents)
def show_conversation() -> None: def show_conversation() -> None:
if st.session_state.messages: if st.session_state.messages:
st.session_state.messages.append({"role": "user", "content": st.session_state.user_text}) st.session_state.messages.append({"role": "user", "content": st.session_state.user_text})