generated from langchain-ai/data-enrichment
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Define the configurable parameters for the chat bot.""" | ||
|
||
import os | ||
from dataclasses import dataclass, fields | ||
from typing import Any, Optional | ||
|
||
from langchain_core.runnables import RunnableConfig | ||
|
||
from chatbot.prompts import SYSTEM_PROMPT | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ChatConfigurable: | ||
"""The configurable fields for the chatbot.""" | ||
|
||
user_id: str = "default-user" | ||
mem_assistant_id: str = ( | ||
"memory_graph" # update to the UUID if you configure a custom assistant | ||
) | ||
model: str = "anthropic/claude-3-5-sonnet-20240620" | ||
delay_seconds: int = 10 # For debouncing memory creation | ||
system_prompt: str = SYSTEM_PROMPT | ||
# None will default to connecting to the local deployment | ||
memory_service_url: str | None = None | ||
|
||
@classmethod | ||
def from_runnable_config( | ||
cls, config: Optional[RunnableConfig] = None | ||
) -> "ChatConfigurable": | ||
"""Load configuration.""" | ||
configurable = ( | ||
config["configurable"] if config and "configurable" in config else {} | ||
) | ||
values: dict[str, Any] = { | ||
f.name: os.environ.get(f.name.upper(), configurable.get(f.name)) | ||
for f in fields(cls) | ||
if f.init | ||
} | ||
return cls(**{k: v for k, v in values.items() if v}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Define utility functions for your graph.""" | ||
|
||
from typing import Any, Mapping, Optional | ||
|
||
from langchain.chat_models import init_chat_model | ||
from langchain_core.language_models import BaseChatModel | ||
|
||
|
||
def format_memories(memories: Optional[list[Mapping[str, Any]]]) -> str: | ||
"""Format the user's memories.""" | ||
if not memories: | ||
return "" | ||
# Note Bene: You can format better than this.... | ||
formatted_memories = "\n".join( | ||
f'{str(m["value"])}\tLast updated: {m["updated_at"]}' for m in memories | ||
) | ||
return f""" | ||
## Memories | ||
You have noted the following memorable events from previous interactions with the user. | ||
<memories> | ||
{formatted_memories} | ||
</memories> | ||
""" | ||
|
||
|
||
def init_model(fully_specified_name: str) -> BaseChatModel: | ||
"""Initialize the configured chat model.""" | ||
if "/" in fully_specified_name: | ||
provider, model = fully_specified_name.split("/", maxsplit=1) | ||
else: | ||
provider = None | ||
model = fully_specified_name | ||
return init_chat_model(model, model_provider=provider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.