06 Transforming
大语言模型(LLM)很擅于将输入转换为不同格式的输出,比如翻译、拼写校正或HTML格式转化。相比于复杂的正则表达式,Chat GPT实现更加准确和高效。
1) 不同语种的转换
下述语句实现了英文到西班牙语的翻译。
prompt = f"""
Translate the following English text to Spanish: \
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)
同样我们也可以实现其它语言之间的相互翻译,甚至通过修改prompt为prompt = f""" Translate the following text to French and Spanish and English pirate:
将单句同时翻译为多个语言。另一方面,我们也可以输入Tell me which language this is: ```Combien coûte le lampadaire?
让模型判断输入的是什么语言。
我们也可以增加一些具体的指示让模型生成不同风格的语言。比如输入
prompt = f"""
Translate the following text to Chineses in both the \
formal and informal forms:
'Would you like to diner with me?'
"""