| import json |
|
|
| from agent import BookstoreAgent |
| from data.seed_database import seed_books |
|
|
|
|
| def print_tool_logs( |
| tool_logs: list[dict], |
| ) -> None: |
| """Tool çağrılarını terminalde okunabilir biçimde gösterir.""" |
|
|
| if not tool_logs: |
| print("\n[Bu cevapta tool çağrısı yapılmadı.]") |
| return |
|
|
| print("\n" + "-" * 80) |
| print("TOOL-CALL ÖZETİ") |
| print("-" * 80) |
|
|
| for index, log in enumerate(tool_logs, start=1): |
| print(f"\n{index}. Tool: {log['tool_name']}") |
|
|
| print( |
| " Arguments:", |
| json.dumps( |
| log["arguments"], |
| ensure_ascii=False, |
| ), |
| ) |
|
|
| print( |
| " Result:", |
| json.dumps( |
| log["result"], |
| ensure_ascii=False, |
| ), |
| ) |
|
|
|
|
| def main() -> None: |
| |
| seed_books() |
|
|
| print("\nAkıllı Kitapçı Asistanı başlatılıyor...") |
|
|
| agent = BookstoreAgent() |
|
|
| history: list[dict[str, str]] = [] |
|
|
| print("\n" + "=" * 80) |
| print("AKILLI KİTAPÇI ASİSTANI") |
| print("=" * 80) |
| print("Çıkmak için: çık, exit veya quit") |
| print("=" * 80) |
|
|
| while True: |
| user_message = input("\nSen: ").strip() |
|
|
| if user_message.casefold() in { |
| "çık", |
| "exit", |
| "quit", |
| }: |
| print("\nAsistan kapatıldı.") |
| break |
|
|
| if not user_message: |
| continue |
|
|
| try: |
| result = agent.run( |
| user_message=user_message, |
| history=history, |
| ) |
| except Exception as error: |
| print("\nBir API veya bağlantı hatası oluştu:") |
| print(f"{type(error).__name__}: {error}") |
| continue |
|
|
| print_tool_logs(result["tool_logs"]) |
|
|
| print("\nAsistan:") |
| print(result["answer"]) |
|
|
| history.extend( |
| [ |
| { |
| "role": "user", |
| "content": user_message, |
| }, |
| { |
| "role": "assistant", |
| "content": result["answer"], |
| }, |
| ] |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| main() |