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

How do I use create_react_agent in langServe? #759

Open
Jimmy-L99 opened this issue Sep 12, 2024 · 2 comments
Open

How do I use create_react_agent in langServe? #759

Jimmy-L99 opened this issue Sep 12, 2024 · 2 comments

Comments

@Jimmy-L99
Copy link

Jimmy-L99 commented Sep 12, 2024

Server test code as follows:

llm_end_point_url = "http://172.16.21.155:8000/v1/"
model = ChatOpenAI(model="glm4v-9b",base_url=llm_end_point_url, api_key="api_key")

### embedding ###
embedding_model = HuggingFaceEmbeddings(model_name='/root/ljm/bge/bge-large-zh-v1.5')

### milvus ###
milvus_host = "***"
milvus_port = ***
collection_name = "***"

vector_store = Milvus(
    embedding_function=embedding_model,
    collection_name="langchain_lichi_txt",
    connection_args={"host": milvus_host, "port": milvus_port, "db_name": "***"}, 
)

retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 3})

RAG = create_retriever_tool(
    retriever=retriever,
    name="***",
    description="***",
)
tools = [RAG]

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

agent_executor = create_react_agent(model, tools, debug=True)
rag_chain = ConversationalRetrievalChain.from_llm(
    llm=model,
    retriever=retriever
)
add_routes(
    app,
    agent_executor,
    path="/Litchi_RAG",
)

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="172.16.21.155", port=8010)

Client test code as follows:

rag_chain = RemoteRunnable("http://172.16.21.155:8010/RAG")
query = "********?"
response = rag_chain.invoke({"question": query})
print(response)

Server error:

  File "/root/anaconda3/envs/ljm_glm4_conda/lib/python3.11/site-packages/langchain_core/messages/utils.py", line 301, in _convert_to_message
    raise NotImplementedError(f"Unsupported message type: {type(message)}")
NotImplementedError: Unsupported message type: <class 'NoneType'>

Q:

If I use create_react_agent, always have some error, but it will work if I use ConversationalRetrievalChain in add_routes. How should I fix it if I want to use create_react_agent?

@eyurtsev
Copy link
Collaborator

@Jimmy-L99
Copy link
Author

Jimmy-L99 commented Sep 13, 2024

@eyurtsev Thank you for your answer, I saw something about agent from the example, but most of them did not talk about create_retriever_tool and the create_react_agent of langgraph.prebuilt,
I still couldn't get an answer with the agent tool according to my code, I would appreciate it if you could give me more specific examples! TvT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants