From a7b94ed107ffb5fe11c1825c2fdcad5c62a13217 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 16:30:47 +0400 Subject: [PATCH 01/24] First commit --- .gitignore | 2 +- LICENSE | 2 +- README.md | 8 ++------ app.py | 1 + requirements.txt | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 894a44cc0..7db61e6d0 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,4 @@ venv.bak/ /site # mypy -.mypy_cache/ +.mypy_cache/ \ No newline at end of file diff --git a/LICENSE b/LICENSE index 91f8bc944..cf627291e 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 42553ee66..7c36ad01d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # README -This is the [Flask](http://flask.pocoo.org/) [quick start](http://flask.pocoo.org/docs/1.0/quickstart/#a-minimal-application) example for [Render](https://render.com). +This is the [Flask](http://flask.pocoo.org/) API for IAGORA. -The app in this repo is deployed at [https://flask.onrender.com](https://flask.onrender.com). - -## Deployment - -Follow the guide at https://render.com/docs/deploy-flask. +The app in this repo is deployed at [https://iagora.onrender.com/](https://iagora.onrender.com/). \ No newline at end of file diff --git a/app.py b/app.py index d82c51f0d..ee63902f1 100644 --- a/app.py +++ b/app.py @@ -4,3 +4,4 @@ @app.route('/') def hello_world(): return 'Hello, World!' + diff --git a/requirements.txt b/requirements.txt index 147ddd086..ba2f6e279 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Flask -Gunicorn +Gunicorn \ No newline at end of file From e4b604e1b6acdd95e11c3c1be8633947d28b0c92 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 17:56:34 +0400 Subject: [PATCH 02/24] [API] create /ask communicate with OpenAI API --- app.py | 8 +++++++- models/__init__.py | 0 models/keymodel.py | 10 ++++++++++ models/txtmodel.py | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 models/__init__.py create mode 100644 models/keymodel.py create mode 100644 models/txtmodel.py diff --git a/app.py b/app.py index ee63902f1..b888ead03 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,13 @@ -from flask import Flask +from flask import Flask, request app = Flask(__name__) +from models import txtmodel + @app.route('/') def hello_world(): return 'Hello, World!' +@app.route("/ask", methods=["POST"]) +def ask(): + question = request.get_json() + return (txtmodel.txtmodel.get_response(question['query'])) \ No newline at end of file diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/models/keymodel.py b/models/keymodel.py new file mode 100644 index 000000000..570c52636 --- /dev/null +++ b/models/keymodel.py @@ -0,0 +1,10 @@ +import os + +class KeyModel: + def load_openai_api_key(): + # Charge le fichier .env + with open(".env", "r") as f: + env = f.read() + + # Récupère la clé API OpenAI + return os.environ.get("OPENAI_API_KEY", "") diff --git a/models/txtmodel.py b/models/txtmodel.py new file mode 100644 index 000000000..a3b306309 --- /dev/null +++ b/models/txtmodel.py @@ -0,0 +1,13 @@ +from langchain.llms import OpenAI +from langchain.chat_models import ChatOpenAI + + +from langchain.chains import ConversationChain + +class txtmodel(): + + def get_response(question): + chat = ChatOpenAI() + + conversation = ConversationChain(llm=chat) + return conversation.run(question) From 907f23990443e444b0ee60b7e8c6227e1318dce1 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:17:39 +0400 Subject: [PATCH 03/24] update requirements.txt --- requirements.txt | 102 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index ba2f6e279..abaf3fee3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,100 @@ -Flask -Gunicorn \ No newline at end of file +aiohttp==3.8.3 +aiosignal==1.3.1 +alembic==1.12.0 +aniso8601==9.0.1 +anyio==3.7.1 +async-timeout==4.0.2 +attrs==22.2.0 +bardapi==0.1.23a0 +beautifulsoup4==4.12.2 +blinker==1.6.2 +cachetools==4.2.4 +certifi==2022.12.7 +charset-normalizer==2.1.1 +click==8.1.6 +colorama==0.4.6 +dataclasses-json==0.5.14 +deep-translator==1.11.4 +dnspython==2.4.2 +email-validator==1.1.3 +exceptiongroup==1.1.2 +Flask==2.0.1 +Flask-Cors==4.0.0 +Flask-Login==0.5.0 +Flask-Migrate==3.1.0 +flask-restx==0.5.1 +Flask-SQLAlchemy==2.5.1 +Flask-WTF==0.15.1 +frozenlist==1.3.3 +google-api-core==1.34.0 +google-auth==1.35.0 +google-cloud-core==1.7.3 +google-cloud-translate==2.0.1 +googleapis-common-protos==1.59.1 +GoogleBard==1.4.0 +greenlet==2.0.2 +grpcio==1.56.0 +grpcio-status==1.48.2 +gunicorn==20.1.0 +h11==0.14.0 +h2==4.1.0 +hpack==4.0.0 +httpcore==0.17.3 +httpx==0.24.1 +hyperframe==6.0.1 +idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.0.1 +joblib==1.3.1 +jsonschema==4.19.0 +jsonschema-specifications==2023.7.1 +langchain==0.0.294 +langsmith==0.0.38 +Mako==1.2.4 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdurl==0.1.2 +multidict==6.0.4 +mypy-extensions==1.0.0 +numexpr==2.8.5 +numpy==1.25.1 +openai==0.28.0 +openapi-schema-pydantic==1.2.4 +packaging==23.1 +pandas==2.0.3 +prompt-toolkit==3.0.39 +protobuf==3.20.3 +pyasn1==0.5.0 +pyasn1-modules==0.3.0 +pydantic==1.10.12 +Pygments==2.15.1 +PyPDF2==3.0.1 +python-dateutil==2.8.2 +python-decouple==3.4 +python-dotenv==1.0.0 +pytz==2023.3 +PyYAML==6.0.1 +referencing==0.30.2 +requests==2.28.2 +rich==13.4.2 +rpds-py==0.10.0 +rsa==4.9 +scikit-learn==1.3.0 +scipy==1.11.1 +six==1.16.0 +sniffio==1.3.0 +socksio==1.0.0 +soupsieve==2.4.1 +SQLAlchemy==1.4.23 +tenacity==8.2.2 +threadpoolctl==3.2.0 +tqdm==4.64.1 +typing-inspect==0.9.0 +typing_extensions==4.7.1 +tzdata==2023.3 +urllib3==1.26.14 +wcwidth==0.2.6 +Werkzeug==2.3.6 +WTForms==2.3.3 +yarl==1.8.2 From ec96650371b3dc181fb9d4e897e03ec4c4176f5f Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:24:47 +0400 Subject: [PATCH 04/24] requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index abaf3fee3..aaf75ebc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ click==8.1.6 colorama==0.4.6 dataclasses-json==0.5.14 deep-translator==1.11.4 -dnspython==2.4.2 +dnspython==2.2.0 email-validator==1.1.3 exceptiongroup==1.1.2 Flask==2.0.1 From 1642164698297116c4a8b177c2df67e557943ad5 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:29:20 +0400 Subject: [PATCH 05/24] requirements --- req.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 req.txt diff --git a/req.txt b/req.txt new file mode 100644 index 000000000..e5fd79f74 --- /dev/null +++ b/req.txt @@ -0,0 +1,100 @@ +aiohttp==3.8.3 +aiosignal==1.3.1 +alembic==1.12.0 +aniso8601==9.0.1 +anyio==3.7.1 +async-timeout==4.0.2 +attrs==22.2.0 +bardapi==0.1.23a0 +beautifulsoup4==4.12.2 +blinker==1.6.2 +cachetools==4.2.4 +certifi==2022.12.7 +charset-normalizer==2.1.1 +click==8.1.6 +colorama==0.4.6 +dataclasses-json==0.5.14 +deep-translator==1.11.4 +dnspython==2.2.0 +email-validator==1.1.3 +exceptiongroup==1.1.2 +Flask==2.0.1 +Flask-Cors==4.0.0 +Flask-Login==0.5.0 +Flask-Migrate==3.1.0 +flask-restx==0.5.1 +Flask-SQLAlchemy==2.5.1 +Flask-WTF==0.15.1 +frozenlist==1.3.3 +google-api-core==1.34.0 +google-auth==1.35.0 +google-cloud-core==1.7.3 +google-cloud-translate==2.0.1 +googleapis-common-protos==1.59.1 +GoogleBard==1.4.0 +greenlet==2.0.2 +grpcio==1.56.0 +grpcio-status==1.48.2 +gunicorn==20.1.0 +h11==0.14.0 +h2==4.1.0 +hpack==4.0.0 +httpcore==0.17.3 +httpx==0.24.1 +hyperframe==6.0.1 +idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.0.1 +joblib==1.3.1 +jsonschema==4.17.3 +jsonschema-specifications==2023.7.1 +langchain==0.0.294 +langsmith==0.0.38 +Mako==1.2.4 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdurl==0.1.2 +multidict==6.0.4 +mypy-extensions==1.0.0 +numexpr==2.8.5 +numpy==1.25.1 +openai==0.28.0 +openapi-schema-pydantic==1.2.4 +packaging==23.1 +pandas==2.0.3 +prompt-toolkit==3.0.39 +protobuf==3.20.3 +pyasn1==0.5.0 +pyasn1-modules==0.3.0 +pydantic==1.10.12 +Pygments==2.15.1 +PyPDF2==3.0.1 +python-dateutil==2.8.2 +python-decouple==3.4 +python-dotenv==1.0.0 +pytz==2023.3 +PyYAML==6.0.1 +referencing==0.30.2 +requests==2.28.2 +rich==13.4.2 +rpds-py==0.10.0 +rsa==4.9 +scikit-learn==1.3.0 +scipy==1.11.1 +six==1.16.0 +sniffio==1.3.0 +socksio==1.0.0 +soupsieve==2.4.1 +SQLAlchemy==1.4.23 +tenacity==8.2.2 +threadpoolctl==3.2.0 +tqdm==4.64.1 +typing-inspect==0.9.0 +typing_extensions==4.7.1 +tzdata==2023.3 +urllib3==1.26.14 +wcwidth==0.2.6 +Werkzeug==2.3.6 +WTForms==2.3.3 +yarl==1.8.2 diff --git a/requirements.txt b/requirements.txt index aaf75ebc2..e5fd79f74 100644 --- a/requirements.txt +++ b/requirements.txt @@ -46,7 +46,7 @@ idna==3.4 itsdangerous==2.1.2 Jinja2==3.0.1 joblib==1.3.1 -jsonschema==4.19.0 +jsonschema==4.17.3 jsonschema-specifications==2023.7.1 langchain==0.0.294 langsmith==0.0.38 From 6e8044fa8fe22e5564e1b760ff7cd2fe72dba41c Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:30:45 +0400 Subject: [PATCH 06/24] requirements --- req.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/req.txt b/req.txt index e5fd79f74..ac1a3ca17 100644 --- a/req.txt +++ b/req.txt @@ -47,7 +47,7 @@ itsdangerous==2.1.2 Jinja2==3.0.1 joblib==1.3.1 jsonschema==4.17.3 -jsonschema-specifications==2023.7.1 +jsonschema-specifications==0.1.3 langchain==0.0.294 langsmith==0.0.38 Mako==1.2.4 diff --git a/requirements.txt b/requirements.txt index e5fd79f74..ac1a3ca17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,7 +47,7 @@ itsdangerous==2.1.2 Jinja2==3.0.1 joblib==1.3.1 jsonschema==4.17.3 -jsonschema-specifications==2023.7.1 +jsonschema-specifications==0.1.3 langchain==0.0.294 langsmith==0.0.38 Mako==1.2.4 From bbb10e24dd2280775b94236b2644c180105a91b7 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:32:30 +0400 Subject: [PATCH 07/24] requirements --- req.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/req.txt b/req.txt index ac1a3ca17..b169b52ca 100644 --- a/req.txt +++ b/req.txt @@ -48,7 +48,7 @@ Jinja2==3.0.1 joblib==1.3.1 jsonschema==4.17.3 jsonschema-specifications==0.1.3 -langchain==0.0.294 +langchain==0.0.27 langsmith==0.0.38 Mako==1.2.4 markdown-it-py==3.0.0 diff --git a/requirements.txt b/requirements.txt index ac1a3ca17..b169b52ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -48,7 +48,7 @@ Jinja2==3.0.1 joblib==1.3.1 jsonschema==4.17.3 jsonschema-specifications==0.1.3 -langchain==0.0.294 +langchain==0.0.27 langsmith==0.0.38 Mako==1.2.4 markdown-it-py==3.0.0 From 574a62655ffb72ed809874d43d4341738edf3a1b Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Tue, 19 Sep 2023 18:51:58 +0400 Subject: [PATCH 08/24] er --- requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index b169b52ca..abaf3fee3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ click==8.1.6 colorama==0.4.6 dataclasses-json==0.5.14 deep-translator==1.11.4 -dnspython==2.2.0 +dnspython==2.4.2 email-validator==1.1.3 exceptiongroup==1.1.2 Flask==2.0.1 @@ -46,9 +46,9 @@ idna==3.4 itsdangerous==2.1.2 Jinja2==3.0.1 joblib==1.3.1 -jsonschema==4.17.3 -jsonschema-specifications==0.1.3 -langchain==0.0.27 +jsonschema==4.19.0 +jsonschema-specifications==2023.7.1 +langchain==0.0.294 langsmith==0.0.38 Mako==1.2.4 markdown-it-py==3.0.0 From 547455944e234e524ae7264e4e86e76c04d590a5 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Wed, 20 Sep 2023 20:09:27 +0400 Subject: [PATCH 09/24] LLM --- app.py | 28 ++++++++- models/embedding.py | 9 +++ models/llm.py | 94 ++++++++++++++++++++++++++++++ models/prediction.py | 136 +++++++++++++++++++++++++++++++++++++++++++ models/scrapPdf.py | 30 ++++++++++ models/scrapUrl.py | 22 +++++++ 6 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 models/embedding.py create mode 100644 models/llm.py create mode 100644 models/prediction.py create mode 100644 models/scrapPdf.py create mode 100644 models/scrapUrl.py diff --git a/app.py b/app.py index b888ead03..ef37ac533 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,12 @@ from flask import Flask, request app = Flask(__name__) + +from flask import Response + +from models import llm from models import txtmodel +from models import prediction @app.route('/') def hello_world(): @@ -10,4 +15,25 @@ def hello_world(): @app.route("/ask", methods=["POST"]) def ask(): question = request.get_json() - return (txtmodel.txtmodel.get_response(question['query'])) \ No newline at end of file + return (txtmodel.txtmodel.get_response(question['query'])) + + +@app.route("/llm", methods=["POST"]) +def index(): + requete = request.get_json() + print(requete['q1']) + print(requete['url']) + #text = request.json["text"] + result = llm.Llm.callLlm(requete['q1'],requete['url']) + resp = Response(result) + resp.charset = "utf-8" + return resp + + +@app.route("/prediction", methods=["POST"]) +def prediction(): + question = request.get_json() + result = prediction.Prediction.callPrediction(question['q2']) + resp = Response(result) + resp.charset = "utf-8" + return resp diff --git a/models/embedding.py b/models/embedding.py new file mode 100644 index 000000000..653647523 --- /dev/null +++ b/models/embedding.py @@ -0,0 +1,9 @@ +import openai + +def get_embedding(text, model="text-embedding-ada-002"): + + # Get the embedding from the text embedding model. + embedding = openai.Embedding.create(input=[text], model=model)['data'][0]['embedding'] + + # Return the embedding. + return embedding \ No newline at end of file diff --git a/models/llm.py b/models/llm.py new file mode 100644 index 000000000..642b2ab7f --- /dev/null +++ b/models/llm.py @@ -0,0 +1,94 @@ +import requests +from bs4 import BeautifulSoup +import langchain +from langchain.embeddings.openai import OpenAIEmbeddings +from langchain.text_splitter import CharacterTextSplitter +from langchain.vectorstores import Chroma +from langchain.document_loaders import TextLoader +from langchain.text_splitter import RecursiveCharacterTextSplitter +from langchain.llms import OpenAI +from langchain import PromptTemplate + +from models import scrapPdf as sp +from models import scrapUrl as su + +from flask import Flask, request +from flask import jsonify + +class Llm: + def callLlm(user_question, url): + + if url.endswith(".pdf"): + scrap = sp.ScrapPdf.load_pdf_content(url) + print("URL "+scrap) + else: + scrap = su.ScrapUrl.scrapUrl(url) + print("URL "+scrap) + + # scapping text from PDF + # scrapP = sp.load_pdf_content("C:/Users/JerryHeritiana(RAPP)/OneDrive - OneWorkplace/Documents/IAGORA/FUNCHATGPTSerge.pdf") + # scrapP = sp.load_pdf_content("https://www.furet.com/media/pdf/feuilletage/9/7/8/2/8/0/4/1/9782804171018.pdf") + # scrapU = su.scrapUrl("https://en.wikipedia.org/wiki/GPT-4") + + text = scrap.replace('\n', '') + + # Open a new file called 'output.txt' in write mode and store the file object in a variable + with open('output.txt', 'w', encoding='utf-8') as file: + # Write the string to the file + file.write(text) + + # load the document + with open('./output.txt', encoding='utf-8') as f: + text = f.read() + + # define the text splitter + text_splitter = RecursiveCharacterTextSplitter( + chunk_size = 500, + chunk_overlap = 100, + length_function = len, + ) + + texts = text_splitter.create_documents([text]) + + # define the embeddings model + embeddings = OpenAIEmbeddings() + + # use the text chunks and the embeddings model to fill our vector store + db = Chroma.from_documents(texts, embeddings) + + # user_question = "C'est quoi chatGPT" + + # use our vector store to find similar text chunks + results = db.similarity_search( + query = user_question, + n_results=5 + ) + + # define the prompt template + template = """ + Tu es un chat bot qui aime aider les gens ! Compte tenu des sections contextuelles suivantes, répondez à la + question en utilisant uniquement le contexte donné. Si tu n'es pas sûr et que la réponse n'est pas + explicitement écrite dans la documentation, dites "Désolé, je ne sais pas comment vous aider." + + Context sections: + {context} + + Question: + {users_question} + + Answer: + """ + + prompt = PromptTemplate(template=template, input_variables=["context", "users_question"]) + + # fill the prompt template + prompt_text = prompt.format(context = results, users_question = user_question) + # print(prompt_text) + + # define the LLM you want to use + llm = OpenAI(temperature=1) + + # ask the defined LLM + result = llm(prompt_text) + print(result.encode("utf-8")) + return result.encode("utf-8") \ No newline at end of file diff --git a/models/prediction.py b/models/prediction.py new file mode 100644 index 000000000..b69530896 --- /dev/null +++ b/models/prediction.py @@ -0,0 +1,136 @@ +import joblib +import numpy as np +import pandas as pd + +from langchain import PromptTemplate +from langchain.llms import OpenAI +from langchain.text_splitter import RecursiveCharacterTextSplitter +from numpy.linalg import norm + +from models import scrapUrl as su +from models import scrapPdf as sp +from models import embedding as em + +from flask import Flask, request +from flask import jsonify + +class Prediction: + def callPrediction(user_question): + + # define the LLM you want to use + llm = OpenAI(temperature=1) + + feature_names = [ + 'HOURS_DATASCIENCE', + 'HOURS_BACKEND', + 'HOURS_FRONTEND', + 'HOURS_IA', + 'HOURS_BDD', + 'NUM_COURSES_BEGINNER_DATASCIENCE', + 'NUM_COURSES_BEGINNER_BACKEND', + 'NUM_COURSES_BEGINNER_FRONTEND', + 'NUM_COURSES_BEGINNER_IA', + 'NUM_COURSES_BEGINNER_BDD', + 'NUM_COURSES_ADVANCED_DATASCIENCE', + 'NUM_COURSES_ADVANCED_BACKEND', + 'NUM_COURSES_ADVANCED_FRONTEND', + 'NUM_COURSES_ADVANCED_IA', + 'NUM_COURSES_ADVANCED_BDD', + 'AVG_SCORE_DATASCIENCE', + 'AVG_SCORE_BACKEND', + 'AVG_SCORE_FRONTEND', + 'AVG_SCORE_IA', + 'AVG_SCORE_BDD', + 'NB_CLICKS_DATASCIENCE', + 'NB_CLICKS_BACKEND', + 'NB_CLICKS_FRONTEND', + 'NB_CLICKS_IA', + 'NB_CLICKS_BDD', + 'ORIENTATION'] + + + data_sample = [ + 10, # HOURS_DATASCIENCE + 5, # HOURS_BACKEND + 8, # HOURS_FRONTEND + 7, # HOURS_IA + 9, # HOURS_BDD + 2, # NUM_COURSES_BEGINNER_DATASCIENCE + 1, # NUM_COURSES_BEGINNER_BACKEND + 2, # NUM_COURSES_BEGINNER_FRONTEND + 1, # NUM_COURSES_BEGINNER_IA + 2, # NUM_COURSES_BEGINNER_BDD + 1, # NUM_COURSES_ADVANCED_DATASCIENCE + 0, # NUM_COURSES_ADVANCED_BACKEND + 1, # NUM_COURSES_ADVANCED_FRONTEND + 2, # NUM_COURSES_ADVANCED_IA + 0, # NUM_COURSES_ADVANCED_BDD + 80, # AVG_SCORE_DATASCIENCE + 75, # AVG_SCORE_BACKEND + 85, # AVG_SCORE_FRONTEND + 70, # AVG_SCORE_IA + 90, # AVG_SCORE_BDD + 15, # NB_CLICKS_DATASCIENCE + 5, # NB_CLICKS_BACKEND + 8, # NB_CLICKS_FRONTEND + 6, # NB_CLICKS_IA + 10, # NB_CLICKS_BDD + 1 # ORIENTATION + ] + + # Vérification de la longueur + assert len(data_sample) == len(feature_names) # Ceci doit passer sans erreur + + model = joblib.load('multi_target_model_5.pkl') + #le = joblib.load('label_encoder4.pkl') + + input_data_df = pd.DataFrame([data_sample], columns=feature_names) + #input_data_df = pd.DataFrame(new_observation_2, columns=feature_names) + + + # Predict using the DataFrame + prediction = model.predict(input_data_df) + #data = le.inverse_transform(prediction) + + # Create a LangChain client + #llm = OpenAI(openai_api_key="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") + + #openai.api_key = config['OpenAI']['key'] + #llm = OpenAI() + + # Question = "Give me some tips on joining python with oracle 23c " + + template = """ + Je suis étudiant en Master 2 BIHAR : Big Data Intelligence for Human Augmented Reality. + mon objectif est de devenir un expert dans l'utilisation de l'Intelligence Artificielle, + dans la gestion du Big Data et dans le développement d'applications Mobiles et Web dans le domaine + de l'intelligence artificielle et du big data. + + Mon domaine préféré est le Frontend. + + Mon style de cours est plutot la pratique. + + Voici mon profil: + + DATASCIENCE: """ + prediction[0][0] + """ + BACKEND: """ + prediction[0][1] + """ + FRONTEND: """ + prediction[0][2] + """ + IA: """ + prediction[0][3] + """ + BDD: """ + prediction[0][4] + """ + + Alors voici ma question: """+user_question+"""" + + Réponds à mes questions en fonction de mon niveau d'étude, de ma matière préférée et de mon style d'enseignement. + et mon profil + + Donne moi des exemples et des scripts ou du code que je peux utiliser si necessaire. + + """ + + print(template) + + + # Generate text + text = llm.predict(template) + + return text \ No newline at end of file diff --git a/models/scrapPdf.py b/models/scrapPdf.py new file mode 100644 index 000000000..f6020aa66 --- /dev/null +++ b/models/scrapPdf.py @@ -0,0 +1,30 @@ +# import PyPDF2 + +# def load_pdf_content(filepath): + +# with open(filepath, 'rb') as f: +# pdf = PyPDF2.PdfReader(f) +# text = '' +# for page in pdf.pages: +# text += page.extract_text() + +# return text + +import PyPDF2 +import requests +from io import BytesIO + +class ScrapPdf: + + def load_pdf_content(url): + response = requests.get(url) + response.raise_for_status() # Raise an error for bad responses + + with BytesIO(response.content) as f: + pdf = PyPDF2.PdfReader(f) + text = '' + for page in pdf.pages: + text += page.extract_text() + + return text + diff --git a/models/scrapUrl.py b/models/scrapUrl.py new file mode 100644 index 000000000..7e7bb0704 --- /dev/null +++ b/models/scrapUrl.py @@ -0,0 +1,22 @@ +import requests +from bs4 import BeautifulSoup + +class ScrapUrl: + + def scrapUrl(url): + + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + # find all the text on the page + text = soup.get_text() + # find the content div + content_div = soup.find('div', {'class': 'mw-parser-output'}) + # remove unwanted elements from div + unwanted_tags = ['sup', 'span', 'table', 'ul', 'ol'] + for tag in unwanted_tags: + for match in content_div.findAll(tag): + match.extract() + + #print(content_div.get_text()) + + return content_div.get_text() \ No newline at end of file From ed7fbdf16682e4b6d7d732a1cdcbfdb1d4e0b01d Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Wed, 20 Sep 2023 20:20:15 +0400 Subject: [PATCH 10/24] Update requirements --- requirements.txt | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index abaf3fee3..f92d8ade3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,19 +5,27 @@ aniso8601==9.0.1 anyio==3.7.1 async-timeout==4.0.2 attrs==22.2.0 +backoff==2.2.1 bardapi==0.1.23a0 +bcrypt==4.0.1 beautifulsoup4==4.12.2 blinker==1.6.2 cachetools==4.2.4 certifi==2022.12.7 charset-normalizer==2.1.1 +Chroma==0.2.0 +chroma-hnswlib==0.7.3 +chromadb==0.4.12 click==8.1.6 colorama==0.4.6 +coloredlogs==15.0.1 dataclasses-json==0.5.14 deep-translator==1.11.4 dnspython==2.4.2 email-validator==1.1.3 exceptiongroup==1.1.2 +fastapi==0.99.1 +filelock==3.12.4 Flask==2.0.1 Flask-Cors==4.0.0 Flask-Login==0.5.0 @@ -25,7 +33,9 @@ Flask-Migrate==3.1.0 flask-restx==0.5.1 Flask-SQLAlchemy==2.5.1 Flask-WTF==0.15.1 +flatbuffers==23.5.26 frozenlist==1.3.3 +fsspec==2023.9.1 google-api-core==1.34.0 google-auth==1.35.0 google-cloud-core==1.7.3 @@ -40,9 +50,13 @@ h11==0.14.0 h2==4.1.0 hpack==4.0.0 httpcore==0.17.3 +httptools==0.6.0 httpx==0.24.1 +huggingface-hub==0.16.4 +humanfriendly==10.0 hyperframe==6.0.1 idna==3.4 +importlib-resources==6.0.1 itsdangerous==2.1.2 Jinja2==3.0.1 joblib==1.3.1 @@ -55,27 +69,36 @@ markdown-it-py==3.0.0 MarkupSafe==2.1.3 marshmallow==3.20.1 mdurl==0.1.2 +monotonic==1.6 +mpmath==1.3.0 multidict==6.0.4 mypy-extensions==1.0.0 numexpr==2.8.5 numpy==1.25.1 +onnxruntime==1.16.0 openai==0.28.0 openapi-schema-pydantic==1.2.4 +overrides==7.4.0 packaging==23.1 pandas==2.0.3 +posthog==3.0.2 prompt-toolkit==3.0.39 protobuf==3.20.3 +pulsar-client==3.3.0 pyasn1==0.5.0 pyasn1-modules==0.3.0 pydantic==1.10.12 Pygments==2.15.1 PyPDF2==3.0.1 +PyPika==0.48.9 +pyreadline3==3.4.1 python-dateutil==2.8.2 python-decouple==3.4 python-dotenv==1.0.0 pytz==2023.3 PyYAML==6.0.1 referencing==0.30.2 +regex==2023.8.8 requests==2.28.2 rich==13.4.2 rpds-py==0.10.0 @@ -87,14 +110,22 @@ sniffio==1.3.0 socksio==1.0.0 soupsieve==2.4.1 SQLAlchemy==1.4.23 +starlette==0.27.0 +sympy==1.12 tenacity==8.2.2 threadpoolctl==3.2.0 -tqdm==4.64.1 +tiktoken==0.5.1 +tokenizers==0.14.0 +tqdm==4.66.1 +typer==0.9.0 typing-inspect==0.9.0 typing_extensions==4.7.1 tzdata==2023.3 urllib3==1.26.14 +uvicorn==0.23.2 +watchfiles==0.20.0 wcwidth==0.2.6 +websockets==11.0.3 Werkzeug==2.3.6 WTForms==2.3.3 yarl==1.8.2 From 822ae7d5d793f411922b9dfce490f926ac172f0c Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Wed, 20 Sep 2023 23:48:37 +0400 Subject: [PATCH 11/24] LLM: les urls possibles --- app.py | 15 ++--- models/prediction.py | 136 ------------------------------------------- models/scrapUrl.py | 6 +- output.txt | 1 + 4 files changed, 8 insertions(+), 150 deletions(-) delete mode 100644 models/prediction.py create mode 100644 output.txt diff --git a/app.py b/app.py index ef37ac533..db931a751 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,15 @@ from flask import Flask, request app = Flask(__name__) +from flask_cors import CORS from flask import Response from models import llm from models import txtmodel -from models import prediction + +CORS(app) @app.route('/') def hello_world(): return 'Hello, World!' @@ -19,7 +21,7 @@ def ask(): @app.route("/llm", methods=["POST"]) -def index(): +def llm_route(): requete = request.get_json() print(requete['q1']) print(requete['url']) @@ -28,12 +30,3 @@ def index(): resp = Response(result) resp.charset = "utf-8" return resp - - -@app.route("/prediction", methods=["POST"]) -def prediction(): - question = request.get_json() - result = prediction.Prediction.callPrediction(question['q2']) - resp = Response(result) - resp.charset = "utf-8" - return resp diff --git a/models/prediction.py b/models/prediction.py deleted file mode 100644 index b69530896..000000000 --- a/models/prediction.py +++ /dev/null @@ -1,136 +0,0 @@ -import joblib -import numpy as np -import pandas as pd - -from langchain import PromptTemplate -from langchain.llms import OpenAI -from langchain.text_splitter import RecursiveCharacterTextSplitter -from numpy.linalg import norm - -from models import scrapUrl as su -from models import scrapPdf as sp -from models import embedding as em - -from flask import Flask, request -from flask import jsonify - -class Prediction: - def callPrediction(user_question): - - # define the LLM you want to use - llm = OpenAI(temperature=1) - - feature_names = [ - 'HOURS_DATASCIENCE', - 'HOURS_BACKEND', - 'HOURS_FRONTEND', - 'HOURS_IA', - 'HOURS_BDD', - 'NUM_COURSES_BEGINNER_DATASCIENCE', - 'NUM_COURSES_BEGINNER_BACKEND', - 'NUM_COURSES_BEGINNER_FRONTEND', - 'NUM_COURSES_BEGINNER_IA', - 'NUM_COURSES_BEGINNER_BDD', - 'NUM_COURSES_ADVANCED_DATASCIENCE', - 'NUM_COURSES_ADVANCED_BACKEND', - 'NUM_COURSES_ADVANCED_FRONTEND', - 'NUM_COURSES_ADVANCED_IA', - 'NUM_COURSES_ADVANCED_BDD', - 'AVG_SCORE_DATASCIENCE', - 'AVG_SCORE_BACKEND', - 'AVG_SCORE_FRONTEND', - 'AVG_SCORE_IA', - 'AVG_SCORE_BDD', - 'NB_CLICKS_DATASCIENCE', - 'NB_CLICKS_BACKEND', - 'NB_CLICKS_FRONTEND', - 'NB_CLICKS_IA', - 'NB_CLICKS_BDD', - 'ORIENTATION'] - - - data_sample = [ - 10, # HOURS_DATASCIENCE - 5, # HOURS_BACKEND - 8, # HOURS_FRONTEND - 7, # HOURS_IA - 9, # HOURS_BDD - 2, # NUM_COURSES_BEGINNER_DATASCIENCE - 1, # NUM_COURSES_BEGINNER_BACKEND - 2, # NUM_COURSES_BEGINNER_FRONTEND - 1, # NUM_COURSES_BEGINNER_IA - 2, # NUM_COURSES_BEGINNER_BDD - 1, # NUM_COURSES_ADVANCED_DATASCIENCE - 0, # NUM_COURSES_ADVANCED_BACKEND - 1, # NUM_COURSES_ADVANCED_FRONTEND - 2, # NUM_COURSES_ADVANCED_IA - 0, # NUM_COURSES_ADVANCED_BDD - 80, # AVG_SCORE_DATASCIENCE - 75, # AVG_SCORE_BACKEND - 85, # AVG_SCORE_FRONTEND - 70, # AVG_SCORE_IA - 90, # AVG_SCORE_BDD - 15, # NB_CLICKS_DATASCIENCE - 5, # NB_CLICKS_BACKEND - 8, # NB_CLICKS_FRONTEND - 6, # NB_CLICKS_IA - 10, # NB_CLICKS_BDD - 1 # ORIENTATION - ] - - # Vérification de la longueur - assert len(data_sample) == len(feature_names) # Ceci doit passer sans erreur - - model = joblib.load('multi_target_model_5.pkl') - #le = joblib.load('label_encoder4.pkl') - - input_data_df = pd.DataFrame([data_sample], columns=feature_names) - #input_data_df = pd.DataFrame(new_observation_2, columns=feature_names) - - - # Predict using the DataFrame - prediction = model.predict(input_data_df) - #data = le.inverse_transform(prediction) - - # Create a LangChain client - #llm = OpenAI(openai_api_key="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") - - #openai.api_key = config['OpenAI']['key'] - #llm = OpenAI() - - # Question = "Give me some tips on joining python with oracle 23c " - - template = """ - Je suis étudiant en Master 2 BIHAR : Big Data Intelligence for Human Augmented Reality. - mon objectif est de devenir un expert dans l'utilisation de l'Intelligence Artificielle, - dans la gestion du Big Data et dans le développement d'applications Mobiles et Web dans le domaine - de l'intelligence artificielle et du big data. - - Mon domaine préféré est le Frontend. - - Mon style de cours est plutot la pratique. - - Voici mon profil: - - DATASCIENCE: """ + prediction[0][0] + """ - BACKEND: """ + prediction[0][1] + """ - FRONTEND: """ + prediction[0][2] + """ - IA: """ + prediction[0][3] + """ - BDD: """ + prediction[0][4] + """ - - Alors voici ma question: """+user_question+"""" - - Réponds à mes questions en fonction de mon niveau d'étude, de ma matière préférée et de mon style d'enseignement. - et mon profil - - Donne moi des exemples et des scripts ou du code que je peux utiliser si necessaire. - - """ - - print(template) - - - # Generate text - text = llm.predict(template) - - return text \ No newline at end of file diff --git a/models/scrapUrl.py b/models/scrapUrl.py index 7e7bb0704..8a036b79f 100644 --- a/models/scrapUrl.py +++ b/models/scrapUrl.py @@ -10,9 +10,9 @@ def scrapUrl(url): # find all the text on the page text = soup.get_text() # find the content div - content_div = soup.find('div', {'class': 'mw-parser-output'}) - # remove unwanted elements from div - unwanted_tags = ['sup', 'span', 'table', 'ul', 'ol'] + content_div = soup.find(['main', 'content', 'body', 'div']) + # remove unwanted elements from main + unwanted_tags = ['sup', 'span', 'table', 'ul', 'ol', 'p', 'i', 'a'] for tag in unwanted_tags: for match in content_div.findAll(tag): match.extract() diff --git a/output.txt b/output.txt new file mode 100644 index 000000000..63099a2cd --- /dev/null +++ b/output.txt @@ -0,0 +1 @@ + GPT-4 and LangChain: Building Python Chatbot with PDF IntegrationWhat is LangChain?Why LangChain?LangChain + GPT-4 + PDFs = ChatBotSetting up the Environmentpython -Vmkdir pdf-chatbotcd pdf-chatbotpython -m venv envenv\scripts\activatesource env/bin/activatepip install langchain openai chromadb pymupdf tiktokenUnderstanding LangChain Data LoadersLangChain PDF Data Loadersimport osfrom langchain.document_loaders import PyMuPDFLoaderos.environ['OPENAI_API_KEY'] = 'ENTER YOUR API KEY'loader = PyMuPDFLoader("./docs/example.pdf")documents = loader.load()from langchain.text_splitter import RecursiveCharacterTextSplittertext_splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=10)texts = text_splitter.split_documents(documents)Leveraging Embeddingsfrom langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingspersist_directory = "./storage"embeddings = OpenAIEmbeddings()vectordb = Chroma.from_documents(documents=texts, embedding=embeddings, persist_directory=persist_directory)vectordb.persist()Chatting with PDF Documentsfrom langchain.chat_models import ChatOpenAIfrom langchain.chains import RetrievalQAretriever = vectordb.as_retriever()llm = ChatOpenAI(model_name='gpt-4')qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)while True: user_input = input("Enter a query: ") if user_input == "exit": break query = f"###Prompt {user_input}" try: llm_response = qa(query) print(llm_response["result"]) except Exception as err: print('Exception occurred. Please try again', str(err))import os from langchain.document_loaders import PyMuPDFLoaderfrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.chat_models import ChatOpenAIfrom langchain.chains import RetrievalQAos.environ["OPENAI_API_KEY"] = 'ENTER YOUR API KEY'persist_directory = "./storage"pdf_path = "./docs/i1040gi.pdf"loader = PyMuPDFLoader(pdf_path)documents = loader.load()text_splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=10)texts = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()vectordb = Chroma.from_documents(documents=texts, embedding=embeddings, persist_directory=persist_directory)vectordb.persist()retriever = vectordb.as_retriever(search_kwargs={"k": 3})llm = ChatOpenAI(model_name='gpt-4')qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)while True: user_input = input("Enter a query: ") if user_input == "exit": break query = f"###Prompt {user_input}" try: llm_response = qa(query) print(llm_response["result"]) except Exception as err: print('Exception occurred. Please try again', str(err))Practical Applications and Use CasesEnter a query: what is this document about?This document is about the legal requirements for the Internal Revenue Service (IRS) to ask for and use information from taxpayers related to their eligibility for benefits or the repayment of loans. It also explains how the IRS may disclose this information to other countries, federal and state agencies, and federal law enforcement and intelligence agencies.Enter a query:Enter a query: By what date is The Marketplace is required to send Form 1095-A?The Marketplace is required to send Form 1095-A by January 31, 2023.Enter a query:ConclusionSubscribe to our newsletter and get exclusive contentRelated PostsShare SkillsPosted on CompanyResourcesHow to hire © 2022 Next Idea Tech \ No newline at end of file From bb9d44a1f03a2c1a0c70c33000b4da9fcdad1ab6 Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Sat, 23 Sep 2023 19:28:09 +0400 Subject: [PATCH 12/24] Json Loader --- .vscode/settings.json | 6 ++++++ app.py | 11 +++++++++++ models/jsonloader.py | 29 +++++++++++++++++++++++++++++ output.txt | 2 +- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 models/jsonloader.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9ee86e71a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/app.py b/app.py index db931a751..db1b2efd5 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,15 @@ from flask import Flask, request app = Flask(__name__) +import json + from flask_cors import CORS from flask import Response from models import llm from models import txtmodel +from models import jsonloader CORS(app) @@ -30,3 +33,11 @@ def llm_route(): resp = Response(result) resp.charset = "utf-8" return resp + +@app.route("/expert") +def loadjson(): + + data = (jsonloader.JsonLoader.loadJson("C:\\Users\\ASUS\\Downloads\\donnerExpert.json")) + search_string = "specialization" + results = jsonloader.JsonLoader.chercher_dans_json(search_string, json.dumps(data)) + return results diff --git a/models/jsonloader.py b/models/jsonloader.py new file mode 100644 index 000000000..7f19c6723 --- /dev/null +++ b/models/jsonloader.py @@ -0,0 +1,29 @@ +import json +from pathlib import Path + +class JsonLoader: + def loadJson(path): + data = json.loads(Path(path).read_text()) + return data + + def search_in_json(data, search_string): + results = [] + for item in data: + if search_string in item: + results.append(item) + return results + + + import json + + def chercher_dans_json(cle, chaine_json): + try: + # Charger le JSON depuis la chaîne + data = json.loads(chaine_json) + + # Rechercher la clé dans le JSON + valeur = data[cle] + + return valeur + except (json.JSONDecodeError, KeyError): + return None diff --git a/output.txt b/output.txt index 63099a2cd..a2ba148c6 100644 --- a/output.txt +++ b/output.txt @@ -1 +1 @@ - GPT-4 and LangChain: Building Python Chatbot with PDF IntegrationWhat is LangChain?Why LangChain?LangChain + GPT-4 + PDFs = ChatBotSetting up the Environmentpython -Vmkdir pdf-chatbotcd pdf-chatbotpython -m venv envenv\scripts\activatesource env/bin/activatepip install langchain openai chromadb pymupdf tiktokenUnderstanding LangChain Data LoadersLangChain PDF Data Loadersimport osfrom langchain.document_loaders import PyMuPDFLoaderos.environ['OPENAI_API_KEY'] = 'ENTER YOUR API KEY'loader = PyMuPDFLoader("./docs/example.pdf")documents = loader.load()from langchain.text_splitter import RecursiveCharacterTextSplittertext_splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=10)texts = text_splitter.split_documents(documents)Leveraging Embeddingsfrom langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingspersist_directory = "./storage"embeddings = OpenAIEmbeddings()vectordb = Chroma.from_documents(documents=texts, embedding=embeddings, persist_directory=persist_directory)vectordb.persist()Chatting with PDF Documentsfrom langchain.chat_models import ChatOpenAIfrom langchain.chains import RetrievalQAretriever = vectordb.as_retriever()llm = ChatOpenAI(model_name='gpt-4')qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)while True: user_input = input("Enter a query: ") if user_input == "exit": break query = f"###Prompt {user_input}" try: llm_response = qa(query) print(llm_response["result"]) except Exception as err: print('Exception occurred. Please try again', str(err))import os from langchain.document_loaders import PyMuPDFLoaderfrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.chat_models import ChatOpenAIfrom langchain.chains import RetrievalQAos.environ["OPENAI_API_KEY"] = 'ENTER YOUR API KEY'persist_directory = "./storage"pdf_path = "./docs/i1040gi.pdf"loader = PyMuPDFLoader(pdf_path)documents = loader.load()text_splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=10)texts = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()vectordb = Chroma.from_documents(documents=texts, embedding=embeddings, persist_directory=persist_directory)vectordb.persist()retriever = vectordb.as_retriever(search_kwargs={"k": 3})llm = ChatOpenAI(model_name='gpt-4')qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)while True: user_input = input("Enter a query: ") if user_input == "exit": break query = f"###Prompt {user_input}" try: llm_response = qa(query) print(llm_response["result"]) except Exception as err: print('Exception occurred. Please try again', str(err))Practical Applications and Use CasesEnter a query: what is this document about?This document is about the legal requirements for the Internal Revenue Service (IRS) to ask for and use information from taxpayers related to their eligibility for benefits or the repayment of loans. It also explains how the IRS may disclose this information to other countries, federal and state agencies, and federal law enforcement and intelligence agencies.Enter a query:Enter a query: By what date is The Marketplace is required to send Form 1095-A?The Marketplace is required to send Form 1095-A by January 31, 2023.Enter a query:ConclusionSubscribe to our newsletter and get exclusive contentRelated PostsShare SkillsPosted on CompanyResourcesHow to hire © 2022 Next Idea Tech \ No newline at end of file +Loading…New search experience powered by AICollectives™ on Stack Overflow1 month ago 540 times 0 from langchain.chains import ConversationalRetrievalChainfrom langchain.memory import ConversationBufferMemoryfrom langchain.vectorstores import DocArrayInMemorySearchfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.document_loaders import ( UnstructuredWordDocumentLoader, TextLoader, UnstructuredPowerPointLoader,)from langchain.tools import Toolfrom langchain.utilities import GoogleSearchAPIWrapperfrom langchain.chat_models import ChatOpenAIimport osimport openaiimport sysfrom dotenv import load_dotenv, find_dotenvsys.path.append('../..')_ = load_dotenv(find_dotenv()) # read local .env filegoogle_api_key = os.environ.get("GOOGLE_API_KEY")google_cse_id = os.environ.get("GOOGLE_CSE_ID")# Initialize OpenAI API keyopenai.api_key = os.environ['OPENAI_API_KEY']# Initialize Langchain environmentos.environ["LANGCHAIN_TRACING_V2"] = "true"os.environ["LANGCHAIN_ENDPOINT"] = "https://api.langchain.plus"os.environ["LANGCHAIN_API_KEY"] = os.environ['LANGCHAIN_API_KEY']os.environ["GOOGLE_API_KEY"] = google_api_keyos.environ["GOOGLE_CSE_ID"] = google_cse_id# Replace with the actual folder pathsfolder_path_docx = "DB\\DB VARIADO\\DOCS"folder_path_txt = "DB\\BLOG-POSTS"folder_path_pptx_1 = "DB\\PPT JUNIO"folder_path_pptx_2 = "DB\\DB VARIADO\\PPTX"# Create a list to store the loaded contentloaded_content = []# Load and process DOCX filesfor file in os.listdir(folder_path_docx): if file.endswith(".docx"): file_path = os.path.join(folder_path_docx, file) loader = UnstructuredWordDocumentLoader(file_path) docx = loader.load() loaded_content.extend(docx)# Load and process TXT filesfor file in os.listdir(folder_path_txt): if file.endswith(".txt"): file_path = os.path.join(folder_path_txt, file) loader = TextLoader(file_path, encoding='utf-8') text = loader.load() loaded_content.extend(text)# Load and process PPTX files from folder 1for file in os.listdir(folder_path_pptx_1): if file.endswith(".pptx"): file_path = os.path.join(folder_path_pptx_1, file) loader = UnstructuredPowerPointLoader(file_path) slides_1 = loader.load() loaded_content.extend(slides_1)# Load and process PPTX files from folder 2for file in os.listdir(folder_path_pptx_2): if file.endswith(".pptx"): file_path = os.path.join(folder_path_pptx_2, file) loader = UnstructuredPowerPointLoader(file_path) slides_2 = loader.load() loaded_content.extend(slides_2)# Initialize OpenAI Embeddingsembedding = OpenAIEmbeddings()# Create embeddings for loaded contentembeddings_content = []for one_loaded_content in loaded_content: embedding_content = embedding.embed_query(one_loaded_content.page_content) embeddings_content.append(embedding_content)db = DocArrayInMemorySearch.from_documents(loaded_content, embedding)retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})search = GoogleSearchAPIWrapper()def custom_search(query): internet_results = search.run(query) print(internet_results) return internet_resultschain = ConversationalRetrievalChain.from_llm( llm=ChatOpenAI(model_name="gpt-4", temperature=0), chain_type="map_reduce", retriever=retriever, return_source_documents=True, return_generated_question=True,)history = []while True: query = input("Hola, soy Chatbot. ¿Qué te gustaría saber? ") # Use the custom_search function to get internet search results internet_results = custom_search(query) # Combine the custom data and internet search results combined_results = loaded_content + [internet_results] # Pass the combined results to the chain response = chain( {"question": query, "chat_history": history, "documents": combined_results}) print(response["answer"]) history.append(("system", query)) # user's query history.append(("assistant", response["answer"])) # chatbot's response Follow asked 1 Answer Sorted by: Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 0 query="what is stackoverflow?"internet_results_prior=search.run(query)def custom_search(query): #internet_results = search.run(query) # comment this line and add the following internet_results = search.results(query,3) # replace with it, so gets metadata results, 3 means return three results print(internet_results) return internet_resultsquery="what is stackoverflow?"internet_results = custom_search(query)[{'title': 'Stack Overflow - Where Developers Learn, Share, & Build Careers', 'link': 'https://stackoverflow.com/', 'snippet': 'Stack Overflow is the largest, most trusted online community for developers to learn, share\u200b \u200btheir programming \u200bknowledge, and build their careers.'}, {'title': 'Stack Overflow - Wikipedia', 'link': 'https://en.wikipedia.org/wiki/Stack_Overflow', 'snippet': 'Stack Overflow is a question-and-answer website for programmers. It is the flagship site of the Stack Exchange Network. It was created in 2008 by Jeff\xa0...'}, {'title': 'What is a stack overflow error?', 'link': 'https://www.techtarget.com/whatis/definition/stack-overflow', 'snippet': 'A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been\xa0...'}]for result in internet_results: print(result['snippet']) print("---"*10)Stack Overflow is the largest, most trusted online community for developers to learn, share​ ​their programming ​knowledge, and build their careers.------------------------------Stack Overflow is a question-and-answer website for programmers. It is the flagship site of the Stack Exchange Network. It was created in 2008 by Jeff ...------------------------------A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been ...import os#https://console.cloud.google.com/apis/credentialsos.environ["GOOGLE_CSE_ID"] = "xxx"#https://programmablesearchengine.google.com/controlpanel/createos.environ["GOOGLE_API_KEY"] = "xxx"from langchain.utilities import GoogleSearchAPIWrappersearch = GoogleSearchAPIWrapper()def custom_search(query): #internet_results = search.run(query) # comment this line and add the following internet_results = search.results(query,3) # replace with it, so gets metadata results print(internet_results) return internet_resultsquery="what is stackoverflow?"internet_results = custom_search(query)for result in internet_results: print(result['snippet']) print("---"*10)loaded_content=[]loaded_content=loaded_content + [internet_results_prior]#convert list to list of docsfrom langchain.docstore.document import Documentloaded_content_docs=[]for each_content in loaded_content: loaded_content_docs.append(Document(page_content=each_content, metadata={"source": "internet"}))from langchain.chains import ConversationalRetrievalChainfrom langchain.vectorstores import DocArrayInMemorySearchfrom langchain.chat_models import ChatOpenAIfrom langchain.embeddings.openai import OpenAIEmbeddings# Initialize OpenAI Embeddingsembedding = OpenAIEmbeddings()vector_db = DocArrayInMemorySearch.from_documents(loaded_content_docs, embedding)retriever = vector_db.as_retriever(search_type="similarity", search_kwargs={"k": 3})history = []chain = ConversationalRetrievalChain.from_llm( llm=ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0), # did not have access to chat-gpt chain_type="map_reduce", retriever=retriever, return_source_documents=True, return_generated_question=True,)question="do you know about stackoverflow?"response = chain( {"question": question, "chat_history": history, "documents": loaded_content_docs})print(response["answer"]) Follow answered Your Answer Draft savedDraft discardedSign up or Sign up using Google Sign up using Facebook Sign up using Email and Password SubmitPost as a guestNameEmailPost as a guestNameEmail Post Your Answer Discard Not the answer you're looking for? Browse other questions tagged or . Related Subscribe to RSS Question feed lang-py Accept all cookies Necessary cookies only Customize settings   \ No newline at end of file From a306bf2ea282c080b175e919d34df4d1f1e681e3 Mon Sep 17 00:00:00 2001 From: Nomena <60197372+john7373@users.noreply.github.com> Date: Sun, 24 Sep 2023 13:57:34 +0300 Subject: [PATCH 13/24] Create expfind.py --- models/expfind.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 models/expfind.py diff --git a/models/expfind.py b/models/expfind.py new file mode 100644 index 000000000..1757de859 --- /dev/null +++ b/models/expfind.py @@ -0,0 +1,30 @@ +import openai +import json + + +# Chargez le fichier JSON local +with open("C:\\Users\\7john\\OneDrive\\Documents\stage\\backend\\IAGORA-API\\data\\donnerExperts.json", "r") as file: + developers = json.load(file) + +# Convertissez les données en une chaîne JSON +json_data = json.dumps(developers) + +# Définissez le prompt avec la chaîne JSON +prompt = f"""{json_data}\n\nRecherche des développeurs java avec plus de 3 ans d'expérience :""" + +# Demandez à GPT-3 de filtrer les développeurs +response = openai.Completion.create( + engine="davinci", + prompt=prompt, + max_tokens=1000 +) + +# Analysez la réponse pour extraire les développeurs filtrés +filtered_developers = [] +data = response.choices[0].text.strip().split('\n') +for entry in data: + expert = eval(entry) + if expert["specialization"] == "Java" and expert["years_of_experience"] > 3: + filtered_developers.append(expert) + +print(filtered_developers) From e9bd606773fc8c6f53579bf6d357801d70670f4f Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Sun, 24 Sep 2023 14:55:52 +0300 Subject: [PATCH 14/24] Update expfind.py --- models/expfind.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/models/expfind.py b/models/expfind.py index 1757de859..b841228d3 100644 --- a/models/expfind.py +++ b/models/expfind.py @@ -1,30 +1,19 @@ import openai import json - # Chargez le fichier JSON local -with open("C:\\Users\\7john\\OneDrive\\Documents\stage\\backend\\IAGORA-API\\data\\donnerExperts.json", "r") as file: +with open("C:\\Users\\7john\\OneDrive\\Documents\\stage\\backend\\IAGORA-API\\data\\donnerExperts.json", "r") as file: developers = json.load(file) - -# Convertissez les données en une chaîne JSON -json_data = json.dumps(developers) - -# Définissez le prompt avec la chaîne JSON -prompt = f"""{json_data}\n\nRecherche des développeurs java avec plus de 3 ans d'expérience :""" - -# Demandez à GPT-3 de filtrer les développeurs + json_data = json.dumps(developers) +# Appeler l'API GPT response = openai.Completion.create( - engine="davinci", - prompt=prompt, - max_tokens=1000 + engine='text-davinci-003', + prompt = f"""{json_data}\n\nRecherche des développeurs angular avec plus de 3 ans d'expérience :""", + max_tokens= 10000 ) -# Analysez la réponse pour extraire les développeurs filtrés -filtered_developers = [] -data = response.choices[0].text.strip().split('\n') -for entry in data: - expert = eval(entry) - if expert["specialization"] == "Java" and expert["years_of_experience"] > 3: - filtered_developers.append(expert) +# Traiter la réponse +answer = response.choices[0].text.strip() -print(filtered_developers) +# Afficher la réponse +print(answer) \ No newline at end of file From 1314c2322fea2bc69681e971362658faad336169 Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Sun, 24 Sep 2023 16:35:08 +0300 Subject: [PATCH 15/24] Create donnerExperts.json --- data/donnerExperts.json | 901 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 901 insertions(+) create mode 100644 data/donnerExperts.json diff --git a/data/donnerExperts.json b/data/donnerExperts.json new file mode 100644 index 000000000..aefc5d7a3 --- /dev/null +++ b/data/donnerExperts.json @@ -0,0 +1,901 @@ +[{ + "expert_id": 1, + "first_name": "Devlen", + "last_name": "Proughten", + "email": "dproughten0@house.gov", + "country": "China", + "years_of_experience": 4, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 2, + "first_name": "Fawn", + "last_name": "Adriani", + "email": "fadriani1@thetimes.co.uk", + "country": "Philippines", + "years_of_experience": 4, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 3, + "first_name": "Donielle", + "last_name": "Olner", + "email": "dolner2@msn.com", + "country": "Serbia", + "years_of_experience": 18, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 4, + "first_name": "Theodor", + "last_name": "Custy", + "email": "tcusty3@examiner.com", + "country": "Russia", + "years_of_experience": 17, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 5, + "first_name": "Barth", + "last_name": "Amort", + "email": "bamort4@sogou.com", + "country": "Thailand", + "years_of_experience": 19, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 6, + "first_name": "Lorinda", + "last_name": "Tertre", + "email": "ltertre5@newsvine.com", + "country": "Tanzania", + "years_of_experience": 10, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 7, + "first_name": "Benedetta", + "last_name": "Prestner", + "email": "bprestner6@usnews.com", + "country": "Portugal", + "years_of_experience": 8, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 8, + "first_name": "Claudine", + "last_name": "Slinn", + "email": "cslinn7@canalblog.com", + "country": "China", + "years_of_experience": 7, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 9, + "first_name": "Reuben", + "last_name": "Sedgefield", + "email": "rsedgefield8@de.vu", + "country": "France", + "years_of_experience": 13, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 10, + "first_name": "Zebadiah", + "last_name": "Hodinton", + "email": "zhodinton9@csmonitor.com", + "country": "Indonesia", + "years_of_experience": 4, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 11, + "first_name": "Augy", + "last_name": "Bartaloni", + "email": "abartalonia@sfgate.com", + "country": "Indonesia", + "years_of_experience": 16, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 12, + "first_name": "Bram", + "last_name": "Dziwisz", + "email": "bdziwiszb@vinaora.com", + "country": "Czech Republic", + "years_of_experience": 5, + "specialization": "react", + "certifications": "CPA" + }, { + "expert_id": 13, + "first_name": "Katalin", + "last_name": "Woodhead", + "email": "kwoodheadc@networkadvertising.org", + "country": "China", + "years_of_experience": 9, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 14, + "first_name": "Van", + "last_name": "MacHostie", + "email": "vmachostied@shareasale.com", + "country": "Chile", + "years_of_experience": 11, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 15, + "first_name": "Octavia", + "last_name": "Beig", + "email": "obeige@addthis.com", + "country": "Comoros", + "years_of_experience": 13, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 16, + "first_name": "Nessa", + "last_name": "Beidebeke", + "email": "nbeidebekef@opensource.org", + "country": "Indonesia", + "years_of_experience": 7, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 17, + "first_name": "Gerald", + "last_name": "Humby", + "email": "ghumbyg@google.pl", + "country": "Indonesia", + "years_of_experience": 1, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 18, + "first_name": "Trev", + "last_name": "Blick", + "email": "tblickh@printfriendly.com", + "country": "Philippines", + "years_of_experience": 3, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 19, + "first_name": "Jacklin", + "last_name": "Orring", + "email": "jorringi@skyrock.com", + "country": "China", + "years_of_experience": 17, + "specialization": "C++", + "certifications": "PMP" + }, { + "expert_id": 20, + "first_name": "Hedda", + "last_name": "Thandi", + "email": "hthandij@latimes.com", + "country": "Nicaragua", + "years_of_experience": 13, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 21, + "first_name": "Gayle", + "last_name": "Coffee", + "email": "gcoffeek@storify.com", + "country": "Georgia", + "years_of_experience": 2, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 22, + "first_name": "Allistir", + "last_name": "Espinet", + "email": "aespinetl@fc2.com", + "country": "Philippines", + "years_of_experience": 17, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 23, + "first_name": "Charleen", + "last_name": "Gaine", + "email": "cgainem@guardian.co.uk", + "country": "Peru", + "years_of_experience": 7, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 24, + "first_name": "Lenora", + "last_name": "Woodland", + "email": "lwoodlandn@state.gov", + "country": "China", + "years_of_experience": 12, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 25, + "first_name": "Micaela", + "last_name": "Perel", + "email": "mperelo@networkadvertising.org", + "country": "Bolivia", + "years_of_experience": 7, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 26, + "first_name": "Adrianne", + "last_name": "Rasmus", + "email": "arasmusp@dot.gov", + "country": "Norway", + "years_of_experience": 1, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 27, + "first_name": "Lauraine", + "last_name": "Bollard", + "email": "lbollardq@elegantthemes.com", + "country": "Ecuador", + "years_of_experience": 13, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 28, + "first_name": "Karlotta", + "last_name": "Bettenay", + "email": "kbettenayr@usgs.gov", + "country": "Slovenia", + "years_of_experience": 6, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 29, + "first_name": "Raymund", + "last_name": "Breckwell", + "email": "rbreckwells@squidoo.com", + "country": "China", + "years_of_experience": 15, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 30, + "first_name": "Jimmy", + "last_name": "Kleinber", + "email": "jkleinbert@jugem.jp", + "country": "Ireland", + "years_of_experience": 3, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 31, + "first_name": "Enrique", + "last_name": "Brandom", + "email": "ebrandomu@myspace.com", + "country": "Indonesia", + "years_of_experience": 3, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 32, + "first_name": "Nil", + "last_name": "Drillingcourt", + "email": "ndrillingcourtv@berkeley.edu", + "country": "Indonesia", + "years_of_experience": 19, + "specialization": "react", + "certifications": "CFA" + }, { + "expert_id": 33, + "first_name": "Dannie", + "last_name": "Oxborough", + "email": "doxboroughw@salon.com", + "country": "Nicaragua", + "years_of_experience": 5, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 34, + "first_name": "Ax", + "last_name": "Hairesnape", + "email": "ahairesnapex@msn.com", + "country": "Spain", + "years_of_experience": 7, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 35, + "first_name": "Peyton", + "last_name": "Callway", + "email": "pcallwayy@plala.or.jp", + "country": "Honduras", + "years_of_experience": 4, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 36, + "first_name": "Gaby", + "last_name": "Fockes", + "email": "gfockesz@google.cn", + "country": "China", + "years_of_experience": 19, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 37, + "first_name": "Fidel", + "last_name": "Olenov", + "email": "folenov10@theglobeandmail.com", + "country": "China", + "years_of_experience": 1, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 38, + "first_name": "Celestina", + "last_name": "Sorby", + "email": "csorby11@google.cn", + "country": "Yemen", + "years_of_experience": 1, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 39, + "first_name": "Waylen", + "last_name": "Scrimshire", + "email": "wscrimshire12@barnesandnoble.com", + "country": "Poland", + "years_of_experience": 9, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 40, + "first_name": "Cleopatra", + "last_name": "Mailes", + "email": "cmailes13@thetimes.co.uk", + "country": "Mexico", + "years_of_experience": 19, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 41, + "first_name": "Krishna", + "last_name": "Adaway", + "email": "kadaway14@bandcamp.com", + "country": "China", + "years_of_experience": 5, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 42, + "first_name": "Lorenzo", + "last_name": "Kitteridge", + "email": "lkitteridge15@ucoz.ru", + "country": "Indonesia", + "years_of_experience": 15, + "specialization": "Java", + "certifications": "CPA" + }, { + "expert_id": 43, + "first_name": "Mirabella", + "last_name": "McKissack", + "email": "mmckissack16@bandcamp.com", + "country": "Brazil", + "years_of_experience": 19, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 44, + "first_name": "Elizabet", + "last_name": "Maydwell", + "email": "emaydwell17@lycos.com", + "country": "Macedonia", + "years_of_experience": 14, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 45, + "first_name": "Granthem", + "last_name": "Tonsley", + "email": "gtonsley18@cisco.com", + "country": "Vietnam", + "years_of_experience": 14, + "specialization": "Java", + "certifications": "CFA" + }, { + "expert_id": 46, + "first_name": "Irwinn", + "last_name": "Puddicombe", + "email": "ipuddicombe19@alexa.com", + "country": "Kenya", + "years_of_experience": 13, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 47, + "first_name": "Clarence", + "last_name": "Pimerick", + "email": "cpimerick1a@hhs.gov", + "country": "Mexico", + "years_of_experience": 18, + "specialization": "C++", + "certifications": "PMP" + }, { + "expert_id": 48, + "first_name": "Celia", + "last_name": "Challace", + "email": "cchallace1b@xing.com", + "country": "Ukraine", + "years_of_experience": 1, + "specialization": "react", + "certifications": "CFA" + }, { + "expert_id": 49, + "first_name": "Wilone", + "last_name": "Barends", + "email": "wbarends1c@seattletimes.com", + "country": "Thailand", + "years_of_experience": 2, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 50, + "first_name": "Rick", + "last_name": "Ingarfield", + "email": "ringarfield1d@marriott.com", + "country": "China", + "years_of_experience": 4, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 51, + "first_name": "Del", + "last_name": "Sawkins", + "email": "dsawkins1e@wix.com", + "country": "Indonesia", + "years_of_experience": 1, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 52, + "first_name": "Denice", + "last_name": "Lamburne", + "email": "dlamburne1f@ftc.gov", + "country": "France", + "years_of_experience": 11, + "specialization": "react", + "certifications": "CFA" + }, { + "expert_id": 53, + "first_name": "Vanessa", + "last_name": "Dopson", + "email": "vdopson1g@facebook.com", + "country": "South Korea", + "years_of_experience": 18, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 54, + "first_name": "Hermy", + "last_name": "Yakobovitz", + "email": "hyakobovitz1h@nasa.gov", + "country": "Bangladesh", + "years_of_experience": 19, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 55, + "first_name": "Gwenneth", + "last_name": "Tradewell", + "email": "gtradewell1i@soup.io", + "country": "Finland", + "years_of_experience": 15, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 56, + "first_name": "Merrie", + "last_name": "Raffles", + "email": "mraffles1j@boston.com", + "country": "Guinea", + "years_of_experience": 1, + "specialization": "Java", + "certifications": "CFA" + }, { + "expert_id": 57, + "first_name": "Stafani", + "last_name": "Fidell", + "email": "sfidell1k@wikipedia.org", + "country": "Mexico", + "years_of_experience": 20, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 58, + "first_name": "Bibbie", + "last_name": "Oxlade", + "email": "boxlade1l@hostgator.com", + "country": "Czech Republic", + "years_of_experience": 19, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 59, + "first_name": "Queenie", + "last_name": "Pierri", + "email": "qpierri1m@omniture.com", + "country": "Russia", + "years_of_experience": 10, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 60, + "first_name": "Maiga", + "last_name": "Bathowe", + "email": "mbathowe1n@angelfire.com", + "country": "Russia", + "years_of_experience": 5, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 61, + "first_name": "Rolland", + "last_name": "Motherwell", + "email": "rmotherwell1o@ebay.com", + "country": "France", + "years_of_experience": 10, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 62, + "first_name": "Silvie", + "last_name": "Bedingfield", + "email": "sbedingfield1p@umn.edu", + "country": "Sweden", + "years_of_experience": 14, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 63, + "first_name": "Jacobo", + "last_name": "Feldhorn", + "email": "jfeldhorn1q@businesswire.com", + "country": "South Africa", + "years_of_experience": 3, + "specialization": "react", + "certifications": "CFA" + }, { + "expert_id": 64, + "first_name": "Gardener", + "last_name": "Veque", + "email": "gveque1r@fastcompany.com", + "country": "Colombia", + "years_of_experience": 9, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 65, + "first_name": "Cora", + "last_name": "Brunton", + "email": "cbrunton1s@example.com", + "country": "Tajikistan", + "years_of_experience": 6, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 66, + "first_name": "Lek", + "last_name": "Lambregts", + "email": "llambregts1t@cmu.edu", + "country": "Philippines", + "years_of_experience": 12, + "specialization": "Java", + "certifications": "CFA" + }, { + "expert_id": 67, + "first_name": "Arlan", + "last_name": "Colerick", + "email": "acolerick1u@mac.com", + "country": "Portugal", + "years_of_experience": 17, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 68, + "first_name": "Cicily", + "last_name": "Longea", + "email": "clongea1v@sohu.com", + "country": "China", + "years_of_experience": 19, + "specialization": "Java", + "certifications": "CPA" + }, { + "expert_id": 69, + "first_name": "William", + "last_name": "Stopford", + "email": "wstopford1w@scientificamerican.com", + "country": "Philippines", + "years_of_experience": 11, + "specialization": "C++", + "certifications": "CFA" + }, { + "expert_id": 70, + "first_name": "Wylie", + "last_name": "Esmonde", + "email": "wesmonde1x@springer.com", + "country": "China", + "years_of_experience": 8, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 71, + "first_name": "Hedi", + "last_name": "Fruish", + "email": "hfruish1y@slashdot.org", + "country": "Poland", + "years_of_experience": 17, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 72, + "first_name": "Salome", + "last_name": "Dagwell", + "email": "sdagwell1z@ycombinator.com", + "country": "Thailand", + "years_of_experience": 20, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 73, + "first_name": "Berk", + "last_name": "Battrum", + "email": "bbattrum20@youtu.be", + "country": "Hungary", + "years_of_experience": 5, + "specialization": "react", + "certifications": "CFA" + }, { + "expert_id": 74, + "first_name": "Nevins", + "last_name": "MacCleod", + "email": "nmaccleod21@1und1.de", + "country": "Philippines", + "years_of_experience": 10, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 75, + "first_name": "Conni", + "last_name": "Tuddall", + "email": "ctuddall22@clickbank.net", + "country": "French Polynesia", + "years_of_experience": 15, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 76, + "first_name": "Osbourne", + "last_name": "Stollenbeck", + "email": "ostollenbeck23@narod.ru", + "country": "China", + "years_of_experience": 6, + "specialization": "Java", + "certifications": "CFA" + }, { + "expert_id": 77, + "first_name": "Dimitry", + "last_name": "Barnaby", + "email": "dbarnaby24@creativecommons.org", + "country": "Philippines", + "years_of_experience": 5, + "specialization": "Java", + "certifications": "CPA" + }, { + "expert_id": 78, + "first_name": "Peadar", + "last_name": "Fantin", + "email": "pfantin25@youtu.be", + "country": "Russia", + "years_of_experience": 17, + "specialization": "react", + "certifications": "PMP" + }, { + "expert_id": 79, + "first_name": "Chic", + "last_name": "Woodrow", + "email": "cwoodrow26@acquirethisname.com", + "country": "Brazil", + "years_of_experience": 2, + "specialization": "Java", + "certifications": "CFA" + }, { + "expert_id": 80, + "first_name": "Boote", + "last_name": "Toderi", + "email": "btoderi27@fema.gov", + "country": "Estonia", + "years_of_experience": 15, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 81, + "first_name": "Maribel", + "last_name": "Furzer", + "email": "mfurzer28@ycombinator.com", + "country": "Brazil", + "years_of_experience": 9, + "specialization": "react", + "certifications": "CPA" + }, { + "expert_id": 82, + "first_name": "Ethelyn", + "last_name": "Rigglesford", + "email": "erigglesford29@wikipedia.org", + "country": "Philippines", + "years_of_experience": 13, + "specialization": "angular", + "certifications": "PHR" + }, { + "expert_id": 83, + "first_name": "Warren", + "last_name": "Bewick", + "email": "wbewick2a@flickr.com", + "country": "China", + "years_of_experience": 4, + "specialization": "Java", + "certifications": "PHR" + }, { + "expert_id": 84, + "first_name": "Aliza", + "last_name": "Callacher", + "email": "acallacher2b@infoseek.co.jp", + "country": "Ukraine", + "years_of_experience": 6, + "specialization": "angular", + "certifications": "PMP" + }, { + "expert_id": 85, + "first_name": "Court", + "last_name": "Lomasny", + "email": "clomasny2c@creativecommons.org", + "country": "China", + "years_of_experience": 18, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 86, + "first_name": "Sylvan", + "last_name": "McGuane", + "email": "smcguane2d@zimbio.com", + "country": "Czech Republic", + "years_of_experience": 4, + "specialization": "react", + "certifications": "CPA" + }, { + "expert_id": 87, + "first_name": "Case", + "last_name": "Dripps", + "email": "cdripps2e@tiny.cc", + "country": "Uzbekistan", + "years_of_experience": 7, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 88, + "first_name": "Steven", + "last_name": "Sullly", + "email": "ssullly2f@ibm.com", + "country": "Mexico", + "years_of_experience": 19, + "specialization": "C++", + "certifications": "PMP" + }, { + "expert_id": 89, + "first_name": "Dari", + "last_name": "Lazare", + "email": "dlazare2g@samsung.com", + "country": "China", + "years_of_experience": 6, + "specialization": "react", + "certifications": "CPA" + }, { + "expert_id": 90, + "first_name": "Devina", + "last_name": "Glavias", + "email": "dglavias2h@blogspot.com", + "country": "Azerbaijan", + "years_of_experience": 17, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 91, + "first_name": "Nicolai", + "last_name": "Bleibaum", + "email": "nbleibaum2i@jigsy.com", + "country": "Vietnam", + "years_of_experience": 5, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 92, + "first_name": "Dieter", + "last_name": "Martland", + "email": "dmartland2j@nih.gov", + "country": "Indonesia", + "years_of_experience": 14, + "specialization": "C++", + "certifications": "CPA" + }, { + "expert_id": 93, + "first_name": "Estele", + "last_name": "Loudyan", + "email": "eloudyan2k@webs.com", + "country": "Indonesia", + "years_of_experience": 15, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 94, + "first_name": "Gwenneth", + "last_name": "Scneider", + "email": "gscneider2l@cmu.edu", + "country": "Poland", + "years_of_experience": 2, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 95, + "first_name": "Mace", + "last_name": "Brant", + "email": "mbrant2m@ezinearticles.com", + "country": "China", + "years_of_experience": 16, + "specialization": "angular", + "certifications": "CPA" + }, { + "expert_id": 96, + "first_name": "Amandie", + "last_name": "Besant", + "email": "abesant2n@discuz.net", + "country": "Portugal", + "years_of_experience": 11, + "specialization": "C++", + "certifications": "PHR" + }, { + "expert_id": 97, + "first_name": "Herc", + "last_name": "Hedingham", + "email": "hhedingham2o@infoseek.co.jp", + "country": "Brazil", + "years_of_experience": 16, + "specialization": "react", + "certifications": "PHR" + }, { + "expert_id": 98, + "first_name": "Paloma", + "last_name": "McGurgan", + "email": "pmcgurgan2p@scribd.com", + "country": "Czech Republic", + "years_of_experience": 13, + "specialization": "angular", + "certifications": "CFA" + }, { + "expert_id": 99, + "first_name": "Cortie", + "last_name": "Beaufoy", + "email": "cbeaufoy2q@pagesperso-orange.fr", + "country": "Philippines", + "years_of_experience": 13, + "specialization": "Java", + "certifications": "PMP" + }, { + "expert_id": 100, + "first_name": "Willyt", + "last_name": "Lauderdale", + "email": "wlauderdale2r@shutterfly.com", + "country": "Indonesia", + "years_of_experience": 4, + "specialization": "angular", + "certifications": "PMP" + }] \ No newline at end of file From f0e4feec8bc7bde0e6358d4aa0fac39b68cf634c Mon Sep 17 00:00:00 2001 From: Fynaritra Date: Sun, 24 Sep 2023 17:57:38 +0400 Subject: [PATCH 16/24] find experts --- app.py | 9 +- data/donnerExperts.json | 813 +--------------------------------------- models/expfind.py | 31 +- 3 files changed, 23 insertions(+), 830 deletions(-) diff --git a/app.py b/app.py index db1b2efd5..a417bfe3d 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ from models import llm from models import txtmodel from models import jsonloader +from models import expfind CORS(app) @@ -34,10 +35,8 @@ def llm_route(): resp.charset = "utf-8" return resp -@app.route("/expert") +@app.route("/expert", methods=["POST"]) def loadjson(): - - data = (jsonloader.JsonLoader.loadJson("C:\\Users\\ASUS\\Downloads\\donnerExpert.json")) - search_string = "specialization" - results = jsonloader.JsonLoader.chercher_dans_json(search_string, json.dumps(data)) + requete = request.get_json() + results = expfind.ExpFind.findExp(requete['message']) return results diff --git a/data/donnerExperts.json b/data/donnerExperts.json index aefc5d7a3..a1c101ba9 100644 --- a/data/donnerExperts.json +++ b/data/donnerExperts.json @@ -88,814 +88,5 @@ "years_of_experience": 4, "specialization": "angular", "certifications": "PHR" - }, { - "expert_id": 11, - "first_name": "Augy", - "last_name": "Bartaloni", - "email": "abartalonia@sfgate.com", - "country": "Indonesia", - "years_of_experience": 16, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 12, - "first_name": "Bram", - "last_name": "Dziwisz", - "email": "bdziwiszb@vinaora.com", - "country": "Czech Republic", - "years_of_experience": 5, - "specialization": "react", - "certifications": "CPA" - }, { - "expert_id": 13, - "first_name": "Katalin", - "last_name": "Woodhead", - "email": "kwoodheadc@networkadvertising.org", - "country": "China", - "years_of_experience": 9, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 14, - "first_name": "Van", - "last_name": "MacHostie", - "email": "vmachostied@shareasale.com", - "country": "Chile", - "years_of_experience": 11, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 15, - "first_name": "Octavia", - "last_name": "Beig", - "email": "obeige@addthis.com", - "country": "Comoros", - "years_of_experience": 13, - "specialization": "angular", - "certifications": "PHR" - }, { - "expert_id": 16, - "first_name": "Nessa", - "last_name": "Beidebeke", - "email": "nbeidebekef@opensource.org", - "country": "Indonesia", - "years_of_experience": 7, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 17, - "first_name": "Gerald", - "last_name": "Humby", - "email": "ghumbyg@google.pl", - "country": "Indonesia", - "years_of_experience": 1, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 18, - "first_name": "Trev", - "last_name": "Blick", - "email": "tblickh@printfriendly.com", - "country": "Philippines", - "years_of_experience": 3, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 19, - "first_name": "Jacklin", - "last_name": "Orring", - "email": "jorringi@skyrock.com", - "country": "China", - "years_of_experience": 17, - "specialization": "C++", - "certifications": "PMP" - }, { - "expert_id": 20, - "first_name": "Hedda", - "last_name": "Thandi", - "email": "hthandij@latimes.com", - "country": "Nicaragua", - "years_of_experience": 13, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 21, - "first_name": "Gayle", - "last_name": "Coffee", - "email": "gcoffeek@storify.com", - "country": "Georgia", - "years_of_experience": 2, - "specialization": "angular", - "certifications": "PHR" - }, { - "expert_id": 22, - "first_name": "Allistir", - "last_name": "Espinet", - "email": "aespinetl@fc2.com", - "country": "Philippines", - "years_of_experience": 17, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 23, - "first_name": "Charleen", - "last_name": "Gaine", - "email": "cgainem@guardian.co.uk", - "country": "Peru", - "years_of_experience": 7, - "specialization": "Java", - "certifications": "PMP" - }, { - "expert_id": 24, - "first_name": "Lenora", - "last_name": "Woodland", - "email": "lwoodlandn@state.gov", - "country": "China", - "years_of_experience": 12, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 25, - "first_name": "Micaela", - "last_name": "Perel", - "email": "mperelo@networkadvertising.org", - "country": "Bolivia", - "years_of_experience": 7, - "specialization": "angular", - "certifications": "CFA" - }, { - "expert_id": 26, - "first_name": "Adrianne", - "last_name": "Rasmus", - "email": "arasmusp@dot.gov", - "country": "Norway", - "years_of_experience": 1, - "specialization": "angular", - "certifications": "CFA" - }, { - "expert_id": 27, - "first_name": "Lauraine", - "last_name": "Bollard", - "email": "lbollardq@elegantthemes.com", - "country": "Ecuador", - "years_of_experience": 13, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 28, - "first_name": "Karlotta", - "last_name": "Bettenay", - "email": "kbettenayr@usgs.gov", - "country": "Slovenia", - "years_of_experience": 6, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 29, - "first_name": "Raymund", - "last_name": "Breckwell", - "email": "rbreckwells@squidoo.com", - "country": "China", - "years_of_experience": 15, - "specialization": "angular", - "certifications": "CPA" - }, { - "expert_id": 30, - "first_name": "Jimmy", - "last_name": "Kleinber", - "email": "jkleinbert@jugem.jp", - "country": "Ireland", - "years_of_experience": 3, - "specialization": "angular", - "certifications": "PHR" - }, { - "expert_id": 31, - "first_name": "Enrique", - "last_name": "Brandom", - "email": "ebrandomu@myspace.com", - "country": "Indonesia", - "years_of_experience": 3, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 32, - "first_name": "Nil", - "last_name": "Drillingcourt", - "email": "ndrillingcourtv@berkeley.edu", - "country": "Indonesia", - "years_of_experience": 19, - "specialization": "react", - "certifications": "CFA" - }, { - "expert_id": 33, - "first_name": "Dannie", - "last_name": "Oxborough", - "email": "doxboroughw@salon.com", - "country": "Nicaragua", - "years_of_experience": 5, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 34, - "first_name": "Ax", - "last_name": "Hairesnape", - "email": "ahairesnapex@msn.com", - "country": "Spain", - "years_of_experience": 7, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 35, - "first_name": "Peyton", - "last_name": "Callway", - "email": "pcallwayy@plala.or.jp", - "country": "Honduras", - "years_of_experience": 4, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 36, - "first_name": "Gaby", - "last_name": "Fockes", - "email": "gfockesz@google.cn", - "country": "China", - "years_of_experience": 19, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 37, - "first_name": "Fidel", - "last_name": "Olenov", - "email": "folenov10@theglobeandmail.com", - "country": "China", - "years_of_experience": 1, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 38, - "first_name": "Celestina", - "last_name": "Sorby", - "email": "csorby11@google.cn", - "country": "Yemen", - "years_of_experience": 1, - "specialization": "react", - "certifications": "PMP" - }, { - "expert_id": 39, - "first_name": "Waylen", - "last_name": "Scrimshire", - "email": "wscrimshire12@barnesandnoble.com", - "country": "Poland", - "years_of_experience": 9, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 40, - "first_name": "Cleopatra", - "last_name": "Mailes", - "email": "cmailes13@thetimes.co.uk", - "country": "Mexico", - "years_of_experience": 19, - "specialization": "angular", - "certifications": "CFA" - }, { - "expert_id": 41, - "first_name": "Krishna", - "last_name": "Adaway", - "email": "kadaway14@bandcamp.com", - "country": "China", - "years_of_experience": 5, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 42, - "first_name": "Lorenzo", - "last_name": "Kitteridge", - "email": "lkitteridge15@ucoz.ru", - "country": "Indonesia", - "years_of_experience": 15, - "specialization": "Java", - "certifications": "CPA" - }, { - "expert_id": 43, - "first_name": "Mirabella", - "last_name": "McKissack", - "email": "mmckissack16@bandcamp.com", - "country": "Brazil", - "years_of_experience": 19, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 44, - "first_name": "Elizabet", - "last_name": "Maydwell", - "email": "emaydwell17@lycos.com", - "country": "Macedonia", - "years_of_experience": 14, - "specialization": "Java", - "certifications": "PMP" - }, { - "expert_id": 45, - "first_name": "Granthem", - "last_name": "Tonsley", - "email": "gtonsley18@cisco.com", - "country": "Vietnam", - "years_of_experience": 14, - "specialization": "Java", - "certifications": "CFA" - }, { - "expert_id": 46, - "first_name": "Irwinn", - "last_name": "Puddicombe", - "email": "ipuddicombe19@alexa.com", - "country": "Kenya", - "years_of_experience": 13, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 47, - "first_name": "Clarence", - "last_name": "Pimerick", - "email": "cpimerick1a@hhs.gov", - "country": "Mexico", - "years_of_experience": 18, - "specialization": "C++", - "certifications": "PMP" - }, { - "expert_id": 48, - "first_name": "Celia", - "last_name": "Challace", - "email": "cchallace1b@xing.com", - "country": "Ukraine", - "years_of_experience": 1, - "specialization": "react", - "certifications": "CFA" - }, { - "expert_id": 49, - "first_name": "Wilone", - "last_name": "Barends", - "email": "wbarends1c@seattletimes.com", - "country": "Thailand", - "years_of_experience": 2, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 50, - "first_name": "Rick", - "last_name": "Ingarfield", - "email": "ringarfield1d@marriott.com", - "country": "China", - "years_of_experience": 4, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 51, - "first_name": "Del", - "last_name": "Sawkins", - "email": "dsawkins1e@wix.com", - "country": "Indonesia", - "years_of_experience": 1, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 52, - "first_name": "Denice", - "last_name": "Lamburne", - "email": "dlamburne1f@ftc.gov", - "country": "France", - "years_of_experience": 11, - "specialization": "react", - "certifications": "CFA" - }, { - "expert_id": 53, - "first_name": "Vanessa", - "last_name": "Dopson", - "email": "vdopson1g@facebook.com", - "country": "South Korea", - "years_of_experience": 18, - "specialization": "react", - "certifications": "PMP" - }, { - "expert_id": 54, - "first_name": "Hermy", - "last_name": "Yakobovitz", - "email": "hyakobovitz1h@nasa.gov", - "country": "Bangladesh", - "years_of_experience": 19, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 55, - "first_name": "Gwenneth", - "last_name": "Tradewell", - "email": "gtradewell1i@soup.io", - "country": "Finland", - "years_of_experience": 15, - "specialization": "angular", - "certifications": "PHR" - }, { - "expert_id": 56, - "first_name": "Merrie", - "last_name": "Raffles", - "email": "mraffles1j@boston.com", - "country": "Guinea", - "years_of_experience": 1, - "specialization": "Java", - "certifications": "CFA" - }, { - "expert_id": 57, - "first_name": "Stafani", - "last_name": "Fidell", - "email": "sfidell1k@wikipedia.org", - "country": "Mexico", - "years_of_experience": 20, - "specialization": "Java", - "certifications": "PMP" - }, { - "expert_id": 58, - "first_name": "Bibbie", - "last_name": "Oxlade", - "email": "boxlade1l@hostgator.com", - "country": "Czech Republic", - "years_of_experience": 19, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 59, - "first_name": "Queenie", - "last_name": "Pierri", - "email": "qpierri1m@omniture.com", - "country": "Russia", - "years_of_experience": 10, - "specialization": "react", - "certifications": "PMP" - }, { - "expert_id": 60, - "first_name": "Maiga", - "last_name": "Bathowe", - "email": "mbathowe1n@angelfire.com", - "country": "Russia", - "years_of_experience": 5, - "specialization": "Java", - "certifications": "PMP" - }, { - "expert_id": 61, - "first_name": "Rolland", - "last_name": "Motherwell", - "email": "rmotherwell1o@ebay.com", - "country": "France", - "years_of_experience": 10, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 62, - "first_name": "Silvie", - "last_name": "Bedingfield", - "email": "sbedingfield1p@umn.edu", - "country": "Sweden", - "years_of_experience": 14, - "specialization": "react", - "certifications": "PMP" - }, { - "expert_id": 63, - "first_name": "Jacobo", - "last_name": "Feldhorn", - "email": "jfeldhorn1q@businesswire.com", - "country": "South Africa", - "years_of_experience": 3, - "specialization": "react", - "certifications": "CFA" - }, { - "expert_id": 64, - "first_name": "Gardener", - "last_name": "Veque", - "email": "gveque1r@fastcompany.com", - "country": "Colombia", - "years_of_experience": 9, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 65, - "first_name": "Cora", - "last_name": "Brunton", - "email": "cbrunton1s@example.com", - "country": "Tajikistan", - "years_of_experience": 6, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 66, - "first_name": "Lek", - "last_name": "Lambregts", - "email": "llambregts1t@cmu.edu", - "country": "Philippines", - "years_of_experience": 12, - "specialization": "Java", - "certifications": "CFA" - }, { - "expert_id": 67, - "first_name": "Arlan", - "last_name": "Colerick", - "email": "acolerick1u@mac.com", - "country": "Portugal", - "years_of_experience": 17, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 68, - "first_name": "Cicily", - "last_name": "Longea", - "email": "clongea1v@sohu.com", - "country": "China", - "years_of_experience": 19, - "specialization": "Java", - "certifications": "CPA" - }, { - "expert_id": 69, - "first_name": "William", - "last_name": "Stopford", - "email": "wstopford1w@scientificamerican.com", - "country": "Philippines", - "years_of_experience": 11, - "specialization": "C++", - "certifications": "CFA" - }, { - "expert_id": 70, - "first_name": "Wylie", - "last_name": "Esmonde", - "email": "wesmonde1x@springer.com", - "country": "China", - "years_of_experience": 8, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 71, - "first_name": "Hedi", - "last_name": "Fruish", - "email": "hfruish1y@slashdot.org", - "country": "Poland", - "years_of_experience": 17, - "specialization": "angular", - "certifications": "CPA" - }, { - "expert_id": 72, - "first_name": "Salome", - "last_name": "Dagwell", - "email": "sdagwell1z@ycombinator.com", - "country": "Thailand", - "years_of_experience": 20, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 73, - "first_name": "Berk", - "last_name": "Battrum", - "email": "bbattrum20@youtu.be", - "country": "Hungary", - "years_of_experience": 5, - "specialization": "react", - "certifications": "CFA" - }, { - "expert_id": 74, - "first_name": "Nevins", - "last_name": "MacCleod", - "email": "nmaccleod21@1und1.de", - "country": "Philippines", - "years_of_experience": 10, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 75, - "first_name": "Conni", - "last_name": "Tuddall", - "email": "ctuddall22@clickbank.net", - "country": "French Polynesia", - "years_of_experience": 15, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 76, - "first_name": "Osbourne", - "last_name": "Stollenbeck", - "email": "ostollenbeck23@narod.ru", - "country": "China", - "years_of_experience": 6, - "specialization": "Java", - "certifications": "CFA" - }, { - "expert_id": 77, - "first_name": "Dimitry", - "last_name": "Barnaby", - "email": "dbarnaby24@creativecommons.org", - "country": "Philippines", - "years_of_experience": 5, - "specialization": "Java", - "certifications": "CPA" - }, { - "expert_id": 78, - "first_name": "Peadar", - "last_name": "Fantin", - "email": "pfantin25@youtu.be", - "country": "Russia", - "years_of_experience": 17, - "specialization": "react", - "certifications": "PMP" - }, { - "expert_id": 79, - "first_name": "Chic", - "last_name": "Woodrow", - "email": "cwoodrow26@acquirethisname.com", - "country": "Brazil", - "years_of_experience": 2, - "specialization": "Java", - "certifications": "CFA" - }, { - "expert_id": 80, - "first_name": "Boote", - "last_name": "Toderi", - "email": "btoderi27@fema.gov", - "country": "Estonia", - "years_of_experience": 15, - "specialization": "angular", - "certifications": "CPA" - }, { - "expert_id": 81, - "first_name": "Maribel", - "last_name": "Furzer", - "email": "mfurzer28@ycombinator.com", - "country": "Brazil", - "years_of_experience": 9, - "specialization": "react", - "certifications": "CPA" - }, { - "expert_id": 82, - "first_name": "Ethelyn", - "last_name": "Rigglesford", - "email": "erigglesford29@wikipedia.org", - "country": "Philippines", - "years_of_experience": 13, - "specialization": "angular", - "certifications": "PHR" - }, { - "expert_id": 83, - "first_name": "Warren", - "last_name": "Bewick", - "email": "wbewick2a@flickr.com", - "country": "China", - "years_of_experience": 4, - "specialization": "Java", - "certifications": "PHR" - }, { - "expert_id": 84, - "first_name": "Aliza", - "last_name": "Callacher", - "email": "acallacher2b@infoseek.co.jp", - "country": "Ukraine", - "years_of_experience": 6, - "specialization": "angular", - "certifications": "PMP" - }, { - "expert_id": 85, - "first_name": "Court", - "last_name": "Lomasny", - "email": "clomasny2c@creativecommons.org", - "country": "China", - "years_of_experience": 18, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 86, - "first_name": "Sylvan", - "last_name": "McGuane", - "email": "smcguane2d@zimbio.com", - "country": "Czech Republic", - "years_of_experience": 4, - "specialization": "react", - "certifications": "CPA" - }, { - "expert_id": 87, - "first_name": "Case", - "last_name": "Dripps", - "email": "cdripps2e@tiny.cc", - "country": "Uzbekistan", - "years_of_experience": 7, - "specialization": "angular", - "certifications": "CPA" - }, { - "expert_id": 88, - "first_name": "Steven", - "last_name": "Sullly", - "email": "ssullly2f@ibm.com", - "country": "Mexico", - "years_of_experience": 19, - "specialization": "C++", - "certifications": "PMP" - }, { - "expert_id": 89, - "first_name": "Dari", - "last_name": "Lazare", - "email": "dlazare2g@samsung.com", - "country": "China", - "years_of_experience": 6, - "specialization": "react", - "certifications": "CPA" - }, { - "expert_id": 90, - "first_name": "Devina", - "last_name": "Glavias", - "email": "dglavias2h@blogspot.com", - "country": "Azerbaijan", - "years_of_experience": 17, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 91, - "first_name": "Nicolai", - "last_name": "Bleibaum", - "email": "nbleibaum2i@jigsy.com", - "country": "Vietnam", - "years_of_experience": 5, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 92, - "first_name": "Dieter", - "last_name": "Martland", - "email": "dmartland2j@nih.gov", - "country": "Indonesia", - "years_of_experience": 14, - "specialization": "C++", - "certifications": "CPA" - }, { - "expert_id": 93, - "first_name": "Estele", - "last_name": "Loudyan", - "email": "eloudyan2k@webs.com", - "country": "Indonesia", - "years_of_experience": 15, - "specialization": "angular", - "certifications": "CFA" - }, { - "expert_id": 94, - "first_name": "Gwenneth", - "last_name": "Scneider", - "email": "gscneider2l@cmu.edu", - "country": "Poland", - "years_of_experience": 2, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 95, - "first_name": "Mace", - "last_name": "Brant", - "email": "mbrant2m@ezinearticles.com", - "country": "China", - "years_of_experience": 16, - "specialization": "angular", - "certifications": "CPA" - }, { - "expert_id": 96, - "first_name": "Amandie", - "last_name": "Besant", - "email": "abesant2n@discuz.net", - "country": "Portugal", - "years_of_experience": 11, - "specialization": "C++", - "certifications": "PHR" - }, { - "expert_id": 97, - "first_name": "Herc", - "last_name": "Hedingham", - "email": "hhedingham2o@infoseek.co.jp", - "country": "Brazil", - "years_of_experience": 16, - "specialization": "react", - "certifications": "PHR" - }, { - "expert_id": 98, - "first_name": "Paloma", - "last_name": "McGurgan", - "email": "pmcgurgan2p@scribd.com", - "country": "Czech Republic", - "years_of_experience": 13, - "specialization": "angular", - "certifications": "CFA" - }, { - "expert_id": 99, - "first_name": "Cortie", - "last_name": "Beaufoy", - "email": "cbeaufoy2q@pagesperso-orange.fr", - "country": "Philippines", - "years_of_experience": 13, - "specialization": "Java", - "certifications": "PMP" - }, { - "expert_id": 100, - "first_name": "Willyt", - "last_name": "Lauderdale", - "email": "wlauderdale2r@shutterfly.com", - "country": "Indonesia", - "years_of_experience": 4, - "specialization": "angular", - "certifications": "PMP" - }] \ No newline at end of file + } +] \ No newline at end of file diff --git a/models/expfind.py b/models/expfind.py index b841228d3..944234c83 100644 --- a/models/expfind.py +++ b/models/expfind.py @@ -1,19 +1,22 @@ import openai import json -# Chargez le fichier JSON local -with open("C:\\Users\\7john\\OneDrive\\Documents\\stage\\backend\\IAGORA-API\\data\\donnerExperts.json", "r") as file: - developers = json.load(file) - json_data = json.dumps(developers) -# Appeler l'API GPT -response = openai.Completion.create( - engine='text-davinci-003', - prompt = f"""{json_data}\n\nRecherche des développeurs angular avec plus de 3 ans d'expérience :""", - max_tokens= 10000 -) +class ExpFind: + def findExp(message): + # Chargez le fichier JSON local + with open("\IAGORA-API\\data\\donnerExperts.json", "r") as file: + developers = json.load(file) + json_data = json.dumps(developers) + # Appeler l'API GPT + response = openai.Completion.create( + engine='text-davinci-003', + prompt = f"""{json_data}\n\n{message} :""", + max_tokens= 1000 + ) -# Traiter la réponse -answer = response.choices[0].text.strip() + # Traiter la réponse + answer = response.choices[0].text.strip() -# Afficher la réponse -print(answer) \ No newline at end of file + # Afficher la réponse + print(answer) + return answer \ No newline at end of file From b72a5100031f64c03d8f6397657ab3b1c616eba4 Mon Sep 17 00:00:00 2001 From: Nomena Date: Sun, 24 Sep 2023 17:50:44 +0300 Subject: [PATCH 17/24] feature:add tutorat choices --- app.py | 34 ++++++++++++++++++++++++++++++---- models/txtmodel.py | 11 ++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index a417bfe3d..0d3b55bbc 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,11 @@ from flask import Flask, request app = Flask(__name__) -import json - from flask_cors import CORS +import json +import gensim from flask import Response - from models import llm from models import txtmodel from models import jsonloader @@ -18,11 +17,38 @@ def hello_world(): return 'Hello, World!' +# Charger le modèle pré-entraîné de Word2Vec en français +model = gensim.models.KeyedVectors.load_word2vec_format("models/frWac_non_lem_no_postag_no_phrase_200_skip_cut100.bin", binary=True) + +# Fonction pour obtenir des synonymes d'un mot avec le modèle Word2Vec +def get_synonyms(word): + synonyms = [] + # Vérifier si le mot est dans le vocabulaire du modèle + if word in model.key_to_index: + # Obtenir les 10 mots les plus similaires au mot donné + similar_words = model.most_similar(word, topn=1000) + # Extraire les mots des tuples (mot, similarité) + for word, similarity in similar_words: + synonyms.append(word) + return synonyms + @app.route("/ask", methods=["POST"]) def ask(): question = request.get_json() - return (txtmodel.txtmodel.get_response(question['query'])) + response = txtmodel.txtmodel.get_response(question['query']) + + # Vérifier si un synonyme de "apprendre" est présent dans la requête + synonyms_learn = get_synonyms("apprendre") # Utiliser le mot "apprendre" en français pour utiliser le modèle Word2Vec + query_lower = question['query'].lower() + + synonym_found = any(synonym in query_lower for synonym in synonyms_learn) + # Imprimer "Tuteur Virtuel" et "Tuteur Réel" si un synonyme de "apprendre" est trouvé + if synonym_found: + print("Tuteur Virtuel") + print("Tuteur Réel") + + return response @app.route("/llm", methods=["POST"]) def llm_route(): diff --git a/models/txtmodel.py b/models/txtmodel.py index a3b306309..e1e77775a 100644 --- a/models/txtmodel.py +++ b/models/txtmodel.py @@ -8,6 +8,15 @@ class txtmodel(): def get_response(question): chat = ChatOpenAI() + conversation = ConversationChain(llm=chat) - conversation = ConversationChain(llm=chat) + # Si l'étudiant a cliqué sur "Tuteur Virtuel" + if question.lower() == "virtual_tutor": + return "Vous avez choisi le Tuteur Virtuel. Comment puis-je vous aider davantage ?" + + # Si l'étudiant a cliqué sur "Tuteur Réel" + elif question.lower() == "real_tutor": + return "Vous avez choisi le Tuteur Réel. Un tuteur réel sera disponible pour vous aider." + + # Sinon, traiter la question normalement return conversation.run(question) From d29a55183a69ce54b691f77a5a301fab1576b8ed Mon Sep 17 00:00:00 2001 From: Ony Date: Sun, 24 Sep 2023 20:44:02 +0300 Subject: [PATCH 18/24] update ask endpoint --- app.py | 15 ++++++++++----- models/expfind.py | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 0d3b55bbc..cdfaf82c0 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, request +from flask import Flask, request, jsonify app = Flask(__name__) from flask_cors import CORS @@ -35,7 +35,10 @@ def get_synonyms(word): @app.route("/ask", methods=["POST"]) def ask(): question = request.get_json() - response = txtmodel.txtmodel.get_response(question['query']) + response = { + "text": txtmodel.txtmodel.get_response(question['query']), + "wantToLearn": False + } # Vérifier si un synonyme de "apprendre" est présent dans la requête synonyms_learn = get_synonyms("apprendre") # Utiliser le mot "apprendre" en français pour utiliser le modèle Word2Vec @@ -45,10 +48,12 @@ def ask(): # Imprimer "Tuteur Virtuel" et "Tuteur Réel" si un synonyme de "apprendre" est trouvé if synonym_found: - print("Tuteur Virtuel") - print("Tuteur Réel") + response = { + "text": "Veuillez Choisir", + "wantToLearn": True + } - return response + return jsonify(response) @app.route("/llm", methods=["POST"]) def llm_route(): diff --git a/models/expfind.py b/models/expfind.py index 944234c83..70e4fc180 100644 --- a/models/expfind.py +++ b/models/expfind.py @@ -1,10 +1,12 @@ import openai +import os import json +data_dir = os.path.join(os.path.dirname(__file__), "..", "data") class ExpFind: def findExp(message): # Chargez le fichier JSON local - with open("\IAGORA-API\\data\\donnerExperts.json", "r") as file: + with open(os.path.join(data_dir, "donnerExperts.json"), "r") as file: developers = json.load(file) json_data = json.dumps(developers) # Appeler l'API GPT From d5541d6fbd27a988083332f3d4bfced27f190acf Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Tue, 26 Sep 2023 20:23:51 +0300 Subject: [PATCH 19/24] Create oraclecnx.py --- models/oraclecnx.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 models/oraclecnx.py diff --git a/models/oraclecnx.py b/models/oraclecnx.py new file mode 100644 index 000000000..e69de29bb From e6edfa481b7483f81248165bf4f24e2093d2c736 Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:12:27 +0300 Subject: [PATCH 20/24] Create findstage.py --- models/findstage.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 models/findstage.py diff --git a/models/findstage.py b/models/findstage.py new file mode 100644 index 000000000..cbc478261 --- /dev/null +++ b/models/findstage.py @@ -0,0 +1,32 @@ +import openai + +# data_dir = os.path.join(os.path.dirname(__file__), "..", "data") +# class Findstage: +# def findstage(message): +# # Appeler l'API GPT +# response = openai.Completion.create( +# engine='text-davinci-003', +# prompt = f"""{json_data}\n\n{message} :""", +# max_tokens= 1000 +# ) + +# # Traiter la réponse +# answer = response.choices[0].text.strip() + +# # Afficher la réponse +# print(answer) +# return answer + + +response = openai.Completion.create( +engine='text-davinci-003', +# prompt = f"""{json_data}\n\n{message} :""", +prompt = "peux tu generer des requetes pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, renumeration et avec le prompt que j'utilise utilise une requette sql. voici mon promt : je veux un stage en java remunerer et retourn seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant", +max_tokens= 1000 + ) + + # Traiter la réponse +answer = response.choices[0].text.strip() + + # Affiher la réponse +print(answer) \ No newline at end of file From 8d9d2825872c2e07765db26a53faacbf4b19a01a Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:39:43 +0300 Subject: [PATCH 21/24] Update findstage.py --- models/findstage.py | 63 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/models/findstage.py b/models/findstage.py index cbc478261..0baabdfd5 100644 --- a/models/findstage.py +++ b/models/findstage.py @@ -1,32 +1,43 @@ import openai - -# data_dir = os.path.join(os.path.dirname(__file__), "..", "data") -# class Findstage: -# def findstage(message): -# # Appeler l'API GPT -# response = openai.Completion.create( -# engine='text-davinci-003', -# prompt = f"""{json_data}\n\n{message} :""", -# max_tokens= 1000 -# ) - -# # Traiter la réponse -# answer = response.choices[0].text.strip() - -# # Afficher la réponse -# print(answer) -# return answer - - -response = openai.Completion.create( -engine='text-davinci-003', -# prompt = f"""{json_data}\n\n{message} :""", -prompt = "peux tu generer des requetes pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, renumeration et avec le prompt que j'utilise utilise une requette sql. voici mon promt : je veux un stage en java remunerer et retourn seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant", -max_tokens= 1000 +import oraclecnx +import json +class Findstage: + def findstage(message): + # Appeler l'API GPT + response = openai.Completion.create( + engine='text-davinci-003', + # prompt = f"""{json_data}\n\n{message} :""", + prompt = f""""peux tu generer des requetes pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, remuneration et avec le prompt que j'utilise utilise une requette sql. + voici mon promt : \n\n{message}\n\n + et retourne seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant""", + + max_tokens= 1000 ) # Traiter la réponse -answer = response.choices[0].text.strip() + answer = response.choices[0].text.strip() # Affiher la réponse -print(answer) \ No newline at end of file + print(answer) + + cursor = oraclecnx.cursor() + cursor.execute(answer) + result = cursor.fetchall() + + data_as_json = [] + + for row in result: + data_as_json.append({ + "id": row[0], + "nom": row[1], + "contexte": row[2], + "remuneration": row[3] + }) + + cursor.close() + oraclecnx.close() + + json_data = json.dumps(data_as_json, indent=4) + + return json_data + \ No newline at end of file From 641696abb5090832d0fb2e5a8567007ed5c8594c Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:49:11 +0300 Subject: [PATCH 22/24] Update findstage.py --- models/findstage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/findstage.py b/models/findstage.py index 0baabdfd5..6535dc500 100644 --- a/models/findstage.py +++ b/models/findstage.py @@ -7,7 +7,7 @@ def findstage(message): response = openai.Completion.create( engine='text-davinci-003', # prompt = f"""{json_data}\n\n{message} :""", - prompt = f""""peux tu generer des requetes pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, remuneration et avec le prompt que j'utilise utilise une requette sql. + prompt = f""""peux tu generer une requete pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, remuneration et avec le prompt que j'utilise utilise une requette sql. voici mon promt : \n\n{message}\n\n et retourne seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant""", From 12c024e168b5fbef37f5a92d84e51b2f80467ca0 Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:57:19 +0300 Subject: [PATCH 23/24] DAO --- models/daollm.py | 35 +++++++++++++++++++++++++++++++++++ models/findstage.py | 2 +- models/oraclecnx.py | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 models/daollm.py diff --git a/models/daollm.py b/models/daollm.py new file mode 100644 index 000000000..a04579e2d --- /dev/null +++ b/models/daollm.py @@ -0,0 +1,35 @@ +from langchain import OpenAI, Cohere, sql_database +from langchain_experimental.sql import SQLDatabaseChain +import cx_Oracle +import os +from langchain.chains import load_chain +import os + +COHERE_API_KEY="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" +os.environ["COHERE_API_KEY"] = COHERE_API_KEY + +lib_dir = os.path.join(os.environ.get("HOME"), "Development", "instantclient_19_8") +cx_Oracle.init_oracle_client(lib_dir=lib_dir) + +hostname='localhost' +port='1521' +service_name='ORCLCDB' +username='c##iagora' +password='iagora' + +cx_Oracle.init_oracle_client(lib_dir=lib_dir) +oracle_connection_string_fmt = ( + 'oracle+cx_oracle://{username}:{password}@' + + cx_Oracle.makedsn('{hostname}', '{port}', service_name='{service_name}') +) +url = oracle_connection_string_fmt.format( + username=username, password=password, + hostname=hostname, port=port, + service_name=service_name, +) +from sqlalchemy import create_engine +engine=create_engine(url, echo=True) +db = SQLDatabase(engine) +llm = Cohere(temperature=1, verbose=True) +db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True) +db_chain.run("Is Casey Brown in the database?") \ No newline at end of file diff --git a/models/findstage.py b/models/findstage.py index 6535dc500..0dab5e33d 100644 --- a/models/findstage.py +++ b/models/findstage.py @@ -8,7 +8,7 @@ def findstage(message): engine='text-davinci-003', # prompt = f"""{json_data}\n\n{message} :""", prompt = f""""peux tu generer une requete pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, remuneration et avec le prompt que j'utilise utilise une requette sql. - voici mon promt : \n\n{message}\n\n + voici mon prompt : \n\n{message}\n\n et retourne seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant""", max_tokens= 1000 diff --git a/models/oraclecnx.py b/models/oraclecnx.py index e69de29bb..424f57d36 100644 --- a/models/oraclecnx.py +++ b/models/oraclecnx.py @@ -0,0 +1,15 @@ +import cx_Oracle + +class Oraclecnx: + def dbcon(connection): +# Informations de connexion + host = "localhost" + port = 1521 + service_name = "ORCLCDB" + +# Créer une connexion + connection = cx_Oracle.connect(user="c##iagora", password="iagora", dsn=f"{host}:{port}/{service_name}") + +# Afficher le nom de la base de données + print(connection.database) + return connection From 29b12d1a14436f2bb10cdb87661e0f69b913fe89 Mon Sep 17 00:00:00 2001 From: john <60197372+john7373@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:56:37 +0300 Subject: [PATCH 24/24] john commit --- app.py | 7 +++++++ models/findstage.py | 45 +++++++++++++-------------------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/app.py b/app.py index cdfaf82c0..d559a28f9 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ from models import txtmodel from models import jsonloader from models import expfind +from models import findstage CORS(app) @@ -71,3 +72,9 @@ def loadjson(): requete = request.get_json() results = expfind.ExpFind.findExp(requete['message']) return results + +@app.route("/stage", methods=["POST"]) +def stage(): + requete = request.get_json() + results = findstage.Findstage.finds(requete['message']) + return results \ No newline at end of file diff --git a/models/findstage.py b/models/findstage.py index 0dab5e33d..ffe28f719 100644 --- a/models/findstage.py +++ b/models/findstage.py @@ -1,43 +1,24 @@ import openai -import oraclecnx +import os import json + +data_dir = os.path.join(os.path.dirname(__file__), "..", "data") class Findstage: - def findstage(message): + def finds(message): + # Chargez le fichier JSON local + with open(os.path.join(data_dir, "MOC.json"), "r") as file: + developers = json.load(file) + json_data = json.dumps(developers) # Appeler l'API GPT response = openai.Completion.create( - engine='text-davinci-003', - # prompt = f"""{json_data}\n\n{message} :""", - prompt = f""""peux tu generer une requete pour une base de donner par example j'ai une table stage, les collones sont id, nom, context, remuneration et avec le prompt que j'utilise utilise une requette sql. - voici mon prompt : \n\n{message}\n\n - et retourne seulement un script sql et la remuneration n'a pas besoin de devise seulement un montant aproximative ou existant""", - - max_tokens= 1000 + engine='text-davinci-003', + prompt = f"""{json_data}\n\n{message} :""", + max_tokens= 1000 ) # Traiter la réponse answer = response.choices[0].text.strip() - # Affiher la réponse + # Afficher la réponse print(answer) - - cursor = oraclecnx.cursor() - cursor.execute(answer) - result = cursor.fetchall() - - data_as_json = [] - - for row in result: - data_as_json.append({ - "id": row[0], - "nom": row[1], - "contexte": row[2], - "remuneration": row[3] - }) - - cursor.close() - oraclecnx.close() - - json_data = json.dumps(data_as_json, indent=4) - - return json_data - \ No newline at end of file + return answer \ No newline at end of file