Skip to content

Commit

Permalink
Fix/fix langchain retrieval chain (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriosofi authored Mar 19, 2024
1 parent a588a18 commit c2b57da
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
22 changes: 16 additions & 6 deletions nebuly/providers/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,29 @@ def _parse_langchain_data( # pylint: disable=too-many-return-statements
if "input" in data:
# Needed when calling invoke with input and chat_history
return str(data["input"])
if "question" in data:
# Needed when calling invoke with question and chat_history
return str(data["question"])
return "\n".join([f"{key}: {value}" for key, value in data.items()])
return str(data)


def _parse_langchain_history(inputs: dict[str, Any]) -> list[HistoryEntry]:
if "chat_history" in inputs:
history = inputs["chat_history"]
return [
HistoryEntry(
user=str(history[i].content), assistant=str(history[i + 1].content)
)
for i in range(0, len(history), 2)
]
if len(history) > 0:
if isinstance(history[0], tuple):
# In some chains, the chat history is a list of tuples
return [
HistoryEntry(user=str(message[0]), assistant=str(message[1]))
for message in history
]
return [
HistoryEntry(
user=str(history[i].content), assistant=str(history[i + 1].content)
)
for i in range(0, len(history), 2)
]
return []


Expand Down
88 changes: 44 additions & 44 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2b57da

Please sign in to comment.