Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid displaying KeyboardInterrupt exception on terminal if user arbitrarily interrupts the inference #10

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions minigpt4/minigpt4_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,12 @@ def generate(self, message: str, limit: int = 1024, temp: float = 0.8, top_k: in
self.library.minigpt4_begin_chat(self.ctx, message, self.n_threads)
chat = ''
for _ in range(limit):
token = self.library.minigpt4_end_chat(self.ctx, self.n_threads, temp, top_k, top_p, tfs_z, typical_p, repeat_last_n, repeat_penalty, alpha_presence, alpha_frequency, mirostat, mirostat_tau, mirostat_eta, penalize_nl)
try:
token = self.library.minigpt4_end_chat(self.ctx, self.n_threads, temp, top_k, top_p, tfs_z, typical_p, repeat_last_n, repeat_penalty, alpha_presence, alpha_frequency, mirostat, mirostat_tau, mirostat_eta, penalize_nl)
except KeyboardInterrupt:
break
except Exception as exception:
raise exception
chat += token
if self.library.minigpt4_contains_eos_token(token):
continue
Expand Down Expand Up @@ -762,7 +767,12 @@ def upload_image(self, image):
library.minigpt4_begin_chat(ctx, prompt, n_threads)
chat = ''
while True:
token = library.minigpt4_end_chat(ctx, n_threads)
try:
token = library.minigpt4_end_chat(ctx, n_threads)
except KeyboardInterrupt:
break
except Exception as exception:
raise exception
chat += token
if library.minigpt4_contains_eos_token(token):
continue
Expand Down