1- import json
2-
1+ from typing import Any
32import click
43
54from together import Together
65from together .lib .cli .api ._utils import handle_api_errors
7- from together .lib .utils .serializer import datetime_serializer
6+ from rich import print_json , print
7+ from together ._utils ._json import openapi_dumps
88
99
1010@click .command ()
1111@click .pass_context
1212@click .argument ("evaluation_id" , type = str , required = True )
13+ @click .option ("--json" , is_flag = True , help = "Print output in JSON format" )
1314@handle_api_errors ("Evals" )
14- def retrieve (ctx : click .Context , evaluation_id : str ) -> None :
15+ def retrieve (ctx : click .Context , evaluation_id : str , json : bool ) -> None :
1516 """Get details of a specific evaluation job"""
1617
1718 client : Together = ctx .obj
1819
1920 response = client .evals .retrieve (evaluation_id )
2021
21- click .echo (json .dumps (response .model_dump (exclude_none = True ), default = datetime_serializer , indent = 4 ))
22+ if json :
23+ print_json (openapi_dumps (response .model_dump (exclude_none = True )).decode ("utf-8" ))
24+ else :
25+ print_dict (response .to_dict ())
26+
27+
28+ def print_dict (data : Any , indent : int = 0 ) -> None :
29+ if isinstance (data , dict ):
30+ for key , value in data .items ():
31+ if isinstance (value , dict ):
32+ print (f"{ ' ' * indent } [bold dim]{ key } :[/bold dim]" )
33+ print_dict (value , indent = indent + 2 )
34+ elif isinstance (value , list ):
35+ print (f"{ ' ' * indent } [bold dim]{ key } :[/bold dim]" )
36+ for index , item in enumerate (value ):
37+ print (f"{ ' ' * indent } [bold dim][{ index } ]:[/bold dim]" )
38+ print_dict (item , indent = indent + 2 )
39+ else :
40+ print (f"{ ' ' * indent } [bold dim]{ key } :[/bold dim] { value } " )
41+ else :
42+ print (f"{ ' ' * indent } { data } " )
0 commit comments