Cortex-ai / examples /cortex_chat.py
asdfasdfqrqwer's picture
feat(cortex-ai): agent engine, tool registry, OpenAI-compatible API, fine-tuning pipeline
c63bc31
Raw History Blame Contribute Delete
1.45 kB
#!/usr/bin/env python3
"""Exemple : appeler CORTEX AI en local, sans serveur HTTP.
PYTHONPATH=/workspace/project:/workspace/project/encoding \
python3 examples/cortex_chat.py "Combien font 12 * 8 ?"
Utilise l'adaptateur simule : aucune carte graphique, aucun telechargement.
Pour utiliser le vrai modele, remplacez MockAdapter par HFAdapter et chargez-le.
"""
from __future__ import annotations
import sys
from cortex_ai.adapters import MockAdapter
from cortex_ai.config import CortexConfig, EngineConfig
from cortex_ai.engine import CortexAgent
from cortex_ai.tools import default_registry
def main(question: str) -> int:
config = CortexConfig()
agent = CortexAgent(
MockAdapter(),
default_registry(),
EngineConfig(thinking_mode="thinking", reasoning_effort="high"),
system_prompt=config.system_prompt,
)
turn = agent.run([{"role": "user", "content": question}])
print(f"Question : {question}")
print(f"Tours : {turn.rounds}")
if turn.reasoning:
print(f"Raisonnement : {turn.reasoning}")
for call in turn.tool_calls:
statut = "ok" if call.ok else "echec"
print(f"Outil : {call.name}({call.arguments}) -> {call.result} [{statut}]")
print(f"Reponse : {turn.content}")
return 0
if __name__ == "__main__":
question = " ".join(sys.argv[1:]) or "Combien font 12 * 8 ?"
raise SystemExit(main(question))