Skip to content

Commit

Permalink
handle error message
Browse files Browse the repository at this point in the history
  • Loading branch information
neph1 committed Jan 10, 2024
1 parent 8b43163 commit 26317f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tale/llm/LivingNpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def tell_action_deferred(self):
actions = '\n'.join(self.deferred_actions)
deferred_action = ParseResult(verb='idle-action', unparsed=actions, who_info=None)
self.tell_others(actions + '\n')
#self.location._notify_action_all(deferred_action, actor=self)
self.location._notify_action_all(deferred_action, actor=self)
self.deferred_actions.clear()

def _clear_quest(self):
Expand Down
9 changes: 3 additions & 6 deletions tale/llm/llm_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ def synchronous_request(self, request_body: dict, prompt: str, context: str = ''
request_body = self.io_adapter._set_prompt(request_body, prompt, context)
print(request_body)
response = requests.post(self.url + self.endpoint, headers=self.headers, data=json.dumps(request_body))
try:
parsed_response = self.io_adapter._parse_result(response.text)
except LlmResponseException as exc:
print("Error parsing response from backend - ", exc)
return ''
return parsed_response
if response.status_code == 200:
return self.io_adapter._parse_result(response.text)
return ''

def asynchronous_request(self, request_body: dict, prompt: str, context: str = '') -> str:
if self.backend != 'kobold_cpp':
Expand Down
11 changes: 11 additions & 0 deletions tests/test_llm_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ def test_set_prompt_llama_cpp(self):
assert(config_file['USER_START'] in result['messages'][1]['content'])
assert(config_file['USER_END'] in result['messages'][1]['content'])

@responses.activate
def test_error_response(self):
config_file = self._load_config()
backend_config = self._load_backend_config('kobold_cpp')
responses.add(responses.POST, backend_config['URL'] + backend_config['ENDPOINT'],
json={'results':['']}, status=500)
io_util = IoUtil(config=config_file, backend_config=backend_config)

response = io_util.synchronous_request(request_body=json.loads(backend_config['DEFAULT_BODY']), prompt='test evoke', context='')
assert(response == '')

@responses.activate
def test_stream_kobold_cpp(self):
config = {'BACKEND':'kobold_cpp', 'USER_START':'', 'USER_END':''}
Expand Down

0 comments on commit 26317f8

Please sign in to comment.