Using this code:"""import openai
from openai import AzureOpenAI
import wikipediaapi
import networkx as nx
import matplotlib.pyplot as plt
import json
import time
from igraph import Graph, plot

# Configuración
AZURE_API_KEY = ...
AZURE_ENDPOINT = ...
AZURE_API_VERSION =...
AZURE_DEPLOYMENT_NAME =...

WIKI_LANGUAGE = 'es'
DOMAIN = 'Paramilitarismo en Colombia'  # Ejemplo de dominio
MAX_ARTICLES = 10  # Número de artículos de Wikipedia a procesar
REQUESTS_DELAY = 1  # Retardo entre solicitudes para respetar los límites de tasa

# Define the user agent
USER_AGENT = "KnowledgeGraphBot/1.0 (contact@example.com)"  # Replace with your details


# Configuración de OpenAI para Azure
openai.api_type = "azure"
openai.api_base = AZURE_ENDPOINT
openai.api_version = AZURE_API_VERSION
openai.api_key = AZURE_API_KEY

def fetch_wikipedia_articles(domain, max_articles=10, language='en'):
    wiki_wiki = wikipediaapi.Wikipedia(
        language=language,
        extract_format=wikipediaapi.ExtractFormat.WIKI,
        user_agent=USER_AGENT  # Añadido user_agent
    )
    category = wiki_wiki.page(f'Category:{domain}')
    articles = []

    def recursive_category_members(category, articles, max_articles, level=0):
        print(f"Traversing category: {category.title} at level {level}")
        for c in category.categorymembers.values():
            if c.ns == wikipediaapi.Namespace.MAIN and len(articles) < max_articles:
                articles.append(c.title)
                print(f"Found article: {c.title}")
            elif c.ns == wikipediaapi.Namespace.CATEGORY and len(articles) < max_articles:
                recursive_category_members(c, articles, max_articles, level + 1)

    if not category.exists():
        print(f"La categoría '{domain}' no existe en Wikipedia.")
        return articles

    recursive_category_members(category, articles, max_articles)
    return articles[:max_articles]

def get_article_content(title, language='en'):
    wiki_wiki = wikipediaapi.Wikipedia(
        language=language,
        extract_format=wikipediaapi.ExtractFormat.WIKI,
        user_agent=USER_AGENT  # Añadido user_agent
    )
    page = wiki_wiki.page(title)
    if page.exists():
        return page.text
    else:
        return ""

def extract_entities_and_relationships(text):
    prompt = f"""
    Extract entities and their relationships from the following text. 
    Provide the output in JSON format with two keys: "entities" and "relationships".
    "entities" should be a list of unique entity names.
    "relationships" should be a list of objects with "source", "relation", and "target".

    Text:
    {text}
    """

    try:
        client = AzureOpenAI(api_key=AZURE_API_KEY,
                             api_version=AZURE_API_VERSION,
                             azure_endpoint=AZURE_ENDPOINT,
                             azure_deployment=AZURE_DEPLOYMENT_NAME)
        
        response = client.chat.completions.create(
            model='gpt-4o-mini',  # Reemplaza deployment_id por el nombre de tu despliegue
            messages=[
                {"role": "system", "content": "You are an assistant that extracts entities and their relationships from text."},
                {"role": "user", "content": prompt}
            ],
            
            temperature=0.3,
        )

        return json.loads(response.to_json())['choices'][0]['message']['content']
    except Exception as e:
        print(f"Error durante la llamada a la API de Azure OpenAI: {e}")
        return None

def build_knowledge_graph(articles, language='en'):
    G = nx.DiGraph()  # Cambiado a Grafo Dirigido

    for title in articles:
        print(f"Processing article: {title}")
        text = get_article_content(title, language)
        if not text:
            print(f"No se encontró contenido para {title}. Se omite.")
            continue

        extracted = extract_entities_and_relationships(text)
        if not extracted:
            print(f"No se pudo extraer datos de {title}. Se omite.")
            continue

        try:
            data = json.loads(extracted[8:-3])
            entities = data.get('entities', [])
            relationships = data.get('relationships', [])

            # Añadir entidades como nodos
            for entity in entities:
                G.add_node(entity)

            # Añadir relaciones como aristas
            for rel in relationships:
                source = rel.get('source')
                target = rel.get('target')
                relation = rel.get('relation', 'related_to')
                if source and target:
                    G.add_edge(source, target, relation=relation)
        except json.JSONDecodeError as e:
            print(f"Error al decodificar JSON para el artículo {title}: {e}")
            continue

        time.sleep(REQUESTS_DELAY)  # Respetar los límites de tasa de la API

    return G""" Modify to create a system of LLM agents that generate a ONTOLOGY grpah of knowledge, so you have to define what information in each wikipedia page showld be interpretated as an ontology  knowledge, aditional, you have to define a strategy to match the node entities mapped to not make duplications of entities.  An when you have the graph, export it as a json