Spaces:
Sleeping
Sleeping
File size: 1,860 Bytes
cce8120 | 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 64 65 66 67 68 69 70 71 72 73 74 | #!/usr/bin/env python3
import json
import sys
RAW_RESPONSE = {
"id": "Root=test-contract",
"object": "chat.completion",
"model": "accounts/fireworks/models/deepseek-v4-flash-0731",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "APPLICATION PROVIDER OK",
"reasoning_content": (
'We need to respond with exactly '
'"APPLICATION PROVIDER OK". No other text.'
),
"tools": None,
},
"finish_reason": "stop",
}
],
}
def extract_assistant_content(payload: dict) -> str:
choices = payload.get("choices")
if not isinstance(choices, list) or not choices:
raise ValueError("Provider returned no choices")
choice = choices[0]
if not isinstance(choice, dict):
raise ValueError("Invalid provider choice")
message = choice.get("message")
if not isinstance(message, dict):
raise ValueError("Provider response has no message object")
content = message.get("content")
if not isinstance(content, str):
raise ValueError("Provider message.content is not a string")
content = content.strip()
if not content:
raise ValueError("Provider message.content is empty")
return content
def main() -> int:
content = extract_assistant_content(RAW_RESPONSE)
assert content == "APPLICATION PROVIDER OK"
assert content != RAW_RESPONSE["choices"][0]["message"]["reasoning_content"]
print("[PASS] message.content extraction")
print("[PASS] reasoning_content isolation")
print("[PASS] non-empty assistant content")
print(json.dumps({"assistant_content": content}, indent=2))
return 0
if __name__ == "__main__":
sys.exit(main())
|