Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Langserve example from Quickstart tutorial not working #14757

Closed
1 of 14 tasks
AvijeetPrasad opened this issue Dec 15, 2023 · 10 comments
Closed
1 of 14 tasks

Langserve example from Quickstart tutorial not working #14757

AvijeetPrasad opened this issue Dec 15, 2023 · 10 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)

Comments

@AvijeetPrasad
Copy link

AvijeetPrasad commented Dec 15, 2023

System Info

Name Version Build Channel
langchain 0.0.350 pypi_0 pypi
langchain-cli 0.0.19 pypi_0 pypi
langchain-community 0.0.3 pypi_0 pypi
langchain-core 0.1.1 pypi_0 pypi
langchain-experimental 0.0.47 pypi_0 pypi
python 3.12.0 h47c9636_0_cpython conda-forge

System: macOS 14.2 (Apple M1 chip)

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

  1. Go to https://python.langchain.com/docs/get_started/quickstart
  2. Do all the package installations as guided.
  3. Copy the python code under the section 'Serving with Langserve' and save it to a file serve.py
  4. Execute the file python serve.py
  5. Open http://localhost:8000 in browser

Expected behavior

Expected to see Langserve UI. Got the following error instead.


LANGSERVE: Playground for chain "/category_chain/" is live at:
LANGSERVE: │
LANGSERVE: └──> /category_chain/playground/
LANGSERVE:
LANGSERVE: See all available routes at /docs/

LANGSERVE: ⚠️ Using pydantic 2.5.2. OpenAPI docs for invoke, batch, stream, stream_log endpoints will not be generated. API endpoints and playground should work as expected. If you need to see the docs, you can downgrade to pydantic 1. For example, pip install pydantic==1.10.13. See fastapi/fastapi#10360 for details.

INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
INFO: ::1:58516 - "GET / HTTP/1.1" 404 Not Found
INFO: ::1:58516 - "GET /favicon.ico HTTP/1.1" 404 Not Found
^CINFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [91610]

Copy link

dosubot bot commented Dec 15, 2023

🤖

Hello @AvijeetPrasad! I'm Dosu, a friendly bot here to lend a digital hand with your LangChain issues. While the human maintainers are away, I'm here to help you debug, answer questions, and guide you if you're looking to contribute. Looking forward to assisting you!

The "404 Not Found" error you're encountering is likely due to the placeholder NotImplemented in the add_routes(app, NotImplemented) function call in your serve.py file. This placeholder should be replaced with the actual chain you want to add to your LangChain application.

Here's the problematic line in your code:

add_routes(app, NotImplemented)

To resolve this issue, you should replace NotImplemented with the actual chain you want to add. For instance, if you have a chain named my_chain, you would modify the line to look like this:

add_routes(app, my_chain)

Please ensure that my_chain is properly defined and imported in your serve.py file. You can refer to the server.py file in the LangChain repository for an example of how to properly set up your server file.

As for the function add_routes(app, NotImplemented), I wasn't able to find specific documentation within the LangChain repository that explains its exact function and purpose. However, based on its usage, it appears to be a function that adds routes to the FastAPI application for the specified chain. If you have further questions about this function, I recommend checking the FastAPI documentation or the LangChain codebase for more information.

I hope this helps! If you have any other questions or if something is unclear, please let me know.

Sources


This 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.

@dosubot dosubot bot added Ɑ: doc loader Related to document loader module (not documentation) 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Dec 15, 2023
@AvijeetPrasad
Copy link
Author

Here's the code from the quickstart page for reference

#!/usr/bin/env python
from typing import List

from fastapi import FastAPI
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.schema import BaseOutputParser
from langserve import add_routes

# 1. Chain definition


class CommaSeparatedListOutputParser(BaseOutputParser[List[str]]):
    """Parse the output of an LLM call to a comma-separated list."""

    def parse(self, text: str) -> List[str]:
        """Parse the output of an LLM call."""
        return text.strip().split(", ")


template = """You are a helpful assistant who generates comma separated lists.
A user will pass in a category, and you should generate 5 objects in that category in a comma separated list.
ONLY return a comma separated list, and nothing more."""
human_template = "{text}"

chat_prompt = ChatPromptTemplate.from_messages([
    ("system", template),
    ("human", human_template),
])
category_chain = chat_prompt | ChatOpenAI() | CommaSeparatedListOutputParser()

