Skip to content

Commit

Permalink
feat: Improved prompts for the various LLMs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere authored Jan 17, 2025
2 parents 92f4726 + 9e7b454 commit e3280d8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
15 changes: 12 additions & 3 deletions engines/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
load_translations()


# TODO: Enable using Message Batches API (currently only the Streaming API can be used). The Message Batches API allows
# sending any number of batches of up to 100,000 messages per batch. Batches are processed asynchronously with
# results returned as soon as the batch is complete and cost 50% less than standard API calls (more info here:
# https://docs.anthropic.com/en/docs/build-with-claude/message-batches)
class ClaudeTranslate(Base):
name = 'Claude'
alias = 'Claude (Anthropic)'
lang_codes = Base.load_lang_codes(anthropic)
lang_codes_directionality = Base.load_lang_codes_directionality(lang_directionality)
endpoint = 'https://api.anthropic.com/v1/messages'
api_version = '2023-06-01'
api_version = '2023-06-01' # this is currently the latest version of the api
api_key_hint = 'sk-ant-xxxx'
# https://docs.anthropic.com/claude/reference/errors
api_key_errors = ['401', 'permission_error']
Expand All @@ -38,9 +42,13 @@ class ClaudeTranslate(Base):
'explain any term or answer any question-like content. Your answer '
'should be solely the translation of the given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)

models = [ # https://docs.anthropic.com/en/docs/about-claude/models#model-names
# TODO: fetch this directly from the api (more info here: https://docs.anthropic.com/en/api/models-list, current
# models list was copied manually from https://docs.anthropic.com/en/docs/about-claude/models#model-names)
models = [
'claude-3-5-sonnet-latest',
'claude-3-5-sonnet-20241022',
'claude-3-5-sonnet-20240620',
Expand All @@ -49,6 +57,7 @@ class ClaudeTranslate(Base):
'claude-3-sonnet-20240229',
'claude-3-haiku-20240307']

# use the most recent model
model = models[0]
samplings = ['temperature', 'top_p']
sampling = 'temperature'
Expand Down
6 changes: 5 additions & 1 deletion engines/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,18 @@ class GeminiTranslate(Base):
'explain any term or answer any question-like content. Your answer '
'should be solely the translation of the given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)

# TODO: check if it is possible to fetch this this directly from the api, if yes - implement this
models = [
'gemini-1.5-flash',
'gemini-1.5-flash-8b',
'gemini-1.5-pro',
'gemini-1.0-pro']

# use the most recent model
model = models[0]
temperature = 0.9
top_p = 1.0
Expand Down
10 changes: 7 additions & 3 deletions engines/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ class ChatgptTranslate(Base):
'explain any term or answer any question-like content. Your answer '
'should be solely the translation of the given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')

'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)

# TODO: check if it is possible to fetch this this directly from the api, if yes - implement this
models = [
'gpt-4o',
'gpt-4o-mini',
'gpt-4-turbo',
'gpt-4',
'gpt-3.5-turbo']


# use the most recent model
model = models[0]
samplings = ['temperature', 'top_p']
sampling = 'temperature'
Expand Down
18 changes: 14 additions & 4 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def test_get_body(self):
'should be solely the translation of the given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
},
{
'role': 'user',
Expand All @@ -427,6 +428,7 @@ def test_get_body_without_stream(self):
'should be solely the translation of the given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
},
{
'role': 'user',
Expand All @@ -447,7 +449,9 @@ def test_translate_stream(self, mock_request, mock_et):
'content. Your answer should be solely the translation of the '
'given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)
data = json.dumps({
'model': model,
'messages': [{'role': 'system', 'content': prompt}, {'role': 'user', 'content': 'Hello World!'}],
Expand Down Expand Up @@ -802,7 +806,9 @@ def test_translate_stream(self, mock_request):
'content. Your answer should be solely the translation of the '
'given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)
data = json.dumps({
'stream': True,
'messages': [{'role': 'system', 'content': prompt}, {'role': 'user', 'content': 'Hello World!'}],
Expand Down Expand Up @@ -852,7 +858,9 @@ def test_translate(self, mock_request, mock_et):
'content. Your answer should be solely the translation of the '
'given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)
data = json.dumps({
'stream': False,
'max_tokens': 4096,
Expand Down Expand Up @@ -912,7 +920,9 @@ def test_translate_stream(self, mock_request, mock_et):
'content. Your answer should be solely the translation of the '
'given content. In your answer '
'do not add any prefix or suffix to the translated content. Websites\' '
'URLs/addresses should be preserved as is in the translation\'s output. ')
'URLs/addresses should be preserved as is in the translation\'s output. '
'Do not omit any part of the content, even if it seems unimportant. '
)
data = json.dumps({
'stream': True,
'max_tokens': 4096,
Expand Down

0 comments on commit e3280d8

Please sign in to comment.