Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Cleanup env usage #11

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 7 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Example of .env file. Check out 1Password for the actual values.

NUR_API_HOST="common api web host"
NUR_API_HOST=localhost
NUR_API_PORT=8000

CONFLUENCE_BASE_URL="https://<namespace>.atlassian.net/"
CONFLUENCE_USER="[email protected]"
CONFLUENCE_API_TOKEN="api-token"
CONFLUENCE_API_TOKEN="???"

OPENAI_API_KEY="api-key"
OPENAI_ASSISTANT_ID_QA="assistant-id"
OPENAI_ASSISTANT_ID_KNOWLEDGE_GAP="rag-assistant-id"
OPENAI_API_KEY="sk-???"
OPENAI_ASSISTANT_ID_QA="asst_???"
OPENAI_ASSISTANT_ID_KNOWLEDGE_GAP="asst_???"

SLACK_APP_TOKEN="app-token"
SLACK_BOT_TOKEN="bot-token"
SLACK_USER_TOKEN="user-token"
SLACK_APP_TOKEN="xapp-???"
SLACK_BOT_TOKEN="xoxb-???"
6 changes: 1 addition & 5 deletions api/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# ./api/endpoint.py
import os
from fastapi import FastAPI
import uvicorn
from openai import OpenAI
Expand All @@ -11,9 +10,6 @@
from configuration import api_host, api_port
from interactions.vectorize_and_store import vectorize_interaction_and_store_in_db

host = os.environ.get("NUR_API_HOST", api_host)
port = os.environ.get("NUR_API_PORT", api_port)

processor = FastAPI()

client = OpenAI(api_key=oai_api_key)
Expand Down Expand Up @@ -93,7 +89,7 @@ def create_interaction_embeds(InteractionEmbedRequest: InteractionEmbedRequest):

def main():
"""Entry point for starting the FastAPI application."""
uvicorn.run("api.endpoint:processor", host=host, port=int(port), reload=True)
uvicorn.run("api.endpoint:processor", host=api_host, port=api_port, reload=True)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_project_root() -> str:
# Configuration for the Nur Services API
# get the values from the environment variables if available or use the default values
api_host = os.environ.get("NUR_API_HOST", "localhost")
api_port = os.environ.get("NUR_API_PORT", "8000")
api_port = int(os.environ.get("NUR_API_PORT", "8000"))

# Name of the vector collection
pages_collection_name = "pages"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from database.page_manager import get_page_ids_missing_embeds


host = os.environ.get("NUR_API_HOST", api_host)
port = os.environ.get("NUR_API_PORT", api_port)

# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

Expand Down Expand Up @@ -96,7 +93,7 @@ def process_page(self, page_id, page_content_map):


def submit_embedding_creation_request(page_id):
endpoint_url = f'http://{host}:{port}/api/v1/embeds'
endpoint_url = f'http://{api_host}:{api_port}/api/v1/embeds'
headers = {"Content-Type": "application/json"}
payload = {"page_id": page_id}

Expand Down
6 changes: 1 addition & 5 deletions interactions/vectorize_and_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
from configuration import embedding_model_id
from configuration import api_host, api_port
import requests
import os

host = os.environ.get("NUR_API_HOST", api_host)
port = os.environ.get("NUR_API_PORT", api_port)


