Skip to content

Commit

Permalink
Improve context reviewer prompter using CO-STAR. (#41)
Browse files Browse the repository at this point in the history
* Improve context reviewer prompt by CO-STAR.
* Minor refactor for check_format.
  • Loading branch information
zh-plus authored Jun 5, 2024
1 parent 1868c6c commit a8450ec
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 99 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ and [Anthropic](https://docs.anthropic.com/claude/docs/models-overview#model-com
| `gpt-3.5-turbo` | 0.5, 1.5 | 0.01 |
| `gpt-4-0125-preview` | 10, 30 | 0.5 |
| `gpt-4-turbo-preview` | 10, 30 | 0.5 |
| `gpt-4o` | 5, 15 | 0.25 |
| `claude-3-haiku-20240307` | 0.25, 1.25 | 0.015 |
| `claude-3-sonnet-20240229` | 3, 15 | 0.2 |
| `claude-3-opus-20240229` | 15, 75 | 1 |
Expand Down
9 changes: 5 additions & 4 deletions openlrc/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from openlrc.chatbot import route_chatbot
from openlrc.context import TranslationContext, TranslateInfo
from openlrc.logger import logger
from openlrc.prompter import BaseTranslatePrompter, ContextReviewPrompter, potential_prefix_combo, \
ProofreaderPrompter, proofread_prefix
from openlrc.prompter import BaseTranslatePrompter, ContextReviewPrompter, POTENTIAL_PREFIX_COMBOS, \
ProofreaderPrompter, PROOFREAD_PREFIX


class Agent(abc.ABC):
Expand Down Expand Up @@ -70,7 +70,7 @@ def _extract_tag_content(self, content: str, tag: str) -> str:
return match.group(1) if match else ''

def _extract_translations(self, content: str) -> List[str]:
for _, trans_prefix in potential_prefix_combo:
for _, trans_prefix in POTENTIAL_PREFIX_COMBOS:
translations = re.findall(f'{trans_prefix}\n*(.*?)(?:#\d+|<summary>|\n*$)', content, re.DOTALL)
if translations:
return self._clean_translations(translations, content)
Expand Down Expand Up @@ -102,6 +102,7 @@ def translate_chunk(self, chunk_id: int, chunk: List[Tuple[int, str]],
class ContextReviewerAgent(Agent):
"""
Review the context of the subtitles to ensure accuracy and completeness.
TODO: Add chunking support.
"""

TEMPERATURE = 0.8
Expand Down Expand Up @@ -149,7 +150,7 @@ def __init__(self, src_lang, target_lang, info: TranslateInfo = TranslateInfo(),

def _parse_responses(self, resp) -> List[str]:
content = self.chatbot.get_content(resp)
revised = re.findall(proofread_prefix + r'\s*(.*)', content, re.MULTILINE)
revised = re.findall(PROOFREAD_PREFIX + r'\s*(.*)', content, re.MULTILINE)

return revised

Expand Down
4 changes: 2 additions & 2 deletions openlrc/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ async def _create_achat(self, messages: List[Dict], output_checker: Callable = l
except openai.APIConnectionError:
logger.warning(f'API connection error. Wait 15s before retry. Retry num: {i + 1}.')
time.sleep(15)
except openai.APIError:
logger.warning(f'API error. Wait 15s before retry. Retry num: {i + 1}.')
except openai.APIError as e:
logger.warning(f'API error: {e}. Wait 15s before retry. Retry num: {i + 1}.')
time.sleep(15)

if not response:
Expand Down
Loading

0 comments on commit a8450ec

Please sign in to comment.