Created
May 22, 2025 19:16
-
-
Save ludndev/b483bf2167941603f34786e71d0fb4aa to your computer and use it in GitHub Desktop.
need to improve this as it's used in an automatic file translator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the API endpoint for Ollama | |
api_url = f"{OLLAMA_API_URL}/v1/chat/completions" | |
# Construct the prompt with system and user messages | |
payload = { | |
"model": model_name, | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "You are a translation engine. Respond ONLY with the direct translation of the input text. No quotes, no explanations, no additional text, no formatting, no line breaks. Return just the translated text string. Ensure the translation is accurate and matches the original text. Maintain the original formatting and structure of the input text. Handle unexpected API responses gracefully, returning only the desired translation." | |
}, | |
{ | |
"role": "user", | |
"content": f"Translate this text to {target_language}:\n{text}" | |
} | |
], | |
"stream": False | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment