How to make the new variables input available via query method? #91

Closed
opened 2026-02-16 00:18:44 -05:00 by yindo · 0 comments
Owner

Originally created by @xiechengmude on GitHub (Jan 10, 2024).

Question:

If I create the new varialbels: input_variables=["history", "input","lession", "affection"],
and setting like the below code.
I cant make the right query via the swagger docs from langserve. Whats the problem here?
Thank you !

`
#!/usr/bin/env python
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from operator import itemgetter

from langchain.prompts import PromptTemplate,ChatPromptTemplate, MessagesPlaceholder
from langchain.chat_models import ChatOpenAI
from langserve import add_routes
from langchain.schema.output_parser import StrOutputParser
from langchain.schema.runnable import RunnablePassthrough
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain.schema.runnable.history import RunnableWithMessageHistory
from langchain import globals

globals.set_debug(True)

REDIS_URL = "redis://localhost:6379/0"
llm = ChatOpenAI()

_DEFAULT_TEMPLATE = """You are excellent assistant.\n
Based on the pieces of previous conversation:{history}\n
The talking lession: {lession}\n
affection number: {affection}\n
Human: {question}\n
\n
Answer:
"""

BASIC_PROMPT = PromptTemplate(
input_variables=["history", "input","lession", "affection"],
template=_DEFAULT_TEMPLATE
)

app = FastAPI(
title="A simple Server",
version="0.1",
description="A Simple Api Server Using Runnable Interfaces",
)

chain_with_history = RunnableWithMessageHistory(
{"lession": RunnablePassthrough(),
"affection": RunnablePassthrough(),
"question": RunnablePassthrough()}
|PROMPT | llm ,
lambda session_id: RedisChatMessageHistory(session_id, url=REDIS_URL),
input_messages_key="input",
history_messages_key="history",
verbose=True,
max_message_history=5,
)

chain_with_history.invoke({"lession":"Math Lession", "affection":66,
"question":"whats the importanct to learn math well?"})

add_routes(
app,
chain_with_history,
path="/query-test",
)

if name == "main":
uvicorn.run("test:app", host="0.0.0.0", port=7000, reload=True)

`

Originally created by @xiechengmude on GitHub (Jan 10, 2024). ### Question: If I create the new varialbels: input_variables=["history", "input",**"lession", "affection"**], and setting like the below code. I cant make the right query via the swagger docs from langserve. Whats the problem here? Thank you ! ` #!/usr/bin/env python from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware import uvicorn from operator import itemgetter from langchain.prompts import PromptTemplate,ChatPromptTemplate, MessagesPlaceholder from langchain.chat_models import ChatOpenAI from langserve import add_routes from langchain.schema.output_parser import StrOutputParser from langchain.schema.runnable import RunnablePassthrough from langchain.schema.chat_history import BaseChatMessageHistory from langchain.schema.runnable.history import RunnableWithMessageHistory from langchain import globals globals.set_debug(True) REDIS_URL = "redis://localhost:6379/0" llm = ChatOpenAI() _DEFAULT_TEMPLATE = """You are excellent assistant.\n Based on the pieces of previous conversation:{history}\n The talking lession: {lession}\n affection number: {affection}\n Human: {question}\n \n Answer: """ BASIC_PROMPT = PromptTemplate( input_variables=["history", "input","lession", "affection"], template=_DEFAULT_TEMPLATE ) app = FastAPI( title="A simple Server", version="0.1", description="A Simple Api Server Using Runnable Interfaces", ) chain_with_history = RunnableWithMessageHistory( {"lession": RunnablePassthrough(), "affection": RunnablePassthrough(), "question": RunnablePassthrough()} |PROMPT | llm , lambda session_id: RedisChatMessageHistory(session_id, url=REDIS_URL), input_messages_key="input", history_messages_key="history", verbose=True, max_message_history=5, ) chain_with_history.invoke({"lession":"Math Lession", "affection":66, "question":"whats the importanct to learn math well?"}) add_routes( app, chain_with_history, path="/query-test", ) if __name__ == "__main__": uvicorn.run("test:app", host="0.0.0.0", port=7000, reload=True) `
yindo closed this issue 2026-02-16 00:18:44 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#91