Skip to content

Commit

Permalink
fix: create ticket tool
Browse files Browse the repository at this point in the history
system msg for data owner should include app_id.
raise correct exception
check if app exists
  • Loading branch information
Erez Sharim committed Jul 5, 2024
1 parent 7387139 commit 3e9b91b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
19 changes: 13 additions & 6 deletions app/llm/nodes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
import functools

from langchain.output_parsers import PydanticOutputParser
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field

from app.llm.tools.deny_access_tool import create_deny_provision_tool
from app.models import ConversationTypes
Expand Down Expand Up @@ -125,8 +126,12 @@ class IGNOutput(BaseModel):
app_name: str = Field(description="the app name")


ign_parser = PydanticOutputParser(pydantic_object=IGNOutput)


def entry_point_node(data_context):
def _epn(state):
data_context["format_instructions"] = ign_parser.get_format_instructions()
agent = create_agent(
prompt=get_prompt(prompt_id=ENTRY_POINT, data_context=data_context),
tools=[find_app_extra_inst_tool],
Expand All @@ -135,17 +140,19 @@ def _epn(state):
)

result = agent.invoke(state)
output = result["output"]
if not isinstance(output, dict):

try:
output = IGNOutput.model_validate(result["output"])
except Exception:
return {
"sender": "entry_point",
}

return {
"sender": "entry_point",
APP_ID_KEY: output[APP_ID_KEY],
APP_NAME_KEY: output[APP_NAME_KEY],
EXTRA_INSTRUCTIONS_KEY: output[EXTRA_INSTRUCTIONS_KEY],
APP_ID_KEY: output.app_id,
APP_NAME_KEY: output.app_name,
EXTRA_INSTRUCTIONS_KEY: output.extra_instructions,
}

return _epn
5 changes: 3 additions & 2 deletions app/llm/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

TEMPLATES = {
ENTRY_POINT: """
Your purpose is to fetch extra instructions for the app_name.
Your purpose is to fetch extra instructions for the app.
<known applications>
{known_apps}
</known applications>
return the following in json formatted string: "extra_instructions", "app_id", "app_name", and nothing more.
The current user email is: {email}
The current workspace id is: {workspace_id}
The conversation id is: {conversation_id}
{format_instructions}
""",
RECOMMENDATION_TEMPLATE: """
Your only goal is to help users get the correct access by recommendation.
Expand Down
7 changes: 5 additions & 2 deletions app/llm/tools/create_ticket_for_role_request_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ async def _request_roles(
app_name=app_name, workspace_id=workspace_id, tx_context=tx_context
)

if app is None:
return "use recommender"

try:
answer = await should_auto_approve(
ws=ws, dir=dir, app=app, user_email=user_email, **kwargs
Expand All @@ -111,7 +114,7 @@ async def _request_roles(
if success:
return "access approved automatically"
else:
raise ValueError(
raise ToolException(
"failed to provision access for unknown reason"
)

Expand Down Expand Up @@ -164,7 +167,7 @@ async def _request_roles(

checkpoint = empty_checkpoint()
kwargs_str = "\n".join(f"{key}: {value}" for key, value in kwargs.items())
sys_msg = f"requester: {user_email}.\nprevious conversation summary: {conv_summary}.\ndirectory: {directory}\napp_name: {app_name}\n{kwargs_str}"
sys_msg = f"requester: {user_email}.\nprevious conversation summary: {conv_summary}.\ndirectory: {directory}\napp_id: {app.id}\napp_name: {app_name}\n{kwargs_str}"
checkpoint["channel_values"] = {
MEMORY_KEY: [
SystemMessage(content=sys_msg),
Expand Down

0 comments on commit 3e9b91b

Please sign in to comment.