fix redis host 更换
This commit is contained in:
zhouchengrong
2024-06-28 13:59:53 +08:00
parent a18d423d06
commit d772adcd7a

View File

@@ -1,9 +1,8 @@
import os import logging
from langchain.chains import LLMChain from langchain.chains import LLMChain
from langchain.chat_models import ChatOpenAI from langchain.chat_models import ChatOpenAI
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate, \ from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
PromptTemplate
from app.core.config import OPENAI_MODEL, OPENAI_API_KEY from app.core.config import OPENAI_MODEL, OPENAI_API_KEY
@@ -21,7 +20,8 @@ def translate_to_en(text):
"""You are a translation expert, proficient in various languages. """You are a translation expert, proficient in various languages.
And can translate various languages into English. And can translate various languages into English.
Please translate to grammatically correct English regardless of the input language. Please translate to grammatically correct English regardless of the input language.
If the input is in English or numbers, check for grammatical errors. If there are no errors, output the input directly. If the input is already in English, or consists of letters or numbers such as "cat", "abc", or "1",
output the input text exactly as it is without any modifications or additions.
If there are grammatical errors, correct them and then output the sentence.""" If there are grammatical errors, correct them and then output the sentence."""
) )
system_message_prompt = SystemMessagePromptTemplate.from_template(template) system_message_prompt = SystemMessagePromptTemplate.from_template(template)
@@ -36,34 +36,41 @@ def translate_to_en(text):
) )
translate_chain = LLMChain(llm=llm, prompt=chat_prompt_template) translate_chain = LLMChain(llm=llm, prompt=chat_prompt_template)
template = ( result = translate_chain.invoke(text)
"""
Input sentence:
{translate}
1. Based on the input,adjust the input sentence to make it more suitable for prompts for generating images,
ensuring all key nouns or adjectives related to the image are retained.
2. Simplify complex sentence structures and clarify ambiguous expressions.
3. Only Output the adjusted English sentence.
Output : logging.info("translate result : " + result.get('text'))
""" # print("translate result : " + result.get('text'))
) return result.get('text')
# "Based on the input sentence, extract key adjectives and nouns.Only Output extracted key words."
# 1. Check if the input sentence contains any grammatical errors. If there are errors, please correct them before proceeding.
prompt_template = PromptTemplate(input_variables=["translate"], template=template) # template = (
prompt_chain = LLMChain(llm=llm, prompt=prompt_template) # """
# Input sentence:
from langchain.chains import SimpleSequentialChain # {translate}
overall_chain = SimpleSequentialChain(chains=[translate_chain, prompt_chain], verbose=True) # 1. Based on the input,adjust the input sentence to make it more suitable for prompts for generating images,
# ensuring all key nouns or adjectives related to the image are retained.
response = overall_chain.run(text) # 2. Simplify complex sentence structures and clarify ambiguous expressions.
return response # 3. Only Output the adjusted English sentence.
#
# Output :
# """
# )
# # "Based on the input sentence, extract key adjectives and nouns.Only Output extracted key words."
# # 1. Check if the input sentence contains any grammatical errors. If there are errors, please correct them before proceeding.
#
# prompt_template = PromptTemplate(input_variables=["translate"], template=template)
# prompt_chain = LLMChain(llm=llm, prompt=prompt_template)
#
# from langchain.chains import SimpleSequentialChain
# overall_chain = SimpleSequentialChain(chains=[translate_chain, prompt_chain], verbose=True)
#
# response = overall_chain.run(text)
# return response
def main(): def main():
"""Main function""" """Main function"""
translate_to_en("生成一件运动风格的夹克,带有拉链和口袋,适合休闲穿着") text = translate_to_en("fire")
print(text)
if __name__ == "__main__": if __name__ == "__main__":