mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-10-31 16:08:59 +00:00 
			
		
		
		
	Co-authored-by: jacoblee93 <jacoblee93@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
		
			
				
	
	
		
			24 lines
		
	
	
		
			795 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			795 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| ```python
 | |
| from langchain import LLMChain
 | |
| from langchain.chat_models import ChatOpenAI
 | |
| from langchain.prompts.chat import (
 | |
|     ChatPromptTemplate,
 | |
|     SystemMessagePromptTemplate,
 | |
|     HumanMessagePromptTemplate,
 | |
| )
 | |
| 
 | |
| chat = ChatOpenAI(temperature=0)
 | |
| 
 | |
| template = "You are a helpful assistant that translates {input_language} to {output_language}."
 | |
| system_message_prompt = SystemMessagePromptTemplate.from_template(template)
 | |
| human_template = "{text}"
 | |
| human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
 | |
| chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
 | |
| 
 | |
| chain = LLMChain(llm=chat, prompt=chat_prompt)
 | |
| chain.run(input_language="English", output_language="French", text="I love programming.")
 | |
| ```
 | |
| ```pycon
 | |
| J'aime programmer.
 | |
| ```
 |