Skip to content

pass parameter betweens each Runnables in a chain #479

Answered by eyurtsev
shaojun asked this question in Q&A
Discussion options

You must be logged in to vote

OK first here's a simple solution without Context:

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough, RunnableGenerator
from langchain_openai.chat_models import ChatOpenAI

from langserve import CustomUserType


class MyCustomRequest(CustomUserType):
    content: str
    prompt: str
    shared_pass_through_parameter: str = "No-natural language content"


model = ChatOpenAI()

prompt = ChatPromptTemplate.from_messages([
    ("system", '{prompt}'),
    ("human", '{content}')
])


def project(request: MyCustomRequest):
    return {
        "prompt": request.prompt,
        "content": request.content,
    }


async def process_response

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@shaojun
Comment options

@eyurtsev
Comment options

@shaojun
Comment options

@eyurtsev
Comment options

Comment options

You must be logged in to vote
1 reply
@shaojun
Comment options

Answer selected by eyurtsev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #474 on February 22, 2024 15:14.