# 2. App definition
app = FastAPI(
    title="LangChain Server",
    version="1.0",
    description="A simple API server using LangChain's Runnable interfaces",
)

# 3. Adding chain route
add_routes(
    app,
    category_chain,
    path="/category_chain",
)

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="localhost", port=8000)

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 15, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 22, 2024
@sishuoyang
Copy link

I had exactly the same problem.

INFO:     Started server process [55250]
INFO:     Waiting for application startup.

 __          ___      .__   __.   _______      _______. _______ .______     ____    ____  _______
|  |        /   \     |  \ |  |  /  _____|    /       ||   ____||   _  \    \   \  /   / |   ____|
|  |       /  ^  \    |   \|  | |  |  __     |   (----`|  |__   |  |_)  |    \   \/   /  |  |__
|  |      /  /_\  \   |  . `  | |  | |_ |     \   \    |   __|  |      /      \      /   |   __|
|  `----./  _____  \  |  |\   | |  |__| | .----)   |   |  |____ |  |\  \----.  \    /    |  |____
|_______/__/     \__\ |__| \__|  \______| |_______/    |_______|| _| `._____|   \__/     |_______|

LANGSERVE: Playground for chain "/agent/" is live at:
LANGSERVE:  │
LANGSERVE:  └──> /agent/playground/
LANGSERVE:
LANGSERVE: See all available routes at /docs/

LANGSERVE: ⚠️ Using pydantic 2.6.4. OpenAPI docs for invoke, batch, stream, stream_log endpoints will not be generated. API endpoints and playground should work as expected. If you need to see the docs, you can downgrade to pydantic 1. For example, `pip install pydantic==1.10.13`. See https://github.com/tiangolo/fastapi/issues/10360 for details.

INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
INFO:     ::1:58755 - "GET /agent HTTP/1.1" 404 Not Found
INFO:     ::1:58756 - "GET /agent HTTP/1.1" 404 Not Found

@agirotra
Copy link

any solutions found for the above error ??

@trannhatquy
Copy link

any solutions please

@plpxsk
Copy link

plpxsk commented May 23, 2024

Try following the suggestion in the error message, to downgrade pydantic from 2.x.x to 1.xx

Per above, this would be pip install pydantic==1.10.13

@Haydn-Mann
Copy link

Haydn-Mann commented May 30, 2024

I am still having issues with this. I followed the tutorial from Langchain and am still getting this issue.

tutorial link: https://www.youtube.com/watch?v=OV2ZIWFBe0s&ab_channel=LangChain

@AnhDai1997
Copy link

change to
uvicorn.run(app, host="0.0.0.0", port=8000)

@wangzhuoya
Copy link

@sishuoyang
😂It is not a mistake, you can open "http://localhost:8000/agent/playground/" in web.

@MohamedLahmeri01
Copy link

when you run your server.py , you need to configure in url to this path of your endpoint :
`

1. the definition of our chain that we just built above

2. Our FastAPI app

3. definition of a route from which to serve the chain , which is done with "langserve.add_routes"

from typing import List

from fastapi import FastAPI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

from langchain_openai import ChatOpenAI (for openai)

from langchain_groq import ChatGroq
from langserve import add_routes
import os

os.environ["GROQ_API_KEY"] = groq_api

1. Create prompt template

system_template = "Translate the following into {language}:"
prompt_template = ChatPromptTemplate.from_messages([
('system', system_template),
('user', '{text}')
])

2. Create model

model = ChatGroq(model="llama3-70b-8192")

3. Create parser

parser = StrOutputParser()

4. Create chain

chain = prompt_template | model | parser

4. App definition

app = FastAPI(
title="LangChain Server",
version="1.0",
description="A simple API server using LangChain's Runnable interfaces",
)

5. Adding chain route

add_routes(
app,
chain,
path="/chain", # add this endpoint to url in web-browser then add '/playground'
)

if name == "main":
import uvicorn

uvicorn.run(app, host="localhost", port=8000)

`
so in the url write this : " http://localhost:8000/chain/playground/ "
remember to replace '/chain' with what you wrote in add_route function in path attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)
Projects
None yet
Development

No branches or pull requests

9 participants