Skip to content
Closed
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
Binary file not shown.
Binary file not shown.
Binary file added artificial_agents/Políticas de Home Office.pdf
Binary file not shown.
123 changes: 123 additions & 0 deletions artificial_agents/agentes de ia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# %%

Check failure on line 1 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

artificial_agents/agentes de ia.py:1:1: INP001 File `artificial_agents/agentes de ia.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

artificial_agents/agentes de ia.py:1:1: INP001 File `artificial_agents/agentes de ia.py` is part of an implicit namespace package. Add an `__init__.py`.
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI

load_dotenv()

google_api_key = os.environ.get("API_KEY")

# %%

TRIAGEM_PROMPT = (
"Você é um triador de Service Desk para políticas internas da empresa Carraro Desenvolvimento. "

Check failure on line 13 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:13:89: E501 Line too long (100 > 88)

Check failure on line 13 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:13:89: E501 Line too long (100 > 88)
"Dada a mensagem do usuário, retorne SOMENTE um JSON com:\n"
"{\n"
' "decisao": "AUTO_RESOLVER" | "PEDIR_INFO" | "ABRIR_CHAMADO",\n'
' "urgencia": "BAIXA" | "MEDIA" | "ALTA",\n'
' "campos_faltantes": ["..."]\n'
"}\n"
"Regras:\n"
'- **AUTO_RESOLVER**: Perguntas claras sobre regras ou procedimentos descritos nas políticas (Ex: "Posso reembolsar a internet do meu home office?", "Como funciona a política de alimentação em viagens?").\n'

Check failure on line 21 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:21:89: E501 Line too long (211 > 88)

Check failure on line 21 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:21:89: E501 Line too long (211 > 88)
'- **PEDIR_INFO**: Mensagens vagas ou que faltam informações para identificar o tema ou contexto (Ex: "Preciso de ajuda com uma política", "Tenho uma dúvida geral").\n'

Check failure on line 22 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:22:89: E501 Line too long (172 > 88)

Check failure on line 22 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:22:89: E501 Line too long (172 > 88)
'- **ABRIR_CHAMADO**: Pedidos de exceção, liberação, aprovação ou acesso especial, ou quando o usuário explicitamente pede para abrir um chamado (Ex: "Quero exceção para trabalhar 5 dias remoto.", "Solicito liberação para anexos externos.", "Por favor, abra um chamado para o RH.").'

Check failure on line 23 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:23:89: E501 Line too long (287 > 88)

Check failure on line 23 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

artificial_agents/agentes de ia.py:23:89: E501 Line too long (287 > 88)
"Analise a mensagem e decida a ação mais apropriada."

Check failure on line 25 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:25:1: W293 Blank line contains whitespace

Check failure on line 25 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:25:1: W293 Blank line contains whitespace
"""
decisao: AUTO_RESOLVER

Check failure on line 27 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

artificial_agents/agentes de ia.py:27:27: W291 Trailing whitespace

Check failure on line 27 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

artificial_agents/agentes de ia.py:27:27: W291 Trailing whitespace
ugencia: BAIXA
campos_faltantes: []
"""
)
# %%

from pydantic import BaseModel, Field
from typing import Literal, List, Dict

class TriagemOut(BaseModel):
decisao: Literal["AUTO_RESOLVER", "PEDIR_INFO", "ABRIR_CHAMADO"]
urgencia: Literal["BAIXA", "MEDIA", "ALTA"]

Check failure on line 39 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

artificial_agents/agentes de ia.py:39:48: W291 Trailing whitespace

Check failure on line 39 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

artificial_agents/agentes de ia.py:39:48: W291 Trailing whitespace
campos_faltantes: List[str] = Field(default_factory=list)

Check failure on line 41 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:41:1: W293 Blank line contains whitespace

Check failure on line 41 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:41:1: W293 Blank line contains whitespace
# %%

Check failure on line 43 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:43:1: W293 Blank line contains whitespace

Check failure on line 43 in artificial_agents/agentes de ia.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

artificial_agents/agentes de ia.py:43:1: W293 Blank line contains whitespace
llm_triagem = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0.0, api_key=google_api_key)
# %%

from langchain_core.messages import SystemMessage, HumanMessage

triagem_chain = llm_triagem.with_structured_output(TriagemOut)

def triagem(mensagem: str) -> Dict:
saida: TriagemOut = triagem_chain.invoke([SystemMessage(content=TRIAGEM_PROMPT), HumanMessage(content=mensagem)])
return saida.model_dump()
# %%

testes = ["posso reembolsar a internet?", "Quero ter mais 5 dias remoto?", "Como sacar o pino do coquilho traseiro do guindaste zunlaine 75"]

for msg_test in testes:
print(f"Pergunta: {msg_test}\n -> Resposta: {triagem(msg_test)}\n")

# %%

from pathlib import Path
from langchain_community.document_loaders import PyMuPDFLoader

docs = [];

for n in Path(".").glob("*.pdf"):
try:
loader = PyMuPDFLoader(str(n))
docs.extend(loader.load())
print(f"carregado arquivo com sucesso: {n.name}")
except Exception as a:
print(f"Erro ao carregar arquivo {n.name}: {a}")
# %%

from langchain_text_splitters import RecursiveCharacterTextSplitter

splitter = RecursiveCharacterTextSplitter(chunk_size=100, chunk_overlap=30)

chunks = splitter.split_documents(docs)

# %%

for chunk in chunks:
print(chunk);
print("--------------------------")
# %%

from langchain_google_genai import GoogleGenerativeAIEmbeddings

embedding = GoogleGenerativeAIEmbeddings(model="models/gemini-embedding-001", google_api_key=google_api_key)

# %%

from langchain_community.vectorstores import FAISS

vectorstoe = FAISS.from_documents(chunks, embedding)

retriever = vectorstoe.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.3, "k": 4})
+
# %%

from langchain_core.prompts import ChatPromptTemplate
from langchain.chains.combine_documents import create_stuff_documents_chain

prompt_rag = ChatPromptTemplate.from_messages([
("system",
"Você é um Assistente de Políticas Internas (RH/IT) da empresa Carraro Desenvolvimento. "
"Responda SOMENTE com base no contexto fornecido. "
"Se não houver base suficiente, responda apenas 'Não sei'."),

("human", "Pergunta: {input}\n\nContexto:\n{context}")
])

document_chain = create_stuff_documents_chain(llm_triagem, prompt_rag)

# %%

def askPolitic_rag(pergunta: str) -> Dict:



Loading