Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caddy Opensearch #150

Merged
merged 53 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9dc91c2
editing survey message
mhgov Jun 14, 2024
d9951bc
reword of control survey phrasing take 2
mhgov Jun 14, 2024
75efdc6
adding in a copy text button
mhgov Jun 18, 2024
b4145d9
poetry updates
mhgov Jun 18, 2024
e60dba6
chagnes
mhgov Jun 18, 2024
629156a
changing copy function
mhgov Jun 19, 2024
5c115a8
changes to pyperclip test
mhgov Jun 20, 2024
cc01a13
pyperclip
mhgov Jun 20, 2024
edc94ae
your client ot you language
mhgov Jun 20, 2024
fef1521
2nd person
mhgov Jun 20, 2024
6143d3d
2nd person
mhgov Jun 20, 2024
c659e5c
test_embedding_local file for lcal embedidng model
mhgov Jun 26, 2024
c009800
Initial teams structure
AndreasThinks Jul 8, 2024
8d652dd
added teams verification refactor
AndreasThinks Jul 8, 2024
d4e5f23
changed async handling
AndreasThinks Jul 8, 2024
96a8276
Merge pull request #132 from i-dot-ai/feature/teams_integration
AndreasThinks Jul 8, 2024
66540d6
git
AndreasThinks Jul 8, 2024
29ccb3b
Merge pull request #133 from i-dot-ai/feature/teams_integration
AndreasThinks Jul 8, 2024
6c3ba0c
Update deployment with Teams Vars
kurtismassey Jul 9, 2024
77a3081
added options handling to Teams endpoints
AndreasThinks Jul 9, 2024
0749e87
Merge pull request #134 from i-dot-ai/feature/teams_integration
AndreasThinks Jul 9, 2024
c46b789
improved async handling for Teams
AndreasThinks Jul 9, 2024
44008d1
added get routes
AndreasThinks Jul 9, 2024
2ba90a0
added debug
AndreasThinks Jul 9, 2024
fad1b9a
returned post method
AndreasThinks Jul 9, 2024
593a880
added msesage type debugging
AndreasThinks Jul 9, 2024
355c561
tweaked bot formula
AndreasThinks Jul 9, 2024
f61aa01
Initial Teams structure
kurtismassey Jul 13, 2024
6631ff0
Merge pull request #135 from i-dot-ai/feature/teamsIntegration
kurtismassey Jul 17, 2024
ed46a4f
teamsIntegration with updated readme
mhgov Jul 18, 2024
54c40cd
bedrock opensearch
mhgov Jul 18, 2024
ae2f5c7
ragas pipeline. No data provided
mhgov Jul 18, 2024
e6dc55e
ragas &updates to retrieval_chain for bedrock only
mhgov Jul 18, 2024
347d87c
Updates to env variables
kurtismassey Jul 19, 2024
6812100
Example env update
kurtismassey Jul 19, 2024
7bc4608
Merge pull request #136 from i-dot-ai/mh-ragas
kurtismassey Jul 19, 2024
a0fb100
new reactions in teams
mhgov Aug 2, 2024
66371aa
Add invoke buttons
kurtismassey Aug 8, 2024
dfc3d35
inserting rather than appending
mhgov Aug 13, 2024
82e5285
Merge pull request #147 from i-dot-ai/mh-moveapproval
mhgov Aug 13, 2024
67f3c35
updated readme for ngrok errors
mhgov Aug 15, 2024
7b96870
updated readme
mhgov Aug 15, 2024
0bc4f02
topic eval notebooks
mhgov Aug 16, 2024
f599692
Route table addition
kurtismassey Aug 16, 2024
4b4b086
Updating storing and routes
kurtismassey Aug 16, 2024
e6c1910
Update prompt handling
kurtismassey Aug 16, 2024
bba23cb
Migrate prompts to dynamo
kurtismassey Aug 16, 2024
9d0b0bb
Logging and format
kurtismassey Aug 17, 2024
7b1d90e
ECS token refresh
kurtismassey Aug 17, 2024
0bbbdbd
Merge pull request #148 from i-dot-ai/feature/migrateRoutesPrompts
kurtismassey Aug 19, 2024
c046947
Fix: remove test branch deployment
kurtismassey Aug 19, 2024
6d25d76
updated commentary on topic eval
mhgov Aug 21, 2024
99fc2d3
Merge pull request #149 from i-dot-ai/mh-teamsmovingchannelmessages
mhgov Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/automated-deployment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
docker push ${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_DEV }}:${{ github.sha }}
- name: Deploy infrastructure
run: |
aws cloudformation deploy --template-file infra/template.yaml --stack-name "caddy-dev" --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=dev MessageTableName=${{ vars.MESSAGES_TABLE_NAME_DEV }} ResponsesTableName=${{ vars.RESPONSES_TABLE_NAME_DEV }} UserTableName=${{ vars.USERS_TABLE_NAME_DEV }} OfficesTableName=${{ vars.OFFICES_TABLE_NAME_DEV }} EvaluationTableName=${{ vars.EVALUATION_TABLE_NAME_DEV }} OpensearchUrl=${{ secrets.OPENSEARCH_DEV_URL }} OpensearchIndex=${{ secrets.OPENSEARCH_INDEX }} CaddyServiceAccountSecretArn=${{ secrets.CADDY_SA_ARN_DEV }} CaddySupervisorServiceAccountSecretArn=${{ secrets.CADDY_SUPERVISOR_SA_ARN_DEV }} CaddyImage=${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_DEV }}:${{ github.sha }} CaddySupervisorGoogleCloudProject=${{ secrets.CADDY_SUPERVISOR_GOOGLE_CLOUD_PROJECT_DEV }} CaddyGoogleCloudProject=${{ secrets.CADDY_GOOGLE_CLOUD_PROJECT_DEV }} LLM=${{ vars.LLM }} DomainName=${{ secrets.CERT_DOMAIN }}
aws cloudformation deploy --template-file infra/template.yaml --stack-name "caddy-dev" --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=dev MessageTableName=${{ vars.MESSAGES_TABLE_NAME_DEV }} RoutesTableName=${{ vars.ROUTES_TABLE_NAME_DEV }} PromptsTableName=${{ vars.PROMPTS_TABLE_NAME_DEV }} ResponsesTableName=${{ vars.RESPONSES_TABLE_NAME_DEV }} UserTableName=${{ vars.USERS_TABLE_NAME_DEV }} OfficesTableName=${{ vars.OFFICES_TABLE_NAME_DEV }} EvaluationTableName=${{ vars.EVALUATION_TABLE_NAME_DEV }} OpensearchUrl=${{ secrets.OPENSEARCH_DEV_URL }} OpensearchIndex=${{ secrets.OPENSEARCH_INDEX }} CaddyServiceAccountSecretArn=${{ secrets.CADDY_SA_ARN_DEV }} CaddySupervisorServiceAccountSecretArn=${{ secrets.CADDY_SUPERVISOR_SA_ARN_DEV }} CaddyImage=${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_DEV }}:${{ github.sha }} CaddySupervisorGoogleCloudProject=${{ secrets.CADDY_SUPERVISOR_GOOGLE_CLOUD_PROJECT_DEV }} CaddyGoogleCloudProject=${{ secrets.CADDY_GOOGLE_CLOUD_PROJECT_DEV }} LLM=${{ vars.LLM }} DomainName=${{ secrets.CERT_DOMAIN }} MicrosoftAppIdSecretArn=${{ secrets.MICROSOFT_APP_ID_SECRET_ARN }} MicrosoftAppPasswordSecretArn=${{ secrets.MICROSOFT_APP_PASSWORD_SECRET_ARN }}
aws cloudformation deploy --template-file infra/opensearch.yaml --stack-name "caddy-opensearch-dev" --region eu-west-3 --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=dev CaddyRoleArn=${{ secrets.CADDY_ROLE_ARN_DEV }}
2 changes: 1 addition & 1 deletion .github/workflows/automated-deployment-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
docker push ${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_PROD }}:${{ github.sha }}
- name: Deploy infrastructure
run: |
aws cloudformation deploy --template-file infra/template.yaml --stack-name "caddy-prod" --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=prod MessageTableName=${{ vars.MESSAGES_TABLE_NAME_PROD }} ResponsesTableName=${{ vars.RESPONSES_TABLE_NAME_PROD }} UserTableName=${{ vars.USERS_TABLE_NAME_PROD }} OfficesTableName=${{ vars.OFFICES_TABLE_NAME_PROD }} EvaluationTableName=${{ vars.EVALUATION_TABLE_NAME_PROD }} OpensearchUrl=${{ secrets.OPENSEARCH_PROD_URL }} OpensearchIndex=${{ secrets.OPENSEARCH_INDEX }} CaddyServiceAccountSecretArn=${{ secrets.CADDY_SA_ARN_PROD }} CaddySupervisorServiceAccountSecretArn=${{ secrets.CADDY_SUPERVISOR_SA_ARN_PROD }} CaddyImage=${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_PROD }}:${{ github.sha }} CaddySupervisorGoogleCloudProject=${{ secrets.CADDY_SUPERVISOR_GOOGLE_CLOUD_PROJECT_PROD }} CaddyGoogleCloudProject=${{ secrets.CADDY_GOOGLE_CLOUD_PROJECT_PROD }} LLM=${{ vars.LLM }} DomainName=${{ secrets.CERT_DOMAIN }}
aws cloudformation deploy --template-file infra/template.yaml --stack-name "caddy-prod" --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=prod MessageTableName=${{ vars.MESSAGES_TABLE_NAME_PROD }} RoutesTableName=${{ vars.ROUTES_TABLE_NAME_PROD }} PromptsTableName=${{ vars.PROMPTS_TABLE_NAME_PROD }} ResponsesTableName=${{ vars.RESPONSES_TABLE_NAME_PROD }} UserTableName=${{ vars.USERS_TABLE_NAME_PROD }} OfficesTableName=${{ vars.OFFICES_TABLE_NAME_PROD }} EvaluationTableName=${{ vars.EVALUATION_TABLE_NAME_PROD }} OpensearchUrl=${{ secrets.OPENSEARCH_PROD_URL }} OpensearchIndex=${{ secrets.OPENSEARCH_INDEX }} CaddyServiceAccountSecretArn=${{ secrets.CADDY_SA_ARN_PROD }} CaddySupervisorServiceAccountSecretArn=${{ secrets.CADDY_SUPERVISOR_SA_ARN_PROD }} CaddyImage=${{ secrets.CADDY_ECR_ENDPOINT }}/${{ secrets.CADDY_ECR_REPO_ID_PROD }}:${{ github.sha }} CaddySupervisorGoogleCloudProject=${{ secrets.CADDY_SUPERVISOR_GOOGLE_CLOUD_PROJECT_PROD }} CaddyGoogleCloudProject=${{ secrets.CADDY_GOOGLE_CLOUD_PROJECT_PROD }} LLM=${{ vars.LLM }} DomainName=${{ secrets.CERT_DOMAIN }}
aws cloudformation deploy --template-file infra/opensearch.yaml --stack-name "caddy-opensearch-prod" --region eu-west-3 --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StageName=prod CaddyRoleArn=${{ secrets.CADDY_ROLE_ARN_PROD }}
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.3
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ To explore the connection to DynamoDB, I have attached the docker-compose file t
$ docker compose up
```

If you get an error with docker, note you may need to change credsStore your .docker/config.json file with:

```json
"credStore": "desktop",
```

## Testing

Running tests on platform agnostic Caddy components with pytest. Tests are stored in tests/caddy_components, and can be invoked by running the below:
Expand Down Expand Up @@ -95,3 +101,24 @@ For ease of deletion, you can remove all the created resources with
```bash
$ aws cloudformation delete-stack --stack-name "INSERT_CUSTOM_STACK_NAME"
```

## Local Teams Deployment

In azure (https://portal.azure.com/#home), creat an azure bot, and add app_id, app_password to the .env from configuration space.

Then you need to build the container and provide a tunnel.

```bash
$ docker compose up
```

Go to ngrok dashboard (https://dashboard.ngrok.com/) and create a domain then expose the domain endpoint for local forwarding on the desired port i.e. 80

```bash
$ ngrok http --domain=insert-static-url 80
```

If you recieve a ngrok 381 errror, this is because ngrok has created an automatic edge. Delete the edge in ngrok dashboard and retry command

In azure bot got to setting > configuration and add static-url with /microsoft-teams/chat into the messaging endpoint
Then in channels use the open in teams button to test locally
42 changes: 37 additions & 5 deletions caddy_chatbot/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

from caddy_core import components as caddy
from caddy_core.services import enrolment
from caddy_core.utils.monitoring import logger

from integrations.google_chat.structures import GoogleChat
from integrations.google_chat.verification import (
verify_google_chat_request,
verify_google_chat_supervision_request,
)

from integrations.microsoft_teams.structures import MicrosoftTeams

from threading import Thread

Expand All @@ -26,17 +28,22 @@ def google_chat_endpoint(event=Depends(verify_google_chat_request)) -> dict:
"""
Handles inbound requests from Google Chat for Caddy
"""
logger.info("New Google Chat Request")
google_chat = GoogleChat()
user = event["user"]["email"]
domain = user.split("@")[1]

domain_enrolled, office = enrolment.check_domain_status(domain)
if domain_enrolled is not True:
logger.info("Domain not enrolled")
return google_chat.responses.DOMAIN_NOT_ENROLLED
logger.info("Domain is enrolled")

user_enrolled, user_record = enrolment.check_user_status(user)
if user_enrolled is not True:
logger.info("User is not enrolled")
return google_chat.responses.USER_NOT_ENROLLED
logger.info("User is enrolled")

included_in_rct = enrolment.check_rct_status(office)
if included_in_rct is True:
Expand Down Expand Up @@ -247,14 +254,39 @@ def google_chat_supervision_endpoint(


@app.post("/microsoft-teams/chat")
def microsoft_teams_endpoint(request: Request):
return JSONResponse(
status_code=status.HTTP_200_OK, content={"text": "Request received"}
)
async def microsoft_teams_endpoint(request: Request):
event = await request.json()
print("POST request received", event)

microsoft_teams = MicrosoftTeams()

match event["type"]:
case "message":
query = microsoft_teams.format_message(event)
caddy.temporary_teams_invoke(microsoft_teams, query, event)
case "invoke":
match event["value"]["action"]["verb"]:
case "proceed":
# TODO Handle Proceed Route
print("Adviser choice was to proceed")
microsoft_teams.update_card(event)
return microsoft_teams.responses.OK
case "redacted_query":
# TODO Handle edit original query
print("Adviser choice was to edit original query")
redacted_card = microsoft_teams.messages.create_redacted_card(event)
microsoft_teams.update_card(event, card=redacted_card)
return microsoft_teams.responses.OK
case "approved":
microsoft_teams.handle_thumbs_up(event)
return microsoft_teams.responses.OK
case "rejected":
microsoft_teams.handle_thumbs_down(event)
return microsoft_teams.responses.OK


@app.post("/microsoft-teams/supervision")
def microsoft_teams_supervision_endpoint(request: Request):
async def microsoft_teams_supervision_endpoint(request: Request):
return JSONResponse(
status_code=status.HTTP_200_OK, content={"text": "Request received"}
)
Expand Down
121 changes: 91 additions & 30 deletions caddy_chatbot/src/caddy_core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from fastapi import status

from langchain.prompts import PromptTemplate
from caddy_core.utils.prompts.default_template import CADDY_PROMPT_TEMPLATE
from caddy_core.utils.prompts.prompt import retrieve_route_specific_augmentation
from caddy_core.utils.prompt import retrieve_route_specific_augmentation, get_prompt

from time import sleep

Expand All @@ -18,10 +17,10 @@

from caddy_core.utils.tables import (
evaluation_table,
message_table,
responses_table,
users_table,
)
from caddy_core.utils.monitoring import logger
from caddy_core.services.retrieval_chain import build_chain
from caddy_core.services import enrolment
from caddy_core.services.evaluation import execute_optional_modules
Expand Down Expand Up @@ -49,6 +48,7 @@ def rct_survey_reminder(event, user_record, chat_client):


def handle_message(caddy_message, chat_client):
logger.info("Running message handler")
module_values, survey_complete = check_existing_call(caddy_message)

if survey_complete is True:
Expand Down Expand Up @@ -107,10 +107,12 @@ def remove_role_played_responses(response: str) -> str:
"""
adviser_index = response.find("Adviser: ")
if adviser_index != -1:
logger.info("Removing role played response")
return True, response[:adviser_index].strip()

adviser_index = response.find("Advisor: ")
if adviser_index != -1:
logger.info("Removing role played response")
return True, response[:adviser_index].strip()

return False, response.strip()
Expand All @@ -128,9 +130,14 @@ def format_chat_history(user_messages: List) -> List:
"""
history_langchain_format = []
for message in user_messages:
human = message["llmPrompt"]
ai = message["llmAnswer"]
history_langchain_format.append((human, ai))
human = message.get("llmPrompt")
ai = message.get("llmAnswer")

if human and ai:
history_langchain_format.append((human, ai))
elif human:
history_langchain_format.append((human, ""))

return history_langchain_format


Expand All @@ -147,7 +154,15 @@ def get_chat_history(message: UserMessage) -> List:
response = responses_table.query(
KeyConditionExpression=Key("threadId").eq(message.thread_id),
)
history = format_chat_history(response["Items"])

sorted_items = sorted(
response["Items"],
key=lambda x: x.get(
"messageReceivedTimestamp", x.get("llmPromptTimestamp", "")
),
)

history = format_chat_history(sorted_items)
return history


Expand Down Expand Up @@ -198,37 +213,37 @@ def format_chat_message(event: ProcessChatMessageEvent) -> UserMessage:


def store_message(message: UserMessage):
message_table.put_item(
responses_table.put_item(
Item={
"threadId": str(message.thread_id),
"messageId": str(message.message_id),
"conversationId": str(message.conversation_id),
"threadId": str(message.thread_id),
"client": message.client,
"userEmail": str(message.user_email),
"message": message.message,
"llmPrompt": message.message,
"messageSentTimestamp": message.message_sent_timestamp,
"messageReceivedTimestamp": str(message.message_received_timestamp),
}
)


def store_response(response: LlmResponse):
responses_table.put_item(
Item={
"responseId": str(response.response_id),
"messageId": str(response.message_id),
"threadId": str(response.thread_id),
"llmPrompt": response.llm_prompt,
"llmAnswer": response.llm_answer,
"llmResponseJSon": response.llm_response_json,
"llmPromptTimestamp": str(response.llm_prompt_timestamp),
"llmResponseTimestamp": str(response.llm_response_timestamp),
}
responses_table.update_item(
Key={"threadId": str(response.thread_id)},
UpdateExpression="set responseId = :rId, llmAnswer = :la, llmResponseJSon = :lrj, llmPromptTimestamp = :lpt, llmResponseTimestamp = :lrt, route = :route, context = :context",
ExpressionAttributeValues={
":rId": response.response_id,
":la": response.llm_answer,
":lrj": response.llm_response_json,
":lpt": str(response.llm_prompt_timestamp),
":lrt": str(response.llm_response_timestamp),
":route": response.route,
":context": response.context,
},
)


def store_user_thanked_timestamp(ai_answer: LlmResponse):
# Updating response in DynamoDB
responses_table.update_item(
Key={"threadId": ai_answer.thread_id},
UpdateExpression="set userThankedTimestamp=:t",
Expand Down Expand Up @@ -333,12 +348,12 @@ def check_existing_call(caddy_message) -> Tuple[Dict[str, Any], bool]:

def send_to_llm(caddy_query: UserMessage, chat_client):
query = caddy_query.message

domain = caddy_query.user_email.split("@")[1]

chat_history = get_chat_history(caddy_query)

route_specific_augmentation = retrieve_route_specific_augmentation(query)
route_specific_augmentation, route = retrieve_route_specific_augmentation(query)

day_date_time = datetime.now(timezone("Europe/London")).strftime(
"%A %d %B %Y %H:%M"
Expand All @@ -348,7 +363,7 @@ def send_to_llm(caddy_query: UserMessage, chat_client):
office_regions = enrolment.get_office_coverage(office)

CADDY_PROMPT = PromptTemplate(
template=CADDY_PROMPT_TEMPLATE,
template=get_prompt("CORE_PROMPT"),
input_variables=["context", "question"],
partial_variables={
"route_specific_augmentation": route_specific_augmentation,
Expand Down Expand Up @@ -486,6 +501,8 @@ def send_to_llm(caddy_query: UserMessage, chat_client):
llm_prompt_timestamp=ai_prompt_timestamp,
llm_response_json=json.dumps(response_card),
llm_response_timestamp=ai_response_timestamp,
route=route or "no_route",
context=[doc_without_embeddings(doc) for doc in caddy_response["context"]],
)

store_response(llm_response)
Expand Down Expand Up @@ -535,8 +552,13 @@ def send_to_llm(caddy_query: UserMessage, chat_client):
store_approver_received_timestamp(supervision_event)


def doc_without_embeddings(doc):
doc_dict = doc.dict()
doc_dict.pop("state", None)
return doc_dict


def store_approver_received_timestamp(event: SupervisionEvent):
# Updating response in DynamoDB
responses_table.update_item(
Key={"threadId": event.thread_id},
UpdateExpression="set approverReceivedTimestamp=:t",
Expand All @@ -545,12 +567,12 @@ def store_approver_received_timestamp(event: SupervisionEvent):
)


def store_approver_event(approval_event: ApprovalEvent):
# Updating response in DynamoDB
def store_approver_event(thread_id: str, approval_event: ApprovalEvent):
responses_table.update_item(
Key={"threadId": str(approval_event.thread_id)},
UpdateExpression="set approverEmail=:email, approved=:approved, approvalTimestamp=:atime, userResponseTimestamp=:utime, supervisorMessage=:sMessage",
Key={"threadId": thread_id},
UpdateExpression="set responseId=:rId, approverEmail=:email, approved=:approved, approvalTimestamp=:atime, userResponseTimestamp=:utime, supervisorMessage=:sMessage",
ExpressionAttributeValues={
":rId": approval_event.response_id,
":email": approval_event.approver_email,
":approved": approval_event.approved,
":atime": str(approval_event.approval_timestamp),
Expand All @@ -559,3 +581,42 @@ def store_approver_event(approval_event: ApprovalEvent):
},
ReturnValues="UPDATED_NEW",
)


def temporary_teams_invoke(chat_client, query, event):
"""
Temporary solution for Teams integration
"""
route_specific_augmentation, _ = retrieve_route_specific_augmentation(query)

day_date_time = datetime.now(timezone("Europe/London")).strftime(
"%A %d %B %Y %H:%M"
)

office_regions = ["England"]

CADDY_PROMPT = PromptTemplate(
template=get_prompt("CORE_PROMPT"),
input_variables=["context", "question"],
partial_variables={
"route_specific_augmentation": route_specific_augmentation,
"day_date_time": day_date_time,
"office_regions": office_regions,
},
)

chain, ai_prompt_timestamp = build_chain(CADDY_PROMPT)

caddy_response = chain.invoke(
{
"input": query,
"chat_history": [],
}
)

_, caddy_response["answer"] = remove_role_played_responses(caddy_response["answer"])

chat_client.send_adviser_card(
event,
card=chat_client.messages.generate_response_card(caddy_response["answer"]),
)
4 changes: 3 additions & 1 deletion caddy_chatbot/src/caddy_core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Union, List, Any
from datetime import datetime
import uuid
import pydantic
Expand Down Expand Up @@ -35,6 +35,8 @@ class LlmResponse(pydantic.BaseModel):
llm_response_json: Union[pydantic.Json, None] = None
llm_prompt_timestamp: datetime
llm_response_timestamp: datetime
route: str
context: Union[List[Any], None]


class SupervisionEvent(pydantic.BaseModel):
Expand Down
Loading