Merge branch 'refs/heads/develop' into local
This commit is contained in:
@@ -19,7 +19,7 @@ class Settings(BaseSettings):
|
||||
LOGGING_CONFIG_FILE = os.path.join(BASE_DIR, 'logging_env.py')
|
||||
|
||||
|
||||
OSS = "S3"
|
||||
OSS = "minio"
|
||||
DEBUG = False
|
||||
if DEBUG:
|
||||
LOGS_PATH = "logs/"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from langchain.chains import LLMChain
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate, \
|
||||
PromptTemplate
|
||||
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
|
||||
|
||||
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.
|
||||
And can translate various languages into English.
|
||||
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."""
|
||||
)
|
||||
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)
|
||||
|
||||
template = (
|
||||
"""
|
||||
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.
|
||||
result = translate_chain.invoke(text)
|
||||
|
||||
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.
|
||||
logging.info("translate result : " + result.get('text'))
|
||||
# print("translate result : " + result.get('text'))
|
||||
return result.get('text')
|
||||
|
||||
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
|
||||
# template = (
|
||||
# """
|
||||
# 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 :
|
||||
# """
|
||||
# )
|
||||
# # "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():
|
||||
"""Main function"""
|
||||
translate_to_en("生成一件运动风格的夹克,带有拉链和口袋,适合休闲穿着")
|
||||
text = translate_to_en("fire")
|
||||
print(text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user