Skip to content

Commit 0f1caad

Browse files
committed
fix: tweak setting locale
1 parent 73917f0 commit 0f1caad

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

e2e/summaries.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import asyncio
22

33
from skynet.logs import get_logger
4-
from .common import get, post
4+
from .common import get, post, skip_smart_tests
55

66
log = get_logger(__name__)
77

88
# courtesy of https://www.gutenberg.org/files/2701/2701-h/2701-h.htm#link2HCH0001
99
moby_dick_text = 'Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.'
1010

1111

12-
async def create_summary():
12+
async def create_summary(locale=None):
1313
summary_job = {'hint': 'text', 'text': moby_dick_text}
14+
if locale:
15+
summary_job['preferred_locale'] = locale
1416

1517
resp = await post('summaries/v1/summary', json=summary_job)
1618
assert resp.status == 200, log.error(f'Unexpected status code: {resp.status}')
@@ -49,6 +51,8 @@ async def get_job_result(job_id):
4951
assert status == 'success', log.error(f'Unexpected status: {status}')
5052
log.info(f'Response: {result.get("result")}')
5153

54+
return result.get("result")
55+
5256

5357
async def run():
5458
log.info('#### Running summaries e2e tests')
@@ -70,3 +74,55 @@ async def run():
7074
job_id = job.get('id')
7175
log.info(f'GET summaries/v1/job/{job_id} - get the result of the process text job')
7276
await get_job_result(job_id)
77+
78+
if skip_smart_tests:
79+
log.info('Skipping locale-specific tests due to skip_smart_tests flag')
80+
return
81+
82+
log.info('POST summaries/v1/summary - create a new summarisation job with Italian locale')
83+
job = await create_summary('it')
84+
job_id = job.get('id')
85+
log.info(f'GET summaries/v1/job/{job_id} - get the result of the Italian summarisation job')
86+
result_it = await get_job_result(job_id)
87+
88+
# Check for Italian words (protagonist = protagonista, navigation = navigazione)
89+
italian_words = ['sentimento', 'quando', 'imbarcarsi', 'narrador']
90+
has_italian = any(word in result_it.lower() for word in italian_words)
91+
assert has_italian, log.error('Italian translation not detected - expected "protagonista" or "navigazione"')
92+
log.info('Italian translation verified')
93+
94+
log.info('POST summaries/v1/summary - create a new summarisation job with Spanish locale')
95+
job = await create_summary('es')
96+
job_id = job.get('id')
97+
log.info(f'GET summaries/v1/job/{job_id} - get the result of the Spanish summarisation job')
98+
result_es = await get_job_result(job_id)
99+
100+
# Check for Spanish words (protagonist = protagonista, navigation = navegación)
101+
spanish_words = ['sentimiento', 'cuando', 'embarcarse', 'narrador']
102+
has_spanish = any(word in result_es.lower() for word in spanish_words)
103+
assert has_spanish, log.error('Spanish translation not detected - expected "protagonista" or "navegación"')
104+
log.info('Spanish translation verified')
105+
106+
log.info('POST summaries/v1/summary - create a new summarisation job with French locale')
107+
job = await create_summary('fr')
108+
job_id = job.get('id')
109+
log.info(f'GET summaries/v1/job/{job_id} - get the result of the French summarisation job')
110+
result_fr = await get_job_result(job_id)
111+
112+
# Check for French words (ocean = océan, character = personnage)
113+
french_words = ['océan', 'quand', 'personnage', 'narrateur']
114+
has_french = any(word in result_fr.lower() for word in french_words)
115+
assert has_french, log.error('French translation not detected - expected "océan" or "personnage"')
116+
log.info('French translation verified')
117+
118+
log.info('POST summaries/v1/summary - create a new summarisation job with German locale')
119+
job = await create_summary('de')
120+
job_id = job.get('id')
121+
log.info(f'GET summaries/v1/job/{job_id} - get the result of the German summarisation job')
122+
result_de = await get_job_result(job_id)
123+
124+
# Check for German words (ocean = ozean, character = charakter)
125+
german_words = ['ozean', 'wenn', 'charakter', 'narrator']
126+
has_german = any(word in result_de.lower() for word in german_words)
127+
assert has_german, log.error('German translation not detected - expected "ozean" or "charakter"')
128+
log.info('German translation verified')

skynet/modules/ttt/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ async def summarize(model: BaseChatModel, payload: DocumentPayload, job_type: Jo
137137

138138
prompt = ChatPromptTemplate(
139139
[
140-
('system', set_response_language(payload.preferred_locale)),
141140
('system', system_message),
141+
('system', set_response_language(payload.preferred_locale)),
142142
('human', '{text}'),
143143
]
144144
)

0 commit comments

Comments
 (0)