Skip to content

Commit

Permalink
Improve context validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-plus committed Jul 2, 2024
1 parent d9dde29 commit 7bda26e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions openlrc/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def __str__(self):
return f'Context Reviewer Agent ({self.chatbot_model})'

def _validate_context(self, context: str) -> bool:
# Use the content to check first
lowered_context = context.lower()
keywords = ['glossary', 'characters', 'summary', 'tone and style', 'target audience']
if all(keyword in lowered_context for keyword in keywords):
return True

messages_list = [
{'role': 'system', 'content': self.validate_prompter.system()},
{'role': 'user', 'content': self.validate_prompter.user(context)},
Expand Down
8 changes: 7 additions & 1 deletion tests/test_prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from openlrc.context import TranslateInfo
from openlrc.prompter import ChunkedTranslatePrompter
from openlrc.prompter import ChunkedTranslatePrompter, Prompter

formatted_user_input = '''Translation guidelines from context reviewer:
This is a guidline.
Expand Down Expand Up @@ -84,3 +84,9 @@ def test_check_format(self):
<scene>Scene</scene>
'''
self.assertTrue(self.prompter.check_format(formatted_user_input, content))

def test_default_check_format(self):
class TMPPrompter(Prompter):
pass

self.assertTrue(TMPPrompter().check_format('content', 'content'))

0 comments on commit 7bda26e

Please sign in to comment.