Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
fix str format error
Browse files Browse the repository at this point in the history
  • Loading branch information
versun authored Apr 25, 2024
1 parent 8050c25 commit 6647a64
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion django_text_translator/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ def translate(self, text:str, target_language:str, system_prompt:str=None, user_
translated_text = ''
system_prompt = system_prompt or self.translate_prompt
try:
system_prompt = system_prompt.replace('{target_language}', target_language)
if user_prompt:
system_prompt += f"\n\n{user_prompt}"

res = client.with_options(max_retries=3).chat.completions.create(
model=self.model,
messages = [
{"role": "system", "content": f'{system_prompt}'},
{"role": "system", "content": system_prompt},
{"role": "user", "content": text}
],
temperature=self.temperature,
Expand Down
2 changes: 1 addition & 1 deletion django_text_translator/models/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def translate(self, text:str, target_language:str, system_prompt:str=None, user_
translated_text = ''
system_prompt = system_prompt or self.translate_prompt
try:
system_prompt = system_prompt.format(target_language=target_language)
system_prompt = system_prompt.replace('{target_language}', target_language)
if user_prompt is not None:
system_prompt += f"\n\n{user_prompt}"

Expand Down
2 changes: 1 addition & 1 deletion django_text_translator/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def translate(self, text:str, target_language:str, system_prompt:str=None, user_
tokens = 0
translated_text = ''
system_prompt = system_prompt or self.translate_prompt
prompt = f"{system_prompt.format(target_language=target_language)}\n{user_prompt}\n{text}"
prompt = f"{system_prompt.replace('{target_language}', target_language)}\n{user_prompt}\n{text}"
try:
model = self._init()
generation_config = genai.types.GenerationConfig(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages = ["./"]

[project]
name = "django-text-translator"
version = "2024.4.25.1"
version = "2024.4.25.2"
authors = [
{ name="Versun", email="django-text-translator@versun.me" },
]
Expand Down

0 comments on commit 6647a64

Please sign in to comment.