44import base64
55import json
66import re
7+ import sys
78from typing import List
89
910from together .inference import Inference
@@ -168,9 +169,10 @@ def _run_complete(args: argparse.Namespace) -> None:
168169
169170 if args .raw :
170171 print (json .dumps (response , indent = 4 ))
171- else :
172+ sys .exit ()
173+
174+ if "output" in response .keys ():
172175 if args .task == "text2text" :
173- # TODO Add exception when generated_text has error, See together docs
174176 try :
175177 text = str (response ["output" ]["choices" ][0 ]["text" ])
176178 except Exception :
@@ -181,9 +183,8 @@ def _run_complete(args: argparse.Namespace) -> None:
181183 logger .critical (f"Error raised: { e } " )
182184 exit_1 (logger )
183185
184- if args .stop is not None :
185- # TODO remove this and permanently implement api stop_word
186- text = _enforce_stop_tokens (text , args .stop )
186+ # if args.stop is not None:
187+ # text = _enforce_stop_tokens(text, args.stop)
187188
188189 elif args .task == "text2img" :
189190 try :
@@ -203,4 +204,17 @@ def _run_complete(args: argparse.Namespace) -> None:
203204 )
204205 exit_1 (logger )
205206
206- print (text .strip ())
207+ elif "error" in response .keys ():
208+ if response ["error" ] == "Returned error: no instance" :
209+ logger .critical (
210+ f"No running instances for { args .model } . You can start an instance by navigating to the Together Playground at api.together.xyz"
211+ )
212+ exit_1 (logger )
213+ else :
214+ logger .critical (f"Error raised: { response ['error' ]} " )
215+
216+ else :
217+ logger .critical ("Unknown response received" )
218+ exit_1 (logger )
219+
220+ print (text .strip ())
0 commit comments