Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uogbuji committed Jun 24, 2024
1 parent b2ea02a commit 7500e2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 2 additions & 4 deletions pylib/llm_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import concurrent.futures
from functools import partial
from typing import List
import warnings

from amara3 import iri

Expand Down Expand Up @@ -72,13 +71,12 @@ def from_openai_chat(response):
c['message'] = llm_response(c['message'])
rc1 = resp['choices'][0]
# No response message content if a tool call is invoked
if 'tool_calls' in rc1['message']:
# Why the hell does OpenAI have these arguments properties as plain text? Seems like a massive layering violation
if rc1.get('message', {}).get('tool_calls'):
# WTH does OpenAI have these arguments properties as plain text? Seems a massive layering violation
for tc in rc1['message']['tool_calls']:
tc['function']['arguments_obj'] = json.loads(tc['function']['arguments'])
else:
resp['first_choice_text'] = rc1['text'] if 'text' in rc1 else rc1['message']['content']
print('GRIPPO', f'from_openai_chat: {rc1 =}')
else:
resp['first_choice_text'] = resp['content']
return resp
Expand Down
6 changes: 3 additions & 3 deletions test/test_ogbujipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

# import pytest

from ogbujipt.llm_wrapper import openai_chat_api
from ogbujipt.llm_wrapper import llm_response #, openai_chat_api

def test_oapi_first_choice_text(OPENAI_TEXT_RESPONSE_OBJECT):
text1 = openai_chat_api.first_choice_text(OPENAI_TEXT_RESPONSE_OBJECT)
text1 = llm_response.from_openai_chat(OPENAI_TEXT_RESPONSE_OBJECT).first_choice_text
assert text1 == '…is an exceptional employee who has made significant contributions to our company.'

def test_oapi_first_choice_message(OPENAI_MSG_RESPONSE_OBJECT):
msg1 = openai_chat_api.first_choice_message(OPENAI_MSG_RESPONSE_OBJECT)
msg1 = llm_response.from_openai_chat(OPENAI_MSG_RESPONSE_OBJECT).first_choice_text
assert msg1 == '…is an exceptional employee who has made significant contributions to our company.'


Expand Down
24 changes: 17 additions & 7 deletions test/test_word_loom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import os
import sys
# import pkgutil
from itertools import chain

import pytest

Expand Down Expand Up @@ -49,19 +49,29 @@ def test_load_fp_vs_str(SAMPLE_TOML_STR, SAMPLE_TOML_FP):
def test_sample_texts_check(SAMPLE_TOML_STR):
# print(SAMPLE_TOML)
loom = word_loom.load(SAMPLE_TOML_STR)
assert list(sorted(loom.keys())) == ['davinci3_instruct_system', 'hello_translated', 'i18n_context', 'write_i18n_advocacy']
assert list(sorted([v[:20] for v in loom.values()])) == ['Hello', 'Internationalization', 'Obey the instruction', '{davinci3_instruct_s']
assert [v.markers or [] for v in loom.values()] == [[], [], ['davinci3_instruct_system', 'i18n_context'], []]
# default language text is also a key
assert len(loom.keys()) == 8
for k in ['davinci3_instruct_system', 'hello_translated', 'i18n_context', 'write_i18n_advocacy']:
assert k in loom.keys()
assert 'Hello' in loom.keys()

# loom_dlt = set([v[:20] for v in loom.values()])

assert len(set(loom.values())) == 4
for k in ['Hello', 'Internationalization', 'Obey the instruction', '{davinci3_instruct_s']:
assert k in [v[:20] for v in loom.values()]

assert [v.markers or [] for v in loom.values()] == [[], [], [], [], ['davinci3_instruct_system', 'i18n_context'], ['davinci3_instruct_system', 'i18n_context'], [], []]
assert loom['davinci3_instruct_system'].lang == 'en'

# Default language is English
loom1 = word_loom.load(SAMPLE_TOML_STR, lang='en')
assert loom1 == loom

loom = word_loom.load(SAMPLE_TOML_STR, lang='fr')
assert list(sorted(loom.keys())) == ['goodbye_translated', 'hardcoded_food', 'translate_request']
assert list(sorted([v[:20] for v in loom.values()])) == ['Adieu', 'Comment dit-on en an', 'pomme de terre']
assert [v.markers or [] for v in loom.values()] == [['hardcoded_food'], [], []]
assert list(sorted(loom.keys())) == ['Adieu', 'Comment dit-on en anglais: {hardcoded_food}?', 'goodbye_translated', 'hardcoded_food', 'pomme de terre', 'translate_request']
assert list(sorted(set([v[:20] for v in loom.values()]))) == ['Adieu', 'Comment dit-on en an', 'pomme de terre']
assert [v.markers or [] for v in loom.values()] == [['hardcoded_food'], ['hardcoded_food'], [], [], [], []]
assert loom['hardcoded_food'].lang == 'fr'


Expand Down

0 comments on commit 7500e2e

Please sign in to comment.