Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #41

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ venv.bak/
/site

# mypy
.mypy_cache/
.mypy_cache/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/).
76 changes: 75 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,80 @@
from flask import Flask
from flask import Flask, request, jsonify
app = Flask(__name__)

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
from models import expfind
from models import findstage


CORS(app)
@app.route('/')
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()
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
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:
response = {
"text": "Veuillez Choisir",
"wantToLearn": True
}

return jsonify(response)

@app.route("/llm", methods=["POST"])
def llm_route():
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("/expert", methods=["POST"])
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
92 changes: 92 additions & 0 deletions data/donnerExperts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[{
"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"
}
]
Empty file added models/__init__.py
Empty file.
35 changes: 35 additions & 0 deletions models/daollm.py
Original file line number Diff line number Diff line change
@@ -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?")
9 changes: 9 additions & 0 deletions models/embedding.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions models/expfind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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(os.path.join(data_dir, "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()

# Afficher la réponse
print(answer)
return answer
24 changes: 24 additions & 0 deletions models/findstage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import openai
import os
import json

data_dir = os.path.join(os.path.dirname(__file__), "..", "data")
class Findstage:
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} :""",
max_tokens= 1000
)

# Traiter la réponse
answer = response.choices[0].text.strip()

# Afficher la réponse
print(answer)
return answer
29 changes: 29 additions & 0 deletions models/jsonloader.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions models/keymodel.py
Original file line number Diff line number Diff line change
@@ -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", "")
Loading