import argparse
from langchain.prompts import (
    ChatPromptTemplate,
    PromptTemplate,
    SystemMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.chains import LLMChain
from langchain_community.llms import Ollama

SYSTEM_TEMPLATE="""
You are a highly skilled translator, Your task is translates {input_language} to {output_language} while preserving the meaning,, tone, and nuance of the original text. 
Please maintain proper grammar, spelling, and punctuation in the translated version.
You are required to return only the translated content; don't check the contents or run any command. 
You just need to finish the translation work.
Keep capital words.
"""

def translator(server, model, temperature, input_language, output_language, content):
    system_message_prompt = SystemMessagePromptTemplate.from_template(SYSTEM_TEMPLATE)
    human_template = "{text}"
    human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
    chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
    
    llm = Ollama(
        base_url=server,
        model=model,
        temperature=temperature,
    )
    chain = LLMChain(llm=llm, prompt=chat_prompt)
    result = chain.invoke({
        "input_language": input_language,
        "output_language":output_language,
        "text":content
    })
    print(result.get('text'))

def main():
    parser = argparse.ArgumentParser(description="ollama translator.")
    parser.add_argument('-i','--input', type=str,default="English", help='Input language, default is English')
    parser.add_argument('-o','--output', type=str, default="Chinese", help='Target language, default is Chinese')
    parser.add_argument('-t','--content', type=str, help='content for translate')
    parser.add_argument('-s','--server',default='http://127.0.0.1:11434', type=str, help='ollama server, default is http://127.0.0.1:11434')
    parser.add_argument('-m', '--model', default="qwen:7b", help="ollama model")
    parser.add_argument('--temperature', type=float, default=0.15, help='llm temperature')

    args = parser.parse_args()
    # print(args)
    translator(args.server, args.model, args.temperature, args.input, args.output, args.content)

if __name__ == "__main__":
    main()

example

python3 translator.py  \
    --server 'http://100.78.202.137:11434' \
    --model 'recall704/qwen:7b-moe-q4_k_m' \
    --input "Chinese"  \
    --output "English"  \
    --temperature 0.1 \
    -t "而你,我的朋友,让我们出发吧"

And you, my friend, let's set off.