Skip to content

Commit

Permalink
chore: Add langgraph (#67)
Browse files Browse the repository at this point in the history
* chore: Add langgraph

* chore: Bump version
  • Loading branch information
valeriosofi authored May 27, 2024
1 parent bf1b4e5 commit d8b3813
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 531 deletions.
2 changes: 1 addition & 1 deletion nebuly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .init import init

__all__ = ["init", "new_interaction"]
__version__ = "0.3.28"
__version__ = "0.3.29"
14 changes: 10 additions & 4 deletions nebuly/providers/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from langchain.prompts import ChatPromptTemplate, PromptTemplate
from langchain.prompts.chat import AIMessagePromptTemplate, HumanMessagePromptTemplate
from langchain.schema import Document
from langchain.schema.messages import AIMessage, BaseMessage, HumanMessage
from langchain.schema.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage
from langchain.schema.output import LLMResult
from langchain.schema.runnable import RunnableSequence

Expand Down Expand Up @@ -134,10 +134,8 @@ def _parse_output(output: str | dict[str, Any] | AIMessage) -> str:
def _parse_langchain_data( # pylint: disable=too-many-return-statements
data: Any,
) -> str:
if isinstance(data, str):
return data
if isinstance(data, dict):
if len(data) == 1:
if len(data) == 1 and isinstance(list(data.values())[0], str):
return str(list(data.values())[0])
if "answer" in data:
# If the data is a retrieval chain, we want to return the answer
Expand All @@ -151,7 +149,15 @@ def _parse_langchain_data( # pylint: disable=too-many-return-statements
if "question" in data:
# Needed when calling invoke with question and chat_history
return str(data["question"])
if "messages" in data and isinstance(
data["messages"][-1], (HumanMessage, AIMessage, ToolMessage)
):
return str(data["messages"][-1].content)
return "\n".join([f"{key}: {value}" for key, value in data.items()])
if isinstance(data, list):
data = data[-1]
if isinstance(data, (HumanMessage, AIMessage, ToolMessage)):
return str(data.content)
return str(data)


Expand Down
Loading

0 comments on commit d8b3813

Please sign in to comment.