Skip to content

Commit

Permalink
Remove LANGSMITH (hub) dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Aug 12, 2024
1 parent dd7b707 commit eeae954
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
12 changes: 4 additions & 8 deletions src/main/askai/core/askai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
Copyright (c) 2024, HomeSetup
"""
from functools import lru_cache

from hspylib.core.metaclass.singleton import Singleton

from askai.__classpath__ import classpath
from askai.core.askai_configs import configs
from askai.core.support.platform import get_os, get_shell, get_user, SupportedPlatforms, SupportedShells
from askai.core.support.utilities import read_resource
from functools import lru_cache
from hspylib.core.metaclass.singleton import Singleton
from langchain import hub
from langchain_core.prompts import ChatPromptTemplate


class AskAiPrompt(metaclass=Singleton):
Expand Down Expand Up @@ -56,10 +56,6 @@ def read_prompt(self, template_file: str, prompt_dir: str = None) -> str:
"""Read a processor prompt template and set its persona."""
return read_resource(prompt_dir or self.PROMPT_DIR, template_file)

def hub(self, owner_repo_commit) -> ChatPromptTemplate:
"""Read a prompt from LangChain hub."""
return hub.pull(owner_repo_commit)

def append_path(self, path: str) -> str:
"""Return the PROMPT_DIR with the extra path appended."""
return f"{self.PROMPT_DIR}/{path}"
Expand Down
4 changes: 2 additions & 2 deletions src/main/askai/core/askai_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import re

# AskAI config directory.
ASKAI_DIR: Path = Path(f'{os.getenv("HHS_DIR", os.getenv("ASKAI_DIR", str(Path.home())))}/askai')
ASKAI_DIR: Path = Path(f'{os.getenv("ASKAI_DIR", os.getenv("HHS_CACHE_DIR", str(Path.home())))}/askai')
if not ASKAI_DIR.exists():
ASKAI_DIR: Path = classpath.resource_path()
ASKAI_DIR.mkdir(parents=True, exist_ok=True)

# Make sure the AskAI directory is exported.
os.environ["ASKAI_DIR"] = str(ASKAI_DIR)
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/features/router/task_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self):
@property
def agent_template(self) -> ChatPromptTemplate:
"""Retrieve the Structured Agent Template."""
return prompt.hub("hwchase17/structured-chat-agent")
return prompt.read_prompt("langchain/structured-agent")

@property
def lc_agent(self) -> Runnable:
Expand Down
36 changes: 36 additions & 0 deletions src/main/askai/resources/prompts/langchain/structured-agent.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Respond to the human as helpfully and accurately as possible. You have access to the following tools:

{tools}

Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).

Valid "action" values: "Final Answer" or {tool_names}

Provide only ONE action per $JSON_BLOB, as shown:

```
{{
"action": $TOOL_NAME,
"action_input": $INPUT
}}
```

Follow this format:

Question: input question to answer
Thought: consider previous and subsequent steps
Action:
```
$JSON_BLOB
```
Observation: action result
... (repeat Thought/Action/Observation N times)
Thought: I know what to respond
Action:
```
{{
"action": "Final Answer",
"action_input": "Final response to human"
}}

Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation

0 comments on commit eeae954

Please sign in to comment.