Untitled

 avatar
unknown
plain_text
a month ago
3.6 kB
6
Indexable
@tool
def create_meeting_tool(user_query, state: Annotated[dict, InjectedState], config: RunnableConfig) -> str:
    """
    Tool that creates the meeting once the meeting details are confirmed
    Args:
        user_query: The user query request for creating a meeting with 1 or more participants.
    """
    access_token = config["configurable"]["access_token"]
    user_timestamp = config["configurable"]["user_timestamp"]
    user_timezone=config["configurable"]["user_timezone"]
    llm = model_categories["l_model"]
    parser = JsonOutputParser(pydantic_object=MeetingInvite)
    meeting_invite_prompt = PromptTemplate(
        template="""
    You are a system that parses a user's meeting request: {query}
    and get the meeting details from the conversation {conversation_history}

    You must return valid JSON with these exact keys:
    1. "meeting_start"
    2. "meeting_end"
    3. "attendees"
    4. "email_subject"
    5. "email_body"

    Requirements:
    - "meeting_start" / "meeting_end":
     -Get the meeting start and meeting end time from the conversation .
     -After gathering the meeting start and end_date, refer to the  current_user timestamp {user_timestamp}.
     Use the user timestamp to calculate the appropriate meeting_start and meeting_end time.
     The meeting_start and meeting_end must be in the same format as current_user timestamp format
    - "attendees":
      - A list of attendee email addresses.Get the list of attendees from the conversation 
    - "email_subject":
      - Get the email_subject from the user.If the user has not provided any email_subject then create one based on the conversation.
    - "email_body":
      - Get the email_body from the user.If the user has not provided any email_subject then create one based on the conversation.
      -Use the email topics as reference.

    No additional keys beyond these five should be in your output.

    {format_instructions}
    """,
        input_variables=["query", "conversation_history","current_utc_time"],
        partial_variables={"format_instructions": parser.get_format_instructions()},
    )
    chain = meeting_invite_prompt | llm | parser
    response = chain.invoke({"query": user_query, "conversation_history": state["messages"],"user_timestamp":user_timestamp})
    outlook_details_of_user_url = f"{storage_api_url}/outlook/list-connected-outlook-accounts"
    response = requests.request("GET", outlook_details_of_user_url, headers={'Authorization': f"Bearer {access_token}"})
    if response.status_code == 200:
         outlook_details_of_user_data = response.json()
    else:
         return "Failed fetching outlook account_id details of sender"
    user_account_details = outlook_details_of_user_data.get("accounts", [])
    user_outlook_account_id = user_account_details[0].get("outlook_account_id", "") if user_account_details else ""
    email_details_url = f"{storage_api_url}/outlook/reply"
    email_details_payload = json.dumps({
        "account_id": user_outlook_account_id,
        "message_id": "",
        "reply_content": response["email_body"],
        "to": response["to"],
        "cc": response["cc"],
        "from_add": "",
        "attachment_info": [],
        "subject": "response["email_subject"]
})
    email_request_api = requests.request("POST", email_details_url,
                                           headers={'Authorization': f"Bearer {access_token}"},
                                           data=email_details_payload)
    return email_request_api.text


    modify this as well similarly
Editor is loading...
Leave a Comment