def get_qna_interactions_from_database():
Expand Down Expand Up @@ -130,7 +126,7 @@ def submit_create_interaction_embeds_request(interaction_id):
:return: None
"""

endpoint_url = f'http://{host}:{port}/api/v1/interaction_embeds'
endpoint_url = f'http://{api_host}:{api_port}/api/v1/interaction_embeds'
headers = {"Content-Type": "application/json"}
# The key here should be "interaction_id" as expected by the InteractionEmbedRequest model in the FastAPI endpoint
payload = {"interaction_id": interaction_id}
Expand Down
5 changes: 2 additions & 3 deletions secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ settings:
OPENAI_ASSISTANT_ID_KNOWLEDGE_GAP: ENC[AES256_GCM,data:FxuyGXRQrBLbfQKATWpvx2IEt9PnbL4NrGKJRJA=,iv:rdFKdsigSrMNBkBOsyO+CZo/ZitYeJOLKUBV7681yyI=,tag:Gvgbde1neisPTVYN5KntbA==,type:str]
SLACK_APP_TOKEN: ENC[AES256_GCM,data:ETykCin5OhzCQH61otJwYWcbOfxdgdCDk566NNpi0AsSyDLtfqsWImNvIdP4hvymetlpnkIlBXvt0rKTGL0NdAjaa97VNo0Nx2X596/uzdYlSvhAeYoyTjhNS9mMHLjNaA==,iv:NWqlVP7zQmDKCgJxZPh8r9kuW9Te4JqIDr2w2YCLcIM=,tag:MNunwFrC1dzfJuM1kFRPAg==,type:str]
SLACK_BOT_TOKEN: ENC[AES256_GCM,data:K0X9C4LMyKkmeSAQhp2qYBonRa6VieW8ck9gVtTCR40TkTrpBAgHf5SchkLDZimJbi5MpMEL,iv:0l1+PH1dM1mzY95WVIpL9zE4do0yWlyUOQQX/9Orvpk=,tag:klkz3BMD6qt9Huk7+bsYJQ==,type:str]
SLACK_USER_TOKEN: ENC[AES256_GCM,data:L0mZJ78T0PaVp8OkwnxwTlwPOGCPOz0bKMtEKK1fuqxnzdQ+1BsHgEM1XCwc2UqIMYrXkJCpYIH97rfuyJFVZKuzXgk8Wskg4LAZLw==,iv:LNU3Mwt7LfzIzERkHJqsqjjvg6MQjwrGkiqch44355w=,tag:0oVWrH2d/ElyKyklhgGrQQ==,type:str]
sops:
kms: []
gcp_kms:
Expand All @@ -19,8 +18,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2024-03-26T14:53:35Z"
mac: ENC[AES256_GCM,data:m86uEsTfQOyKc650WQP884d/w+/1jD3nATyQJ3n1J3yYIJxuyXtqW+DvQbv9hljbSZOYQx07NMk65FoaWVN+wCvrEd8qaNDsT5MtGqD6X4NM0qeI34c1NmKMucpjdnzOeHGdZCjwoANIwgAmMT5DnZ4nvWAk26IadzgJhJUHYnA=,iv:0jvrYvHdsC5FuaD0n8t88kkyCZ4lyk90fNuBn0q+IGM=,tag:xGcmWB2Pya5797/rqy156A==,type:str]
lastmodified: "2024-04-05T11:09:11Z"
mac: ENC[AES256_GCM,data:EcCVycn2kEHhBJlKDWOGpXZuGPDF7luRd4gbcvhJb4Bq4fzR8lgebsNP9xWEdEuoRb8ydURkeHb/8GHbuFyhi3nFRmsRa1ssBNyjdCXXI5WEzmSyD7JSKR0q9J1OepX62UTURVRl/XIknEd6qYcz6GibUuX565/UsZ807DcpuEg=,iv:lr55BRA9gqxuK4vBcTohhjgFycsbHN2qx862nvNfhcE=,tag:nCLw6J22unr8cANU9C87jg==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.8.1
9 changes: 2 additions & 7 deletions slack/channel_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
from slack_sdk.socket_mode import SocketModeClient
from configuration import api_host, api_port
import requests
import os
from slack.reaction_manager import process_checkmark_added_event, process_bookmark_added_event


host = os.environ.get("NUR_API_HOST", api_host)
port = os.environ.get("NUR_API_PORT", api_port)


class ChannelMessageHandler(SlackEventHandler):
"""Handles incoming messages from the channel and publishes questions and feedback to the persist queue"""

Expand Down Expand Up @@ -103,7 +98,7 @@ def handle(self, client: SocketModeClient, req: SocketModeRequest, web_client: W
# publish question event to the persist queue
try:
# Make an API call to publish the question
response = requests.post(f'http://{host}:{port}/api/v1/questions/', json=question_event)
response = requests.post(f'http://{api_host}:{api_port}/api/v1/questions/', json=question_event)
response.raise_for_status()
logging.info(f"Question event published: {question_event}")

Expand All @@ -125,7 +120,7 @@ def handle(self, client: SocketModeClient, req: SocketModeRequest, web_client: W
# publish feedback event to the persist queue
try:
# Make an API call to publish the feedback
response = requests.post(f'http://{host}:{port}/api/v1/feedback/', json=feedback_event)
response = requests.post(f'http://{api_host}:{api_port}/api/v1/feedback/', json=feedback_event)
response.raise_for_status()
logging.info(f"Feedback published: {feedback_event}")
except Exception as e:
Expand Down