File size: 1,480 Bytes
8ceabd3
4624775
 
 
 
 
 
 
f92e1ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ceabd3
 
 
 
 
 
 
 
 
 
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
from inference import _format_action, _looks_like_placeholder_api_key, _tool_result_message


def test_placeholder_api_key_detection():
    assert _looks_like_placeholder_api_key("your_openai_api_key") is True
    assert _looks_like_placeholder_api_key("sk-your-real-openai-key") is True
    assert _looks_like_placeholder_api_key("replace-me") is True
    assert _looks_like_placeholder_api_key("sk-proj-realistic-looking-token") is False


def test_tool_result_message_reuses_assistant_tool_call_id():
    assistant_message = {
        "role": "assistant",
        "content": "",
        "tool_calls": [
            {
                "id": "call_123",
                "type": "function",
                "function": {"name": "get_post", "arguments": "{\"post_id\":\"post_midnight_manifest\"}"},
            }
        ],
    }
    result = {"reward": 0.1, "done": False}
    tool_message = _tool_result_message(assistant_message, result)
    assert tool_message is not None
    assert tool_message["tool_call_id"] == "call_123"
    assert tool_message["role"] == "tool"


def test_action_formatter_matches_single_line_style():
    assert _format_action({"action_type": "ANSWER", "payload": {"answer": "user_bharat"}}) == "answer(user_bharat)"
    assert _format_action(
        {
            "action_type": "CALL_TOOL",
            "payload": {"tool_name": "get_post", "args": {"post_id": "post_midnight_manifest"}},
        }
    ) == "get_post(post_id=post_midnight_manifest)"