Pass data dynamically to LangServer server file #14291
Replies: 4 comments 2 replies
-
🤖 Hello @DameStoilovski99! I'm Dosu, a bot that helps with bug-solving, answering queries, and guiding contributors in the LangChain community. While waiting for a human maintainer, I'm here to assist you. Let's get started on your issue! To pass data dynamically from a function in a .py file to a LangServe server file, you can modify the def create_runnable(collection_name):
embeddings = OpenAIEmbeddings()
db = PGVector(
collection_name=collection_name,
connection_string=f"postgresql+psycopg2://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{POSTGRES_PORT}/{POSTGRES_DB}",
embedding_function=embeddings,
)
# rest of your code Now, when you call add_routes(
app,
create_runnable("my_dynamic_collection_name"),
path="/openai",
) In this example, This approach is based on the definition of the I hope this helps! If you have any other questions, feel free to ask. Best regards, SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
I have the same question |
Beta Was this translation helpful? Give feedback.
-
Nope, you can't create a route dynamically based on the API call parameters. Routes and endpoints have to be created when the server starts or reloads, so your create_runnable() call must create the runnable first, then add it as a route and endpoint to the fastapi server. Then you can call it. I had the same issue, had to create multiple routes. I suggest you get a list of all your collections from the db, then in a for loop, add a bunch of routes dynamically, named differently, one for each collection. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Looks like a configurable chain is the way to go. https://github.com/langchain-ai/langserve/blob/main/examples/configurable_chain/client.ipynb |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello guys, I am trying to pass data dynamically from a function in a .py file to a LangServe server file, does anyone have been through this process and maybe have an idea how it can be done?
Below is my code of the LangServe server where I want to accept the collection_name dynamically, for example, instead of collection_name="openAi" to be collection_name=collection_name
Beta Was this translation helpful? Give feedback.
All reactions