Commit fac2c742 by 范立洲

feat: add intent and chatgpt

parent 7d4baa0f
yunheBot-Jie2ooj2
FROM python:3.9-slim AS compile-image
RUN apt-get upgrade & \
apt-get install -y --no-install-recommends build-essential gcc & \
python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
FROM python:3.9-slim AS build-image
COPY --from=compile-image /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH" FLASK_ENV="PRD"
WORKDIR /yuheBot
COPY ./src/ .
CMD ["gunicorn","-w","4","-b","0.0.0.0:9000","--log-level=info","--access-logfile","./log/access.log","--error-logfile","./log/error.log","wsgi:app"]
[base] [base]
secret_key=asdfzxcv secret_key=asdfzxcv
debug=true debug=false
host=0.0.0.0 host=0.0.0.0
port=9000 port=9000
[openai]
api_key=qwertyuiopasdfghjkl
temperature=0.7
[qdrant] [qdrant]
qdrant_host=127.0.0.1 qdrant_host=127.0.0.1
qdrant_port=6333 qdrant_port=6333
qdrant_collection=test
[openai] [qa]
api_key=qwertyuiopasdfghjkl score=0.8
limit=3
collection=qa
[yhbot] [intent]
park_score=0.8 score=0.8
limit=3
collection=intent
...@@ -174,22 +174,22 @@ files = [ ...@@ -174,22 +174,22 @@ files = [
[[package]] [[package]]
name = "attrs" name = "attrs"
version = "22.2.0" version = "23.1.0"
description = "Classes Without Boilerplate" description = "Classes Without Boilerplate"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.6" python-versions = ">=3.7"
files = [ files = [
{file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, {file = "attrs-23.1.0-py3-none-any.whl", hash = "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04"},
{file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, {file = "attrs-23.1.0.tar.gz", hash = "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"},
] ]
[package.extras] [package.extras]
cov = ["attrs[tests]", "coverage-enable-subprocess", "coverage[toml] (>=5.3)"] cov = ["attrs[tests]", "coverage[toml] (>=5.3)"]
dev = ["attrs[docs,tests]"] dev = ["attrs[docs,tests]", "pre-commit"]
docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope.interface"] docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"]
tests = ["attrs[tests-no-zope]", "zope.interface"] tests = ["attrs[tests-no-zope]", "zope-interface"]
tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
[[package]] [[package]]
name = "cachetools" name = "cachetools"
...@@ -496,119 +496,100 @@ files = [ ...@@ -496,119 +496,100 @@ files = [
[[package]] [[package]]
name = "grpcio" name = "grpcio"
version = "1.53.0" version = "1.54.0"
description = "HTTP/2-based RPC framework" description = "HTTP/2-based RPC framework"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "grpcio-1.53.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:752d2949b40e12e6ad3ed8cc552a65b54d226504f6b1fb67cab2ccee502cc06f"}, {file = "grpcio-1.54.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:a947d5298a0bbdd4d15671024bf33e2b7da79a70de600ed29ba7e0fef0539ebb"},
{file = "grpcio-1.53.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:8a48fd3a7222be226bb86b7b413ad248f17f3101a524018cdc4562eeae1eb2a3"}, {file = "grpcio-1.54.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:e355ee9da9c1c03f174efea59292b17a95e0b7b4d7d2a389265f731a9887d5a9"},
{file = "grpcio-1.53.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:f3e837d29f0e1b9d6e7b29d569e2e9b0da61889e41879832ea15569c251c303a"}, {file = "grpcio-1.54.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:73c238ef6e4b64272df7eec976bb016c73d3ab5a6c7e9cd906ab700523d312f3"},
{file = "grpcio-1.53.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aef7d30242409c3aa5839b501e877e453a2c8d3759ca8230dd5a21cda029f046"}, {file = "grpcio-1.54.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1c59d899ee7160638613a452f9a4931de22623e7ba17897d8e3e348c2e9d8d0b"},
{file = "grpcio-1.53.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e6f90698b5d1c5dd7b3236cd1fa959d7b80e17923f918d5be020b65f1c78b173"}, {file = "grpcio-1.54.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48cb7af77238ba16c77879009003f6b22c23425e5ee59cb2c4c103ec040638a5"},
{file = "grpcio-1.53.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:a96c3c7f564b263c5d7c0e49a337166c8611e89c4c919f66dba7b9a84abad137"}, {file = "grpcio-1.54.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:2262bd3512ba9e9f0e91d287393df6f33c18999317de45629b7bd46c40f16ba9"},
{file = "grpcio-1.53.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:ee81349411648d1abc94095c68cd25e3c2812e4e0367f9a9355be1e804a5135c"}, {file = "grpcio-1.54.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:224166f06ccdaf884bf35690bf4272997c1405de3035d61384ccb5b25a4c1ca8"},
{file = "grpcio-1.53.0-cp310-cp310-win32.whl", hash = "sha256:fdc6191587de410a184550d4143e2b24a14df495c86ca15e59508710681690ac"}, {file = "grpcio-1.54.0-cp310-cp310-win32.whl", hash = "sha256:ed36e854449ff6c2f8ee145f94851fe171298e1e793f44d4f672c4a0d78064e7"},
{file = "grpcio-1.53.0-cp310-cp310-win_amd64.whl", hash = "sha256:658ffe1e39171be00490db5bd3b966f79634ac4215a1eb9a85c6cd6783bf7f6e"}, {file = "grpcio-1.54.0-cp310-cp310-win_amd64.whl", hash = "sha256:27fb030a4589d2536daec5ff5ba2a128f4f155149efab578fe2de2cb21596d3d"},
{file = "grpcio-1.53.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:1b172e6d497191940c4b8d75b53de82dc252e15b61de2951d577ec5b43316b29"}, {file = "grpcio-1.54.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:f4a7dca8ccd8023d916b900aa3c626f1bd181bd5b70159479b142f957ff420e4"},
{file = "grpcio-1.53.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:82434ba3a5935e47908bc861ce1ebc43c2edfc1001d235d6e31e5d3ed55815f7"}, {file = "grpcio-1.54.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:1209d6b002b26e939e4c8ea37a3d5b4028eb9555394ea69fb1adbd4b61a10bb8"},
{file = "grpcio-1.53.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:1c734a2d4843e4e14ececf5600c3c4750990ec319e1299db7e4f0d02c25c1467"}, {file = "grpcio-1.54.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:860fcd6db7dce80d0a673a1cc898ce6bc3d4783d195bbe0e911bf8a62c93ff3f"},
{file = "grpcio-1.53.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b6a2ead3de3b2d53119d473aa2f224030257ef33af1e4ddabd4afee1dea5f04c"}, {file = "grpcio-1.54.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3930669c9e6f08a2eed824738c3d5699d11cd47a0ecc13b68ed11595710b1133"},
{file = "grpcio-1.53.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a34d6e905f071f9b945cabbcc776e2055de1fdb59cd13683d9aa0a8f265b5bf9"}, {file = "grpcio-1.54.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62117486460c83acd3b5d85c12edd5fe20a374630475388cfc89829831d3eb79"},
{file = "grpcio-1.53.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:eaf8e3b97caaf9415227a3c6ca5aa8d800fecadd526538d2bf8f11af783f1550"}, {file = "grpcio-1.54.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:e3e526062c690517b42bba66ffe38aaf8bc99a180a78212e7b22baa86902f690"},
{file = "grpcio-1.53.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:da95778d37be8e4e9afca771a83424f892296f5dfb2a100eda2571a1d8bbc0dc"}, {file = "grpcio-1.54.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:ebff0738be0499d7db74d20dca9f22a7b27deae31e1bf92ea44924fd69eb6251"},
{file = "grpcio-1.53.0-cp311-cp311-win32.whl", hash = "sha256:e4f513d63df6336fd84b74b701f17d1bb3b64e9d78a6ed5b5e8a198bbbe8bbfa"}, {file = "grpcio-1.54.0-cp311-cp311-win32.whl", hash = "sha256:21c4a1aae861748d6393a3ff7867473996c139a77f90326d9f4104bebb22d8b8"},
{file = "grpcio-1.53.0-cp311-cp311-win_amd64.whl", hash = "sha256:ddb2511fbbb440ed9e5c9a4b9b870f2ed649b7715859fd6f2ebc585ee85c0364"}, {file = "grpcio-1.54.0-cp311-cp311-win_amd64.whl", hash = "sha256:3db71c6f1ab688d8dfc102271cedc9828beac335a3a4372ec54b8bf11b43fd29"},
{file = "grpcio-1.53.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:2a912397eb8d23c177d6d64e3c8bc46b8a1c7680b090d9f13a640b104aaec77c"}, {file = "grpcio-1.54.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:960b176e0bb2b4afeaa1cd2002db1e82ae54c9b6e27ea93570a42316524e77cf"},
{file = "grpcio-1.53.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:55930c56b8f5b347d6c8c609cc341949a97e176c90f5cbb01d148d778f3bbd23"}, {file = "grpcio-1.54.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:d8ae6e0df3a608e99ee1acafaafd7db0830106394d54571c1ece57f650124ce9"},
{file = "grpcio-1.53.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:6601d812105583948ab9c6e403a7e2dba6e387cc678c010e74f2d6d589d1d1b3"}, {file = "grpcio-1.54.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:c33744d0d1a7322da445c0fe726ea6d4e3ef2dfb0539eadf23dce366f52f546c"},
{file = "grpcio-1.53.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c705e0c21acb0e8478a00e7e773ad0ecdb34bd0e4adc282d3d2f51ba3961aac7"}, {file = "grpcio-1.54.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1d109df30641d050e009105f9c9ca5a35d01e34d2ee2a4e9c0984d392fd6d704"},
{file = "grpcio-1.53.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba074af9ca268ad7b05d3fc2b920b5fb3c083da94ab63637aaf67f4f71ecb755"}, {file = "grpcio-1.54.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:775a2f70501370e5ba54e1ee3464413bff9bd85bd9a0b25c989698c44a6fb52f"},
{file = "grpcio-1.53.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:14817de09317dd7d3fbc8272864288320739973ef0f4b56bf2c0032349da8cdf"}, {file = "grpcio-1.54.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c55a9cf5cba80fb88c850915c865b8ed78d5e46e1f2ec1b27692f3eaaf0dca7e"},
{file = "grpcio-1.53.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:c7ad9fbedb93f331c2e9054e202e95cf825b885811f1bcbbdfdc301e451442db"}, {file = "grpcio-1.54.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:1fa7d6ddd33abbd3c8b3d7d07c56c40ea3d1891ce3cd2aa9fa73105ed5331866"},
{file = "grpcio-1.53.0-cp37-cp37m-win_amd64.whl", hash = "sha256:dad5b302a4c21c604d88a5d441973f320134e6ff6a84ecef9c1139e5ffd466f6"}, {file = "grpcio-1.54.0-cp37-cp37m-win_amd64.whl", hash = "sha256:ed3d458ded32ff3a58f157b60cc140c88f7ac8c506a1c567b2a9ee8a2fd2ce54"},
{file = "grpcio-1.53.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:fa8eaac75d3107e3f5465f2c9e3bbd13db21790c6e45b7de1756eba16b050aca"}, {file = "grpcio-1.54.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:5942a3e05630e1ef5b7b5752e5da6582460a2e4431dae603de89fc45f9ec5aa9"},
{file = "grpcio-1.53.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:104a2210edd3776c38448b4f76c2f16e527adafbde171fc72a8a32976c20abc7"}, {file = "grpcio-1.54.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:125ed35aa3868efa82eabffece6264bf638cfdc9f0cd58ddb17936684aafd0f8"},
{file = "grpcio-1.53.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:dbc1ba968639c1d23476f75c356e549e7bbf2d8d6688717dcab5290e88e8482b"}, {file = "grpcio-1.54.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:b7655f809e3420f80ce3bf89737169a9dce73238af594049754a1128132c0da4"},
{file = "grpcio-1.53.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:95952d3fe795b06af29bb8ec7bbf3342cdd867fc17b77cc25e6733d23fa6c519"}, {file = "grpcio-1.54.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:87f47bf9520bba4083d65ab911f8f4c0ac3efa8241993edd74c8dd08ae87552f"},
{file = "grpcio-1.53.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f144a790f14c51b8a8e591eb5af40507ffee45ea6b818c2482f0457fec2e1a2e"}, {file = "grpcio-1.54.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:16bca8092dd994f2864fdab278ae052fad4913f36f35238b2dd11af2d55a87db"},
{file = "grpcio-1.53.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:0698c094688a2dd4c7c2f2c0e3e142cac439a64d1cef6904c97f6cde38ba422f"}, {file = "grpcio-1.54.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d2f62fb1c914a038921677cfa536d645cb80e3dd07dc4859a3c92d75407b90a5"},
{file = "grpcio-1.53.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6b6d60b0958be711bab047e9f4df5dbbc40367955f8651232bfdcdd21450b9ab"}, {file = "grpcio-1.54.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:a7caf553ccaf715ec05b28c9b2ab2ee3fdb4036626d779aa09cf7cbf54b71445"},
{file = "grpcio-1.53.0-cp38-cp38-win32.whl", hash = "sha256:1948539ce78805d4e6256ab0e048ec793956d54787dc9d6777df71c1d19c7f81"}, {file = "grpcio-1.54.0-cp38-cp38-win32.whl", hash = "sha256:2585b3c294631a39b33f9f967a59b0fad23b1a71a212eba6bc1e3ca6e6eec9ee"},
{file = "grpcio-1.53.0-cp38-cp38-win_amd64.whl", hash = "sha256:df9ba1183b3f649210788cf80c239041dddcb375d6142d8bccafcfdf549522cd"}, {file = "grpcio-1.54.0-cp38-cp38-win_amd64.whl", hash = "sha256:3b170e441e91e4f321e46d3cc95a01cb307a4596da54aca59eb78ab0fc03754d"},
{file = "grpcio-1.53.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:19caa5b7282a89b799e63776ff602bb39604f7ca98db6df27e2de06756ae86c3"}, {file = "grpcio-1.54.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:1382bc499af92901c2240c4d540c74eae8a671e4fe9839bfeefdfcc3a106b5e2"},
{file = "grpcio-1.53.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:b5bd026ac928c96cc23149e6ef79183125542062eb6d1ccec34c0a37e02255e7"}, {file = "grpcio-1.54.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:031bbd26656e0739e4b2c81c172155fb26e274b8d0312d67aefc730bcba915b6"},
{file = "grpcio-1.53.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:7dc8584ca6c015ad82e186e82f4c0fe977394588f66b8ecfc4ec873285314619"}, {file = "grpcio-1.54.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:a97b0d01ae595c997c1d9d8249e2d2da829c2d8a4bdc29bb8f76c11a94915c9a"},
{file = "grpcio-1.53.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2eddaae8af625e45b5c8500dcca1043264d751a6872cde2eda5022df8a336959"}, {file = "grpcio-1.54.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:533eaf5b2a79a3c6f35cbd6a095ae99cac7f4f9c0e08bdcf86c130efd3c32adf"},
{file = "grpcio-1.53.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c5fb6f3d7824696c1c9f2ad36ddb080ba5a86f2d929ef712d511b4d9972d3d27"}, {file = "grpcio-1.54.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49eace8ea55fbc42c733defbda1e4feb6d3844ecd875b01bb8b923709e0f5ec8"},
{file = "grpcio-1.53.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:8270d1dc2c98ab57e6dbf36fa187db8df4c036f04a398e5d5e25b4e01a766d70"}, {file = "grpcio-1.54.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:30fbbce11ffeb4f9f91c13fe04899aaf3e9a81708bedf267bf447596b95df26b"},
{file = "grpcio-1.53.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:976a7f24eb213e8429cab78d5e120500dfcdeb01041f1f5a77b17b9101902615"}, {file = "grpcio-1.54.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:650f5f2c9ab1275b4006707411bb6d6bc927886874a287661c3c6f332d4c068b"},
{file = "grpcio-1.53.0-cp39-cp39-win32.whl", hash = "sha256:9c84a481451e7174f3a764a44150f93b041ab51045aa33d7b5b68b6979114e48"}, {file = "grpcio-1.54.0-cp39-cp39-win32.whl", hash = "sha256:02000b005bc8b72ff50c477b6431e8886b29961159e8b8d03c00b3dd9139baed"},
{file = "grpcio-1.53.0-cp39-cp39-win_amd64.whl", hash = "sha256:6beb84f83360ff29a3654f43f251ec11b809dcb5524b698d711550243debd289"}, {file = "grpcio-1.54.0-cp39-cp39-win_amd64.whl", hash = "sha256:6dc1e2c9ac292c9a484ef900c568ccb2d6b4dfe26dfa0163d5bc815bb836c78d"},
{file = "grpcio-1.53.0.tar.gz", hash = "sha256:a4952899b4931a6ba12951f9a141ef3e74ff8a6ec9aa2dc602afa40f63595e33"}, {file = "grpcio-1.54.0.tar.gz", hash = "sha256:eb0807323572642ab73fd86fe53d88d843ce617dd1ddf430351ad0759809a0ae"},
] ]
[package.extras] [package.extras]
protobuf = ["grpcio-tools (>=1.53.0)"] protobuf = ["grpcio-tools (>=1.54.0)"]
[[package]] [[package]]
name = "grpcio-tools" name = "grpcio-tools"
version = "1.53.0" version = "1.54.0"
description = "Protobuf code generator for gRPC" description = "Protobuf code generator for gRPC"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "grpcio-tools-1.53.0.tar.gz", hash = "sha256:925efff2d63ca3266f93c924ffeba5d496f16a8ccbe125fa0d18acf47cc5fa88"}, {file = "grpcio_tools-1.54.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:7abdefb364de75d13d929093e571b84c4ea2580dbf5e4b6f5099ac9fa1a93f29"},
{file = "grpcio_tools-1.53.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:41b859cf943256debba1e7b921e3689c89f95495b65f7ad226c4f0e38edf8ee4"}, {file = "grpcio_tools-1.54.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:66738bc9d7b5db1a86832fa930cdd8faaf0c68bf70751d930c686d6bb309fad0"},
{file = "grpcio_tools-1.53.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:17c557240f7fbe1886dcfb5f3ba79740ecb65fe3b93061e64b8f4dfc6a6a5dc5"}, {file = "grpcio_tools-1.54.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:de07f7441e2f318a68631626d4d99c22244901ad7451a3e9fa08e5601a54772f"},
{file = "grpcio_tools-1.53.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:6afffd7e97e5bddc63b3ce9abe912b9adb704a36ba86d4406be94426734b97c2"}, {file = "grpcio_tools-1.54.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fb6774907a708079afb3deecdd8e053d2b2b066c279a5d8c4957687db3f809ce"},
{file = "grpcio_tools-1.53.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f55e2c13620271b7f5a81a489a188d6e34a24da8885d46f1566f0e798cb59e6f"}, {file = "grpcio_tools-1.54.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7615b824132fcea4769d0cd99bdeffe25b096b48215c36675f37f7b57dc09635"},
{file = "grpcio_tools-1.53.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6bd4c732d8d7a736e787b5d0963d4195267fc856e1d313d4532d1625e19a0e4a"}, {file = "grpcio_tools-1.54.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:22b826b1d0d98a3bb80094928e21c48e23d022168e91d466a21389d1cda87177"},
{file = "grpcio_tools-1.53.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:99ecefb6b66e9fe41468a70ee2f05da2eb9c7bf63867fb9ff07f7dd90ea813ae"}, {file = "grpcio_tools-1.54.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c03ceec6441365ec56c7fc6f38386917814ad02144dc1ecf03e13cee45f26389"},
{file = "grpcio_tools-1.53.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:7754d6466191d327a0eef364ad5b863477a8fcc12953adc06b30b8e470c70e4a"}, {file = "grpcio_tools-1.54.0-cp310-cp310-win32.whl", hash = "sha256:a61f367a153e3e604b1b59cec2f5e61255ffb6328d7348a53531e90ad98cc4fd"},
{file = "grpcio_tools-1.53.0-cp310-cp310-win32.whl", hash = "sha256:f31c549d793a0e72c044f724b3373141d2aa9970fe97b1c2cfaa7ea44002b9aa"}, {file = "grpcio_tools-1.54.0-cp310-cp310-win_amd64.whl", hash = "sha256:8a91f973b44fc90c32b7df79daec78907f0721e65d85fdff9133e05fee1f6e56"},
{file = "grpcio_tools-1.53.0-cp310-cp310-win_amd64.whl", hash = "sha256:b4173b95e2c29a5145c806d16945ce1e5b38a11c7eb6ab1a6d74afc0a2ce47d9"}, {file = "grpcio_tools-1.54.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:436335857731e8f0bc5d345804d7dcd1bc677a1f793ea2b22e0627870ea31df6"},
{file = "grpcio_tools-1.53.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:613a84ebd1881635370c12503f2b15b37332a53fbac32904c94ac4c0c10f0a2a"}, {file = "grpcio_tools-1.54.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:9fa42e3851c3c795228e2699c68ff7db14789991da4b53d3634360a361e0e420"},
{file = "grpcio_tools-1.53.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:af686b83bc6b5c1f1591c9f49183717974047de9546adcf5e09a18781b550c96"}, {file = "grpcio_tools-1.54.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:7ab23a94a8a7aa97ad8f46ba39ade4462c19833aa4815780db2cec647df7efef"},
{file = "grpcio_tools-1.53.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:3cc832e8297e9437bc2b137fe815c8ba1d9af6ffdd76c5c6d7f911bf8e1b0f45"}, {file = "grpcio_tools-1.54.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:12c3091ef09df47c20d698dc74a373c1674c67ac5ac12ef24433002165129556"},
{file = "grpcio_tools-1.53.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:39d0a254de49d852f5fe9f9df0a45b2ae66bc04e2d9ee1d6d2c0ba1e70fac91a"}, {file = "grpcio_tools-1.54.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:536c108ee8fa46b1ca8d03f4033cdf282741978f3f83dcc8b2a9e7a2b8197271"},
{file = "grpcio_tools-1.53.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7062109553ec1873c5c09cc379b8ae0aa76a2d6d6aae97759b97787b93fa9786"}, {file = "grpcio_tools-1.54.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:a66baf974aa00542ba4b6be499266ef8d63aa1abe7c78abab168bdf2fcd7f216"},
{file = "grpcio_tools-1.53.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:7728407b1e89fb1473b86152fc33be00f1a25a5aa3264245521f05cbbef9d817"}, {file = "grpcio_tools-1.54.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:b944c1654b5f0710e782c0e3462d7acca900cbf2fb874d62e51a5279293151a9"},
{file = "grpcio_tools-1.53.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:2758ea125442bc81251267fc9c28f65555a571f6a0afda4d71a6e7d669347095"}, {file = "grpcio_tools-1.54.0-cp311-cp311-win32.whl", hash = "sha256:f5aaa7e90e0947aec936e02fb85f312ca03c2258f3ee78403dcc27389fc62838"},
{file = "grpcio_tools-1.53.0-cp311-cp311-win32.whl", hash = "sha256:8940d59fca790f1bd45785d0661c3a8c081231c9f8049d7fbf6c6c00737e43da"}, {file = "grpcio_tools-1.54.0-cp311-cp311-win_amd64.whl", hash = "sha256:6ff318cd73b5cbdb16616d093c1c7b340d8d13b5bada2df7fbd873e899eab162"},
{file = "grpcio_tools-1.53.0-cp311-cp311-win_amd64.whl", hash = "sha256:c2cff79be5a06d63e9a6a7e38f8f160ade21517386eabe27afacef65a8531358"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:86169076170f835139db7ec8362124cabe8f01050c2a717500a0fcdeb71dc537"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:d646d65fafbf70a57416493e719a0df7ffa0772133266cfe1b2b72e072ae64a2"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:24158db60cdda7c9eb803a9ed033a23b4420fd13ba4c54392d6b396589afb969"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:7da0fc185735050d8240b1d74c4667a02baf1b4fa379a5fc05d1fc067eeba596"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:58d2cbbf4e40cecd09f4fa6a2c15f7a95ec90f492b4e31469d8c9db981426106"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:2be17265c0f070efd625683cef986e07dbc495103fcc719009ff2f6988003166"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1e15aa21a68cdb66b38db645924a09196cbbf4ad3ce1cf9dbcdf7b245292e380"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4701d48f649443f1101a24d85e9d5ac13346ccac7781e243f49491328e172266"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:23474a820bdf8126af93724c7f6b23b16d9f3ad4c4bdcb40936ecb7f2be6bcc7"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b54c64d85bea5c3a3d895454878c7d6bed5cbb80dc3cafcd75dc1e78300d8c95"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:8d2d5522d2222879c161479b5c91661cf788a3178f0b7532fd4c3e918e3390c4"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:7152045190e9bd665d1feaeaef931d82c75cacce2b116ab150befa90855de3d0"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:52b6f78f5601cd080e5456ec24fd960328f9962e9aa4f9f556ec6fd5e4a391bf"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:e18292123c86975d0aa47f1bcb176393640dcc23912e9f3a2247f1eff81ac8e8"}, {file = "grpcio_tools-1.54.0-cp37-cp37m-win_amd64.whl", hash = "sha256:292c0838d4a52ca53a941d197de57efc7f9df548d0619e14680c3e1ebeb33752"},
{file = "grpcio_tools-1.53.0-cp37-cp37m-win_amd64.whl", hash = "sha256:b1b76b6ab5c24e44b15d6a7df6c1b81c3099a54b82d41a3ce96e73a2e6a5081c"},
{file = "grpcio_tools-1.53.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:e76e8dfe6fe4e61ce3049e9d56c0d806d0d3edc28aa32117d1b17f387469c52e"},
{file = "grpcio_tools-1.53.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:4c6acaca09cfcd59850e27bd138df9d01c0686c42a5412aa6a92141c15316b1e"},
{file = "grpcio_tools-1.53.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:76898c1dadf8630a75a40b5a89ab38e326f1288dcfde3413cdfa7a58e149c987"},
{file = "grpcio_tools-1.53.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2b47f8b1bd3af2fb25548b625ad9c3659da30fe83c06f462f357c754f49b71ae"},
{file = "grpcio_tools-1.53.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a2faad4b6362e7ff3ae43ef2d51dfce0a3bc32cf52469e88568c3f65cae377d5"},
{file = "grpcio_tools-1.53.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:830261fe08541f0fd2dd5035264df2b91012988f37aa1d80a0b4ee6404dc25ae"},
{file = "grpcio_tools-1.53.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:4be32c694c760f3281555089f7aed7d48ca7ea4094115a08b5fc895e17d7e62e"},
{file = "grpcio_tools-1.53.0-cp38-cp38-win32.whl", hash = "sha256:4605db5a5828205d7fa33a5de9e00723bd037709e74e15c028b9dcec2339b7bc"},
{file = "grpcio_tools-1.53.0-cp38-cp38-win_amd64.whl", hash = "sha256:0229e6cd442915192b8f8ee2e7e1c8b9986c878bc4dd8be3539f3be35f1b8282"},
{file = "grpcio_tools-1.53.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:ad0c20688a650e731e8328a7a08899c433a59bfc995a7afcf715b5ad9eca9e7b"},
{file = "grpcio_tools-1.53.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:a8c3e30c531969c62a5a219be414277b269c1be9a76bcd6948571868894e19b2"},
{file = "grpcio_tools-1.53.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:326c67b35be69409a88632e6145032d53b8b8141634e9cbcd27fa8f9015a112c"},
{file = "grpcio_tools-1.53.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:102b6d323d7cef7ac29683f949ec66885b417c06df6059f6a88d07c5556c2592"},
{file = "grpcio_tools-1.53.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:861f8634cca3ca5bb5336ba16cc78291dba3e7fcadedff195bfdeb433f2c29f2"},
{file = "grpcio_tools-1.53.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:c9a9e1da1868349eba401e9648eac19132700942c475adcc97b6938bf4bf0182"},
{file = "grpcio_tools-1.53.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ccf7313e5bee13f2f86d12741489f3ed8c901d6b463dff2604191cd4ff518abb"},
{file = "grpcio_tools-1.53.0-cp39-cp39-win32.whl", hash = "sha256:65b77532bb8f6ab1bfbdd2ac0788626a6c05b227f4722d3bbc2c54258e49c3e5"},
{file = "grpcio_tools-1.53.0-cp39-cp39-win_amd64.whl", hash = "sha256:7c0ede22796259e83aa1f108038513e86672b2892d3654f94415e3930b74b871"},
] ]
[package.dependencies] [package.dependencies]
grpcio = ">=1.53.0" grpcio = ">=1.54.0"
protobuf = ">=4.21.6,<5.0dev" protobuf = ">=4.21.6,<5.0dev"
setuptools = "*" setuptools = "*"
......
aiohttp==3.8.4
aiosignal==1.3.1
aniso8601==9.0.1
anyio==3.6.2
async-timeout==4.0.2
attrs==23.1.0
cachetools==5.3.0
certifi==2022.12.7
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
colorama==0.4.6
distlib==0.3.6
filelock==3.11.0
Flask==2.2.3
Flask-RESTful==0.3.9
frozenlist==1.3.3
grpcio==1.54.0
grpcio-tools==1.54.0
gunicorn==20.1.0
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.17.0
httpx==0.24.0
hyperframe==6.0.1
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.17.3
MarkupSafe==2.1.2
multidict==6.0.4
numpy==1.24.2
openai==0.27.4
packaging==23.1
platformdirs==3.2.0
pluggy==1.0.0
protobuf==4.22.3
pydantic==1.10.7
pyproject_api==1.5.1
pyrsistent==0.19.3
pytz==2023.3
qdrant-client==1.1.4
requests==2.28.2
setuptools-scm==7.1.0
six==1.16.0
sniffio==1.3.0
tox==4.4.12
tqdm==4.65.0
typing_extensions==4.5.0
urllib3==1.26.15
virtualenv==20.21.0
Werkzeug==2.2.3
yarl==1.8.2
...@@ -49,12 +49,13 @@ package_dir = ...@@ -49,12 +49,13 @@ package_dir =
# For more information, check out https://semver.org/. # For more information, check out https://semver.org/.
install_requires = install_requires =
importlib-metadata importlib-metadata
Flask>=2.2.3 Flask==2.2.3
qdrant-client>=1.1.4 qdrant-client==1.1.4
openai>=0.27.4 openai==0.27.4
flask-restful>=0.3.9 flask-restful==0.3.9
click==8.1.3 click==8.1.3
jsonschema==4.17.3 jsonschema==4.17.3
gunicorn==20.1.0
[options.packages.find] [options.packages.find]
......
# coding=utf-8
#!/usr/bin/env python3
import os
import logging
from yunheBot.create_app import create_app
config_path = os.getenv("CONFIG")
if config_path is None or len(config_path) == 0:
config_path = "/etc/yunheBot/yhbot.ini"
app = create_app(config_path=config_path)
gunicorn_logger = logging.getLogger("gunicorn.error")
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
from flask import Blueprint from flask import Blueprint
from flask_restful import Api from flask_restful import Api
from .v1.industrial_park import IndustrialParkResource from .v1.completion import CompletionResource
rest_api_bp = Blueprint("api", __name__) rest_api_bp = Blueprint("api", __name__)
rest_api = Api(rest_api_bp) rest_api = Api(rest_api_bp)
rest_api.add_resource(IndustrialParkResource, "/v1/park", endpoint="park") rest_api.add_resource(CompletionResource, "/v1/completion", endpoint="completion")
# coding=utf-8
# import json
from flask_restful import Resource
from flask import current_app, request
from typing import Dict
from ...core.embedding import OpenAIEmbedding
from ...core.datasource import QDDataSource, OpenAIDataSource
from ...common import response, validator
from ...core.qa import QABot
from ...core.intent import IntentBot
from ...core.chatgpt import ChatGPTBot
from ...core import const
POST_SCHEMA = {
"type": "object",
"properties": {
"prompt": {"type": "string"},
"limit": {"type": "integer"},
"score": {"type": "integer"},
},
"required": ["prompt"],
}
class CompletionResource(Resource):
def __init__(self):
embedder = OpenAIEmbedding(current_app.config["OPENAI_API_KEY"])
qd_ds = QDDataSource(
current_app.config["QDRANT_HOST"],
current_app.config["QDRANT_PORT"],
)
openai_ds = OpenAIDataSource(
current_app.config["OPENAI_API_KEY"],
float(current_app.config["OPENAI_TEMPERATURE"]),
)
qa_score = float(current_app.config["QA_SCORE"])
qa_limit = int(current_app.config["QA_LIMIT"])
qa_collection = current_app.config["QA_COLLECTION"]
self.qa_bot = QABot(qd_ds, embedder, qa_collection, qa_score, qa_limit)
intent_score = float(current_app.config["INTENT_SCORE"])
intent_limit = int(current_app.config["INTENT_LIMIT"])
intent_collection = current_app.config["INTENT_COLLECTION"]
self.intent_bot = IntentBot(
qd_ds, embedder, intent_collection, intent_score, intent_limit
)
self.chatgpt_bot = ChatGPTBot(openai_ds)
@response.wrap_response
@validator.validator(POST_SCHEMA)
def post(self):
data = request.get_json(force=True)
# req: Dict = json.loads(data)
req: Dict = data
# 1. intent check
intent = self.intent_bot.complete(req["prompt"])
# 1.1 intent ==> qa
if intent is not None and intent.answer == const.INTENT_QA:
try:
answer = self.qa_bot.complete(**req)
if answer is None:
return response.NotFound("No Answer Found")
return response.OK("OK", answer.to_dict())
except Exception as e:
return response.InternalServerError(str(e))
# 1.2 intent ==> chatgpt
try:
resp = self.chatgpt_bot.complete(req["prompt"])
return response.OK("", resp.to_dict())
except Exception as e:
return response.InternalServerError(str(e))
# coding=utf-8
from flask_restful import Resource
from flask import current_app, request
from ...core.embedding import OpenAIEmbedding
from ...core.datasource import YHQdrantClient
from ...common import response, validator
POST_SCHEMA = {"type": "object", "properties": {"prompt": {"type": "string"}}}
class IndustrialParkResource(Resource):
def __init__(self):
self.embedder = OpenAIEmbedding(current_app.config["OPENAI_API_KEY"])
self.qd_client = YHQdrantClient(
current_app.config["QDRANT_HOST"],
current_app.config["QDRANT_PORT"],
self.embedder,
)
self.collection = current_app.config["QDRANT_COLLECTION"]
self.park_score = float(current_app.config["PARK_SCORE"])
@response.wrap_response
@validator.validator(POST_SCHEMA)
def post(self):
data = request.get_json(force=True)
prompt = data.get("prompt")
try:
raw_results = self.qd_client.search(
prompt=prompt,
collection_name=self.collection,
limit=3,
)
except Exception as e:
return response.InternalServerError(str(e))
results = [item for item in raw_results if item.score >= self.park_score]
if len(results) == 0:
return response.NotFound("No Answer Found")
answer = results[0].payload
return response.OK("", answer)
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
import click import click
import os import os
from yunheBot.create_app import create_app from .create_app import create_app
from yunheBot.core.embedding import OpenAIEmbedding from .core.embedding import OpenAIEmbedding
from yunheBot.core.datasource import YHQdrantClient from .core.datasource import QDDataSource
from .core.qa import QABot
from .core.intent import IntentBot
@click.group() @click.group()
...@@ -23,22 +25,33 @@ def server(conf): ...@@ -23,22 +25,33 @@ def server(conf):
@click.command() @click.command()
@click.option("--bot_type", type=str)
@click.option("--open_ai_key", type=str) @click.option("--open_ai_key", type=str)
@click.option("--db", type=str) @click.option("--db", type=str)
@click.option("--file", type=str) @click.option("--file", type=str)
@click.option("--collection", type=str) @click.option("--collection", type=str)
def upload(open_ai_key: str, db: str, filepath: str, collection: str): def upload(bot_type: str, open_ai_key: str, db: str, file: str, collection: str):
embdder = OpenAIEmbedding(open_ai_key) embedder = OpenAIEmbedding(open_ai_key)
qdrant_host, qdrant_port = db.split(":") qdrant_host, qdrant_port = db.split(":")
client = YHQdrantClient(qdrant_host, qdrant_port, embdder) qd_ds = QDDataSource(qdrant_host, qdrant_port)
if os.path.splitext(filepath)[1].lower() == ".csv": bot = None
client.create_collection(collection)
client.upload_csv(filepath, collection) if bot_type == "qa":
bot = QABot(qd_ds, embedder, collection, 0, 0)
elif bot_type == "intent":
bot = IntentBot(qd_ds, embedder, collection, 0, 0)
if bot is None:
print("--bot_type must be specificed as 'qa' or 'intent'")
if os.path.splitext(file)[1].lower() == ".csv":
bot.create_collection()
bot.upload_csv(file)
else: else:
print(f"{filepath} is not a CSV file.") print(f"{file} is not a CSV file.")
return return
cli.add_command(server) cli.add_command(server)
cli.add_command(upload) cli.add_command(upload)
# cli.add_command(intent)
...@@ -19,79 +19,24 @@ def setup_config(config_path): ...@@ -19,79 +19,24 @@ def setup_config(config_path):
new_config = { new_config = {
# base # base
"SECRET_KEY": conf.get("base", "secret_key"), # session加密 "SECRET_KEY": conf.get("base", "secret_key"), # session加密
# "PERMANENT_SESSION_LIFETIME": timedelta(days=30), # 设置session过期时间
"DEBUG": conf.getboolean("base", "debug"), "DEBUG": conf.getboolean("base", "debug"),
"HOST": conf.get("base", "host"), "HOST": conf.get("base", "host"),
"PORT": conf.getint("base", "port"), "PORT": conf.getint("base", "port"),
# qdrant # qdrant
"QDRANT_HOST": conf.get("qdrant", "qdrant_host"), "QDRANT_HOST": conf.get("qdrant", "qdrant_host"),
"QDRANT_PORT": conf.get("qdrant", "qdrant_port"), "QDRANT_PORT": conf.get("qdrant", "qdrant_port"),
"QDRANT_COLLECTION": conf.get("qdrant", "qdrant_collection"), # "QDRANT_COLLECTION": conf.get("qdrant", "qdrant_collection"),
# openai_api_key # openai_api_key
"OPENAI_API_KEY": conf.get("openai", "api_key"), "OPENAI_API_KEY": conf.get("openai", "api_key"),
"OPENAI_TEMPERATURE": conf.get("openai", "temperature"),
# yhbot # qa
"PARK_SCORE": conf.get("yhbot", "park_score") "QA_COLLECTION": conf.get("qa", "collection"),
"QA_SCORE": conf.get("qa", "score"),
"QA_LIMIT": conf.get("qa", "limit"),
# intent
"INTENT_COLLECTION": conf.get("intent", "collection"),
"INTENT_SCORE": conf.get("intent", "score"),
"INTENT_LIMIT": conf.get("intent", "limit"),
} }
base_config.update(new_config)
# class BaseConfig: base_config.update(new_config)
# """配置基类"""
#
# # SECRET_KEY = os.urandom(24)
# SECRET_KEY = "asdfzxcv" # session加密
# PERMANENT_SESSION_LIFETIME = timedelta(days=30) # 设置session过期时间
# DEBUG = True
# # SERVER_NAME = 'example.com'
# HOST = "0.0.0.0"
# PORT = 9000
#
# @staticmethod
# def init_app(app):
# pass
# class NewConfig(BaseConfig):
# """区分配置文件"""
#
# def __init__(self, config_path):
# self._conf = get_config(config_path)
#
#
# # base
# SECRET_KEY = self._conf.get("base", "secret_key") # session加密
# PERMANENT_SESSION_LIFETIME = timedelta(days=30) # 设置session过期时间
# DEBUG = self._conf.getboolean("base", "debug")
# HOST = self._conf.get("base", "host")
# PORT = self._conf.getint("base", "port")
#
# # qdrant
# QDRANT_HOST = self._conf.get("qdrant", "qdrant_host")
# QDRANT_PORT = self._conf.get("qdrant", "qdrant_port")
#
# # openai_api_key
# OPENAI_KEY = self._conf.get("openai", "api_key")
#
# # # mysql
# # MYSQL_USERNAME = conf.get("mysql", "USERNAME")
# # MYSQL_PASSWORD = conf.get("mysql", "PASSWORD")
# # MYSQL_HOSTNAME = conf.get("mysql", "HOSTNAME")
# # MYSQL_PORT = conf.getint("mysql", "PORT")
# # MYSQL_DATABASE = conf.get("mysql", "DATABASE")
# # DB_URI = "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
# # MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_HOSTNAME, MYSQL_PORT, MYSQL_DATABASE
# # )
# # SQLALCHEMY_DATABASE_URI = DB_URI
# # SQLALCHEMY_TRACK_MODIFICATIONS = True
#
# # # redis
# # redis_obj = {
# # "host": conf.get("redis", "REDIS_HOST"),
# # "port": conf.get("redis", "REDIS_PORT"),
# # "password": conf.get("redis", "REDIS_PWD"),
# # "decode_responses": conf.getboolean("redis", "DECODE_RESPONSES"),
# # "db": conf.getint("redis", "REDIS_DB"),
# # }
# # POOL = redis.ConnectionPool(**redis_obj)
# # R = redis.Redis(connection_pool=POOL)
# coding=utf-8
from .datasource import DataSource
from .common import BotPayload
class ChatGPTBot:
def __init__(self, data_source: DataSource):
self.data_source = data_source
def complete(self, prompt: str) -> BotPayload:
answer = self.data_source.search(prompt)
resp = {"question": prompt, "answer": answer}
return BotPayload.factory(**resp)
# coding=utf-8
class BotPayload:
@classmethod
def factory(cls, **kwargs):
return cls(
**{
key: value
for key, value in kwargs.items()
if not key.startswith("_") and not key.startswith("__")
}
)
def __init__(self, question: str, answer: str, **kwargs):
self.question = question
self.answer = answer
for k, v in kwargs.items():
setattr(self, k, v)
def to_dict(self):
return {
key: value
for key, value in self.__dict__.items()
if not key.startswith("_")
}
# coding=utf-8
INTENT_QA = 1
# coding=utf-8 # coding=utf-8
import csv import csv
import openai
from abc import abstractmethod, ABCMeta
from typing import List, Callable, Dict, Union
from qdrant_client import QdrantClient from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams from qdrant_client.http.models import Distance, VectorParams
from qdrant_client.http.models import PointStruct from qdrant_client.http.models import PointStruct
from .embedding import Embedding from .embedding import Embedding
from ..util import util
# from ..util import util
class DataSource(metaclass=ABCMeta):
@abstractmethod
def search(
self, collection: str, prompt: str, limit: int, **kwargs
) -> Union[List, str]:
pass
@util.singleton # @util.singleton
class YHQdrantClient: class QDDataSource:
def __init__(self, host: str, port: int, embedder: Embedding): def __init__(self, host: str, port: int):
self.client = QdrantClient(host=host, port=port) self.client = QdrantClient(host=host, port=port)
self.embedder = embedder
def create_collection( def create_collection(
self, collection: str, size: int = 1536, distance: Distance = Distance.COSINE self, collection: str, size: int = 1536, distance: Distance = Distance.COSINE
...@@ -33,7 +45,13 @@ class YHQdrantClient: ...@@ -33,7 +45,13 @@ class YHQdrantClient:
except Exception as e: except Exception as e:
raise e raise e
def upload_csv(self, filepath: str, collection: str): def upload_csv(
self,
collection: str,
embedder: Embedding,
filepath: str,
formatter: Callable[[List], Dict],
):
"""导入csv数据集 """导入csv数据集
Args: Args:
...@@ -43,28 +61,55 @@ class YHQdrantClient: ...@@ -43,28 +61,55 @@ class YHQdrantClient:
csv_reader = csv.reader(f) csv_reader = csv.reader(f)
count = 0 count = 0
for line in csv_reader: for line in csv_reader:
print(line) vec = embedder.get_vector(line[0])
item = self.embedder.to_embedding(line) print(line, vec)
print(item)
self.client.upsert( self.client.upsert(
collection_name=collection, collection_name=collection,
wait=True, wait=True,
points=[ points=[
PointStruct( PointStruct(
id=count, id=count,
vector=item[2], vector=vec,
payload={"title": item[0], "text": item[1]}, payload=formatter(line),
) )
], ],
) )
count += 1 count += 1
def search(self, prompt, collection_name, limit): def search(
vec = self.embedder.get_vector(prompt) self,
prompt: str,
limit: int,
embedder: Embedding = None,
collection: str = "",
) -> List:
if embedder is None:
raise ValueError("Embedding Object is None")
if collection is None or len(collection) == 0:
raise ValueError("Collection is None")
vec = embedder.get_vector(prompt)
results = self.client.search( results = self.client.search(
collection_name=collection_name, collection_name=collection,
query_vector=vec, query_vector=vec,
limit=limit, limit=limit,
search_params={"exact": False, "hnsw_ef": 128}, search_params={"exact": False, "hnsw_ef": 128},
) )
return results return results
class OpenAIDataSource:
def __init__(self, api_key: str, temperature: float):
self.api_key = api_key
self.temperature = temperature
openai.api_key = api_key
def search(self, prompt: str, limit: int = 0, model="gpt-3.5-turbo") -> str:
completion = openai.ChatCompletion.create(
temperature=self.temperature,
model=model,
messages=[{"role": "user", "content": prompt}],
)
return completion.choices[0].message.content
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
import openai import openai
from abc import abstractmethod, ABCMeta from abc import abstractmethod, ABCMeta
from typing import List, Tuple # from typing import List, Tuple
from ..util import util from ..util import util
class Embedding(metaclass=ABCMeta): class Embedding(metaclass=ABCMeta):
@abstractmethod # @abstractmethod
def generate_sample(self, items: List[str]) -> Tuple[str, str, float]: # def generate_sample(self, items: List[str]) -> Tuple[str, str, float]:
pass # pass
@abstractmethod @abstractmethod
def get_vector(self, prompt: str) -> float: def get_vector(self, prompt: str) -> float:
...@@ -18,9 +18,9 @@ class Embedding(metaclass=ABCMeta): ...@@ -18,9 +18,9 @@ class Embedding(metaclass=ABCMeta):
@util.singleton @util.singleton
class OpenAIEmbedding: class OpenAIEmbedding:
def __init__(self, open_ai_key): def __init__(self, api_key):
self.open_ai_key = open_ai_key self.open_ai_key = api_key
openai.api_key = open_ai_key openai.api_key = api_key
def _create_embedding(self, text): def _create_embedding(self, text):
sentence_embeddings = openai.Embedding.create( sentence_embeddings = openai.Embedding.create(
...@@ -28,10 +28,6 @@ class OpenAIEmbedding: ...@@ -28,10 +28,6 @@ class OpenAIEmbedding:
) )
return sentence_embeddings["data"][0]["embedding"] return sentence_embeddings["data"][0]["embedding"]
def generate_sample(self, items):
vec = self._create_embedding(items[1])
return [items[0], items[1], vec]
def get_vector(self, prompt): def get_vector(self, prompt):
vec = self._create_embedding(prompt) vec = self._create_embedding(prompt)
return vec return vec
# coding=utf-8
from collections import Counter
from typing import List, Dict
from .datasource import QDDataSource
from .embedding import Embedding
from .const import INTENT_QA
from .common import BotPayload
class IntentBot:
def __init__(
self,
data_source: QDDataSource,
embedder: Embedding,
collection: str,
score: float,
limit: int,
):
self.data_source = data_source
self.embdder = embedder
self.collection = collection
self.score = float(score)
self.limit = int(limit)
def create_collection(self):
"""创建数据集
Args:
size (int): 向量大小
distance (QdrantClient.Distance): 损失函数
"""
try:
self.data_source.create_collection(collection=self.collection)
except Exception as e:
raise e
def formatter(self, line: List) -> Dict:
# line format: 问题,答案(意图)
# return {"question": line[0], "answer": INTENT_QA}
return BotPayload(question=line[0], answer=INTENT_QA).to_dict()
def upload_csv(self, filepath: str):
"""导入csv数据集
Args:
filepath: 文件路径
"""
self.data_source.upload_csv(
self.collection, self.embdder, filepath, self.formatter
)
def complete(self, prompt: str) -> BotPayload:
points = self.data_source.search(
prompt,
self.limit,
embedder=self.embdder,
collection=self.collection,
)
print(points)
if points is None or len(points) == 0:
return None
payloads = [item.payload for item in points if item.score >= self.score]
if len(payloads) == 0:
return None
answers = [p["answer"] for p in payloads]
most_common_answer = Counter(answers).most_common(1)[0][0]
result = list(filter(lambda p: p["answer"] == most_common_answer, payloads))
return BotPayload.factory(**result[0])
# coding=utf-8
from typing import List, Dict
from .datasource import QDDataSource
from .embedding import Embedding
from .common import BotPayload
class QABot:
def __init__(
self,
data_source: QDDataSource,
embedder: Embedding,
collection: str,
score: int,
limit: int,
):
self.data_source = data_source
self.embdder = embedder
self.collection = collection
self.score = float(score)
self.limit = int(limit)
def create_collection(self):
"""创建数据集
Args:
size (int): 向量大小
distance (QdrantClient.Distance): 损失函数
"""
try:
self.data_source.create_collection(collection=self.collection)
except Exception as e:
raise e
def formatter(self, line: List) -> Dict:
# line format: 问题,答案,跳转类型
# return {"question": line[0], "answer": line[1], "type": line[2]}
# return {"question": line[0], "answer": line[1], "type": "demo"}
return BotPayload(question=line[0], answer=line[1], type="demo").to_dict()
def upload_csv(self, filepath: str):
"""导入csv数据集
Args:
filepath: 文件路径
"""
self.data_source.upload_csv(
self.collection, self.embdder, filepath, self.formatter
)
def complete(self, prompt: str, score: int = 0, limit: int = 0) -> BotPayload:
_limit = self.limit if limit == 0 else limit
_score = self.score if score == 0 else score
points = self.data_source.search(
prompt,
_limit,
embedder=self.embdder,
collection=self.collection,
)
if points is None or len(points) == 0:
return None
payloads = [item.payload for item in points if item.score >= _score]
if len(payloads) == 0:
return None
return BotPayload.factory(**payloads[0])
...@@ -6,7 +6,6 @@ from flask import Flask ...@@ -6,7 +6,6 @@ from flask import Flask
from .register.bp_register import register_blueprint from .register.bp_register import register_blueprint
from .register.conf_register import register_config from .register.conf_register import register_config
def create_app(*args, **kwargs): def create_app(*args, **kwargs):
app = Flask(__name__) app = Flask(__name__)
register_blueprint(app, *args, **kwargs) register_blueprint(app, *args, **kwargs)
......
...@@ -11,4 +11,3 @@ def register_config(app: Flask, *args, **kwargs): ...@@ -11,4 +11,3 @@ def register_config(app: Flask, *args, **kwargs):
setup_config(config_path) setup_config(config_path)
app.config.from_mapping(base_config) app.config.from_mapping(base_config)
# print(app.config)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论