Skip to content

Commit

Permalink
Fix secrets and build stuff in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Dec 9, 2024
1 parent 8381943 commit a38842d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 91 deletions.
5 changes: 1 addition & 4 deletions chat/src/event_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os
import json

from dataclasses import dataclass, field

from langchain_core.prompts import ChatPromptTemplate

from typing import List
from handlers.streaming_socket_callback_handler import StreamingSocketCallbackHandler
from helpers.apitoken import ApiToken
from helpers.prompts import document_template, prompt_template
from helpers.prompts import prompt_template
from websocket import Websocket

CHAIN_TYPE = "stuff"
Expand Down
4 changes: 3 additions & 1 deletion chat/src/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def load_secrets():
SecretsPath = os.getenv('SECRETS_PATH')
EnvironmentMap = [
['API_TOKEN_SECRET', 'dcapi', 'api_token_secret'],
['OPENSEARCH_ENDPOINT', 'index', 'endpoint'],
['OPENSEARCH_MODEL_ID', 'index', 'embedding_model'],
['AZURE_OPENAI_API_KEY', 'azure_openai', 'api_key'],
Expand All @@ -15,7 +16,8 @@ def load_secrets():
client = boto3.client("secretsmanager")
response = client.batch_get_secret_value(SecretIdList=[
f'{SecretsPath}/infrastructure/index',
f'{SecretsPath}/infrastructure/azure_openai'
f'{SecretsPath}/infrastructure/azure_openai',
f'{SecretsPath}/config/dcapi'
])

secrets = {
Expand Down
52 changes: 24 additions & 28 deletions chat/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Websocket Chat API for dc-api-v2
Parameters:
ApiTokenSecret:
ApiTokenName:
Type: String
Description: Secret Key for Encrypting JWTs (must match IIIF server)
AzureOpenaiApiKey:
Type: String
Description: OpenAI API Key
Description: Name of the jwt that DC API issues
EnvironmentPrefix:
Type: String
Description: Prefix for Index names
Expand Down Expand Up @@ -178,34 +175,33 @@ Resources:
Action: lambda:InvokeFunction
FunctionName: !Ref ChatFunction
Principal: apigateway.amazonaws.com
ChatDependencies:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName:
Fn::Sub: "${AWS::StackName}-dependencies"
Description: Dependencies for streaming chat function
ContentUri: ./dependencies
CompatibleRuntimes:
- python3.12
LicenseInfo: "Apache-2.0"
Metadata:
BuildMethod: python3.12
#* ChatDependencies:
#* Type: AWS::Serverless::LayerVersion
#* Properties:
#* LayerName:
#* Fn::Sub: "${AWS::StackName}-dependencies"
#* Description: Dependencies for streaming chat function
#* ContentUri: ./dependencies
#* CompatibleRuntimes:
#* - python3.12
#* LicenseInfo: "Apache-2.0"
#* Metadata:
#* BuildMethod: python3.12
ChatFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Runtime: python3.12
Architectures:
- x86_64
Layers:
- !Ref ChatDependencies
#* Layers:
#* - !Ref ChatDependencies
MemorySize: 1024
Handler: handlers/chat.handler
Timeout: 300
Environment:
Variables:
API_TOKEN_SECRET: !Ref ApiTokenSecret
AZURE_OPENAI_API_KEY: !Ref AzureOpenaiApiKey
API_TOKEN_NAME: !Ref ApiTokenName
ENV_PREFIX: !Ref EnvironmentPrefix
HONEYBADGER_API_KEY: !Ref HoneybadgerApiKey
HONEYBADGER_ENVIRONMENT: !Ref HoneybadgerEnv
Expand All @@ -232,23 +228,23 @@ Resources:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Sub "${ChatMetricsLog.Arn}:*"
Metadata:
BuildMethod: nodejs20.x
#* Metadata:
#* BuildMethod: nodejs20.x
ChatSyncFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Runtime: python3.12
Architectures:
- x86_64
Layers:
- !Ref ChatDependencies
#* Layers:
#* - !Ref ChatDependencies
MemorySize: 1024
Handler: handlers/chat_sync.handler
Timeout: 300
Environment:
Variables:
API_TOKEN_SECRET: !Ref ApiTokenSecret
API_TOKEN_NAME: !Ref ApiTokenName
ENV_PREFIX: !Ref EnvironmentPrefix
HONEYBADGER_API_KEY: !Ref HoneybadgerApiKey
HONEYBADGER_ENVIRONMENT: !Ref HoneybadgerEnv
Expand All @@ -271,8 +267,8 @@ Resources:
# - logs:CreateLogStream
# - logs:PutLogEvents
# Resource: !Sub "${ChatMetricsLog.Arn}:*"
Metadata:
BuildMethod: nodejs20.x
#* Metadata:
#* BuildMethod: nodejs20.x
ChatMetricsLog:
Type: AWS::Logs::LogGroup
Properties:
Expand Down
Loading

0 comments on commit a38842d

Please sign in to comment.