File size: 2,109 Bytes
5196bf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import os

# Add backend to path
sys.path.append(os.path.join(os.getcwd(), "backend"))

from app.services import llm
from config import settings

def list_registered_tools():
    # Bypass registry import for isolated LLM test
    print("\n--- Registered Tools (Registry bypass for LLM test) ---")
    print(" [Skipping registry load to avoid dependency errors]")
    print("\n--- Testing JARVIS Multi-Step Reasoning ---")
    
    # Initialize LLM (Mock/Real)
    # Note: This requires .env to be set up correctly for OpenAI or Ollama to be running.
    # We will just verify if the loop runs without crashing and logs steps.
    
    messages = [
        {"role": "user", "content": "Jarvis, what's the current time and what application am I using right now?"}
    ]
    
    print("User: " + messages[0]["content"])
    try:
        response = llm.chat(messages, use_tools=True)
        print("\nJARVIS: " + response)
    except Exception as e:
        print(f"Error during agent test: {e}")

def list_registered_tools():
    print("\n--- Registered Tools ---")
    tools = registry.get_all_tools_schema()
    for t in tools:
        print(f" - {t['function']['name']}: {t['function'].get('description')}")

def test_groq_connection():
    print("\n--- Testing Groq (Free Cloud) connection ---")
    try:
        from app.services import llm
        from app.config import settings
        
        # Re-init with new settings
        llm.init(
            openai_api_key=settings.openai_api_key,
            openai_model=settings.openai_model,
            openai_base_url=settings.openai_base_url,
            use_cloud=True
        )
        
        messages = [{"role": "user", "content": "Say 'Groq is active' if you can hear me."}]
        print(f"Base URL: {settings.openai_base_url}")
        print(f"Model: {settings.openai_model}")
        
        response = llm.chat(messages, use_tools=False)
        print(f"Response: {response}")
    except Exception as e:
        print(f"Connection failed: {e}")

if __name__ == "__main__":
    list_registered_tools()
    test_groq_connection()