Update main.py
Browse files
main.py
CHANGED
@@ -8,8 +8,7 @@ import uuid
|
|
8 |
import langsmith as ls
|
9 |
from pathlib import Path
|
10 |
import chainlit as cl
|
11 |
-
|
12 |
-
#from mistralai import Mistral, UserMessage, SystemMessage
|
13 |
from deep_translator import GoogleTranslator
|
14 |
from operator import itemgetter
|
15 |
from langchain_huggingface import HuggingFaceEndpoint
|
@@ -17,10 +16,12 @@ from langchain.schema.runnable import Runnable, RunnablePassthrough, RunnableLam
|
|
17 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
18 |
from langchain.memory import ChatMessageHistory, ConversationBufferMemory
|
19 |
from langchain.schema.runnable.config import RunnableConfig
|
|
|
|
|
20 |
|
21 |
from offres_emploi import Api
|
22 |
from offres_emploi.utils import dt_to_str_iso
|
23 |
-
|
24 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.environ['HUGGINGFACEHUB_API_TOKEN']
|
25 |
|
26 |
session_id = str(uuid.uuid4())
|
@@ -81,6 +82,13 @@ def connexion_France_Travail():
|
|
81 |
client_secret=os.getenv('POLE_EMPLOI_CLIENT_SECRET'))
|
82 |
return client
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
@traceable(run_type="chain", name="API France Travail : recherche par code ROME",)
|
85 |
def API_France_Travail_ROME(romeListArray):
|
86 |
client = connexion_France_Travail()
|
@@ -109,19 +117,28 @@ def API_France_Travail_ROME(romeListArray):
|
|
109 |
|
110 |
@traceable(run_type="chain", name="API France Travail : recherche par métier type",)
|
111 |
def API_France_Travail_Metier(metier):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
client = connexion_France_Travail()
|
113 |
todayDate = datetime.datetime.today()
|
114 |
month, year = (todayDate.month-1, todayDate.year) if todayDate.month != 1 else (12, todayDate.year-1)
|
115 |
start_dt = todayDate.replace(day=1, month=month, year=year)
|
116 |
end_dt = datetime.datetime.today()
|
117 |
results = []
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
125 |
results_df = pd.DataFrame(results)
|
126 |
return results_df
|
127 |
|
|
|
8 |
import langsmith as ls
|
9 |
from pathlib import Path
|
10 |
import chainlit as cl
|
11 |
+
|
|
|
12 |
from deep_translator import GoogleTranslator
|
13 |
from operator import itemgetter
|
14 |
from langchain_huggingface import HuggingFaceEndpoint
|
|
|
16 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
17 |
from langchain.memory import ChatMessageHistory, ConversationBufferMemory
|
18 |
from langchain.schema.runnable.config import RunnableConfig
|
19 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
20 |
+
from langchain_pinecone import PineconeVectorStore
|
21 |
|
22 |
from offres_emploi import Api
|
23 |
from offres_emploi.utils import dt_to_str_iso
|
24 |
+
|
25 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.environ['HUGGINGFACEHUB_API_TOKEN']
|
26 |
|
27 |
session_id = str(uuid.uuid4())
|
|
|
82 |
client_secret=os.getenv('POLE_EMPLOI_CLIENT_SECRET'))
|
83 |
return client
|
84 |
|
85 |
+
def connexion_vector_database():
|
86 |
+
os.environ['PINECONE_API_KEY'] = os.environ['PINECONE_API_KEY']
|
87 |
+
os.environ['PINECONE_INDEX_NAME'] = os.environ['PINECONE_INDEX_NAME'] = 'all-skills'
|
88 |
+
embeddings = HuggingFaceEmbeddings()
|
89 |
+
docsearch = PineconeVectorStore.from_existing_index(os.environ['PINECONE_INDEX_NAME'], embeddings)
|
90 |
+
return docsearch
|
91 |
+
|
92 |
@traceable(run_type="chain", name="API France Travail : recherche par code ROME",)
|
93 |
def API_France_Travail_ROME(romeListArray):
|
94 |
client = connexion_France_Travail()
|
|
|
117 |
|
118 |
@traceable(run_type="chain", name="API France Travail : recherche par métier type",)
|
119 |
def API_France_Travail_Metier(metier):
|
120 |
+
os.environ['PINECONE_API_KEYROME'] = os.environ['PINECONE_API_KEYROME']
|
121 |
+
docsearch = await connexion_vector_database()
|
122 |
+
retrieve_comp = docsearch.similarity_search(metier, k=2, filter={"categorie": {"$eq": os.environ['PINECONE_API_KEYROME']}})
|
123 |
+
codeRome = []
|
124 |
+
for i in range(0,len(retrieve_comp)):
|
125 |
+
codeRome.append(retrieve_comp[i].metadata['code_rome'])
|
126 |
+
|
127 |
client = connexion_France_Travail()
|
128 |
todayDate = datetime.datetime.today()
|
129 |
month, year = (todayDate.month-1, todayDate.year) if todayDate.month != 1 else (12, todayDate.year-1)
|
130 |
start_dt = todayDate.replace(day=1, month=month, year=year)
|
131 |
end_dt = datetime.datetime.today()
|
132 |
results = []
|
133 |
+
|
134 |
+
for k in codeRome:
|
135 |
+
params = {"motsCles": k,'minCreationDate': dt_to_str_iso(start_dt),'maxCreationDate': dt_to_str_iso(end_dt),'range':'0-149'}
|
136 |
+
try:
|
137 |
+
search_on_big_data = client.search(params=params)
|
138 |
+
results += search_on_big_data["resultats"]
|
139 |
+
except:
|
140 |
+
print("Il n'y a pas d'offres d'emploi.")
|
141 |
+
|
142 |
results_df = pd.DataFrame(results)
|
143 |
return results_df
|
144 |
|