Spaces:
Sleeping
Sleeping
from langchain_community.chat_models import ChatOllama | |
from langchain.prompts import ChatPromptTemplate | |
from langchain_core.output_parsers import StrOutputParser | |
from langchain_core.runnables import RunnablePassthrough | |
def generate_title(message: str) -> str: | |
prompt_template = """Generate one concise and descriptive title that is not longer than 3 words. Only generate one that title. Only generate 3 words. No alternatives. No explanation. Generate this title based on the following message: | |
Message: {message} | |
Title: """ | |
prompt = ChatPromptTemplate.from_template(prompt_template) | |
model = ChatOllama(model="mistral") | |
title_chain = ( | |
{"message": RunnablePassthrough()} | |
| prompt | |
| model | |
| StrOutputParser() | |
) | |
result = title_chain.invoke(message) | |
return result | |