Spaces:
Sleeping
Sleeping
Update src/config.py
Browse files- src/config.py +74 -74
src/config.py
CHANGED
|
@@ -1,74 +1,74 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
load_dotenv()
|
| 4 |
-
from langchain_groq import ChatGroq
|
| 5 |
-
from langchain_community.document_loaders import PyPDFLoader
|
| 6 |
-
from langchain_openai import ChatOpenAI
|
| 7 |
-
from typing import Dict, List, Any, Tuple, Optional, Type
|
| 8 |
-
from crewai import LLM
|
| 9 |
-
#########################################################################################################
|
| 10 |
-
# formatage du json
|
| 11 |
-
def format_cv(document):
|
| 12 |
-
def format_section(title, data, indent=0):
|
| 13 |
-
prefix = " " * indent
|
| 14 |
-
lines = [f"{title}:"]
|
| 15 |
-
if isinstance(data, dict):
|
| 16 |
-
for k, v in data.items():
|
| 17 |
-
if isinstance(v, (dict, list)):
|
| 18 |
-
lines.append(f"{prefix}- {k.capitalize()}:")
|
| 19 |
-
lines.extend(format_section("", v, indent + 1))
|
| 20 |
-
else:
|
| 21 |
-
lines.append(f"{prefix}- {k.capitalize()}: {v}")
|
| 22 |
-
elif isinstance(data, list):
|
| 23 |
-
for i, item in enumerate(data):
|
| 24 |
-
lines.append(f"{prefix}- Élément {i + 1}:")
|
| 25 |
-
lines.extend(format_section("", item, indent + 1))
|
| 26 |
-
else:
|
| 27 |
-
lines.append(f"{prefix}- {data}")
|
| 28 |
-
return lines
|
| 29 |
-
sections = []
|
| 30 |
-
for section_name, content in document.items():
|
| 31 |
-
title = section_name.replace("_", " ").capitalize()
|
| 32 |
-
sections.extend(format_section(title, content))
|
| 33 |
-
sections.append("")
|
| 34 |
-
return "\n".join(sections)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def read_system_prompt(file_path):
|
| 38 |
-
with open(file_path, 'r', encoding='utf-8') as file:
|
| 39 |
-
return file.read()
|
| 40 |
-
|
| 41 |
-
def load_pdf(pdf_path):
|
| 42 |
-
loader = PyPDFLoader(pdf_path)
|
| 43 |
-
pages = loader.load_and_split()
|
| 44 |
-
cv_text = ""
|
| 45 |
-
for page in pages:
|
| 46 |
-
cv_text += page.page_content + "\n\n"
|
| 47 |
-
return cv_text
|
| 48 |
-
|
| 49 |
-
#########################################################################################################
|
| 50 |
-
# modéles
|
| 51 |
-
|
| 52 |
-
"""GEMINI_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 53 |
-
model_google = "gemini/gemma-3-27b-it"
|
| 54 |
-
def chat_gemini():
|
| 55 |
-
llm = ChatGoogleGenerativeAI("gemini/gemma-3-27b-it")"""
|
| 56 |
-
|
| 57 |
-
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 58 |
-
model_openai = "gpt-4o"
|
| 59 |
-
|
| 60 |
-
def crew_openai():
|
| 61 |
-
llm = ChatOpenAI(
|
| 62 |
-
model="gpt-4o-mini",
|
| 63 |
-
temperature=0
|
| 64 |
-
api_key=OPENAI_API_KEY
|
| 65 |
-
)
|
| 66 |
-
return llm
|
| 67 |
-
|
| 68 |
-
def chat_openai():
|
| 69 |
-
llm = ChatOpenAI(
|
| 70 |
-
model="gpt-4o",
|
| 71 |
-
temperature=0
|
| 72 |
-
api_key=OPENAI_API_KEY
|
| 73 |
-
)
|
| 74 |
-
return llm
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
load_dotenv()
|
| 4 |
+
from langchain_groq import ChatGroq
|
| 5 |
+
from langchain_community.document_loaders import PyPDFLoader
|
| 6 |
+
from langchain_openai import ChatOpenAI
|
| 7 |
+
from typing import Dict, List, Any, Tuple, Optional, Type
|
| 8 |
+
from crewai import LLM
|
| 9 |
+
#########################################################################################################
|
| 10 |
+
# formatage du json
|
| 11 |
+
def format_cv(document):
|
| 12 |
+
def format_section(title, data, indent=0):
|
| 13 |
+
prefix = " " * indent
|
| 14 |
+
lines = [f"{title}:"]
|
| 15 |
+
if isinstance(data, dict):
|
| 16 |
+
for k, v in data.items():
|
| 17 |
+
if isinstance(v, (dict, list)):
|
| 18 |
+
lines.append(f"{prefix}- {k.capitalize()}:")
|
| 19 |
+
lines.extend(format_section("", v, indent + 1))
|
| 20 |
+
else:
|
| 21 |
+
lines.append(f"{prefix}- {k.capitalize()}: {v}")
|
| 22 |
+
elif isinstance(data, list):
|
| 23 |
+
for i, item in enumerate(data):
|
| 24 |
+
lines.append(f"{prefix}- Élément {i + 1}:")
|
| 25 |
+
lines.extend(format_section("", item, indent + 1))
|
| 26 |
+
else:
|
| 27 |
+
lines.append(f"{prefix}- {data}")
|
| 28 |
+
return lines
|
| 29 |
+
sections = []
|
| 30 |
+
for section_name, content in document.items():
|
| 31 |
+
title = section_name.replace("_", " ").capitalize()
|
| 32 |
+
sections.extend(format_section(title, content))
|
| 33 |
+
sections.append("")
|
| 34 |
+
return "\n".join(sections)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def read_system_prompt(file_path):
|
| 38 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 39 |
+
return file.read()
|
| 40 |
+
|
| 41 |
+
def load_pdf(pdf_path):
|
| 42 |
+
loader = PyPDFLoader(pdf_path)
|
| 43 |
+
pages = loader.load_and_split()
|
| 44 |
+
cv_text = ""
|
| 45 |
+
for page in pages:
|
| 46 |
+
cv_text += page.page_content + "\n\n"
|
| 47 |
+
return cv_text
|
| 48 |
+
|
| 49 |
+
#########################################################################################################
|
| 50 |
+
# modéles
|
| 51 |
+
|
| 52 |
+
"""GEMINI_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 53 |
+
model_google = "gemini/gemma-3-27b-it"
|
| 54 |
+
def chat_gemini():
|
| 55 |
+
llm = ChatGoogleGenerativeAI("gemini/gemma-3-27b-it")"""
|
| 56 |
+
|
| 57 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 58 |
+
model_openai = "gpt-4o"
|
| 59 |
+
|
| 60 |
+
def crew_openai():
|
| 61 |
+
llm = ChatOpenAI(
|
| 62 |
+
model="gpt-4o-mini",
|
| 63 |
+
temperature=0,
|
| 64 |
+
api_key=OPENAI_API_KEY
|
| 65 |
+
)
|
| 66 |
+
return llm
|
| 67 |
+
|
| 68 |
+
def chat_openai():
|
| 69 |
+
llm = ChatOpenAI(
|
| 70 |
+
model="gpt-4o",
|
| 71 |
+
temperature=0,
|
| 72 |
+
api_key=OPENAI_API_KEY
|
| 73 |
+
)
|
| 74 |
+
return llm
|