File size: 854 Bytes
c6ce43e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

import pytest

from agents import CBTAgent

requires_hf_token = pytest.mark.skipif(
    not (os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")),
    reason="HF Inference token not configured",
)


@requires_hf_token
def test_agent_analyze_thought_with_hf():
    agent = CBTAgent()
    analysis = agent.analyze_thought("I will fail the interview")
    assert isinstance(analysis, dict)
    codes = [c for c, _ in analysis.get("distortions", [])]
    assert "FT" in codes
    assert isinstance(analysis.get("reframe", ""), str) and analysis["reframe"]
    assert isinstance(analysis.get("similar_situations", []), list)


@requires_hf_token
def test_agent_generate_response_hf():
    agent = CBTAgent()
    resp = agent.generate_response("I will definitely mess up the interview")
    assert isinstance(resp, str) and len(resp) > 0