-
Notifications
You must be signed in to change notification settings - Fork 234
List index out of range _parse_chat_history_gemini #859
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
Labels
Comments
could you share a reproducible snippet, please? |
from datetime import datetime, timezone
from langchain_core.prompts import ChatPromptTemplate
# ....
from typing import Annotated, Any, Dict, List, Union
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode, tools_condition
from app.llm.base import llm_handler, llm
# ...
from langgraph.prebuilt import create_react_agent
class State(TypedDict):
messages: Annotated[list, add_messages]
selected_tools: list[str]
tree: dict[str, Any]
class RepoAgent:
def __init__(self, handler: Union[TestHandler, TestHandler2], branch: str | None = None, system_message: str | None = None):
self.handler = handler
self.branch = branch
self.system_message = system_message
self.agent = self.get_repo_agent()
def get_repo_agent(self):
if not llm:
raise ValueError("LLM not initialized")
builder = StateGraph(State)
tools = get_repo_agent_tools(self.handler, self.branch)
if not self.handler.project:
raise ValueError("No Project has been provided.")
def fetch_tree(state: State):
return state
def agent(state: State):
# Map tool IDs to actual tools
# based on the state's selected_tools list.
if not llm:
raise ValueError("LLM not initialized")
selected_tools = tools
# Bind the selected tools to the LLM for the current interaction.
llm_with_tools = llm.bind_tools(selected_tools)
# Invoke the LLM with the current messages and return the updated message list.
return {"messages": [llm_with_tools.invoke(state["messages"], config={"callbacks": [CostCallbackHandler(self.handler.usage_information)]})]}
pb_react_agent = create_react_agent(llm, tools=tools, prompt=self.system_message)
builder.add_node("agent", agent)
builder.add_edge(START, "fetch_tree")
builder.add_node("fetch_tree", fetch_tree)
builder.add_node("pb_agent", pb_react_agent)
builder.add_edge("fetch_tree", "pb_agent")
graph = builder.compile()
return graph
def get_agent(self):
return self.agent This was the example code snippet that was failing for me, thanks a lot! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting the following error in file https://github.com/langchain-ai/langchain-google/blob/main/libs/vertexai/langchain_google_vertexai/chat_models.py
A safety check should be in place, e.g.
parsed_content[0] if parsed_content else {"content": ""}
The text was updated successfully, but these errors were encountered: