Skip to content

Commit 048bfab

Browse files
authored
Updated UX for errors
1 parent bb0c619 commit 048bfab

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/together/commands/inference.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import base64
55
import json
66
import re
7+
import sys
78
from typing import List
89

910
from 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

Comments
 (0)