How to customize the processing process in the request chain? #144

Closed
opened 2026-02-16 00:18:58 -05:00 by yindo · 1 comment
Owner

Originally created by @Lufffya on GitHub (Mar 21, 2024).

from langchain_community.chat_models import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

from ai_academic.prompts.translation import SYSTEM_MESSAGE

_prompt = ChatPromptTemplate.from_messages(
    [
        ("system", SYSTEM_MESSAGE),
        ("human", "{text}"),
    ]
)
_model = ChatOpenAI()

chain = _prompt | _model

image
image

For example, if a file name is passed in, I want to determine in the server what the file name is by reading a pre-existing file, parsing it into text, and inputting it into the model.

Specifically, "HI" will be replaced by "HI.txt". I judge that if it is a file, read the file content as model input.

Originally created by @Lufffya on GitHub (Mar 21, 2024). ``` from langchain_community.chat_models import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from ai_academic.prompts.translation import SYSTEM_MESSAGE _prompt = ChatPromptTemplate.from_messages( [ ("system", SYSTEM_MESSAGE), ("human", "{text}"), ] ) _model = ChatOpenAI() chain = _prompt | _model ``` ![image](https://github.com/langchain-ai/langserve/assets/49063302/60756f4e-c578-4946-92a5-b286b5813100) ![image](https://github.com/langchain-ai/langserve/assets/49063302/c83fa400-5dfe-4dd1-9766-05c95cdc1408) For example, if a file name is passed in, I want to determine in the server what the file name is by reading a pre-existing file, parsing it into text, and inputting it into the model. Specifically, "HI" will be replaced by "HI.txt". I judge that if it is a file, read the file content as model input.
yindo closed this issue 2026-02-16 00:18:58 -05:00
Author
Owner

@eyurtsev commented on GitHub (Mar 27, 2024):

Prepend a runnable lambda to your chain to manipulate the input. (This is more of an LCEL question rather than langserve.)

@eyurtsev commented on GitHub (Mar 27, 2024): Prepend a runnable lambda to your chain to manipulate the input. (This is more of an LCEL question rather than langserve.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#144