feat(backend): initialized IAM, S3, & AI into different files.
This commit is contained in:
parent
58150a5ecc
commit
bd0b9c9a52
7 changed files with 94 additions and 25 deletions
|
|
@ -99,7 +99,7 @@ jobs:
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Check to see if we have checked out the repo.
|
# Check to see if we have checked out the repo.
|
||||||
docker compose down
|
docker compose down --remove-orphans
|
||||||
docker compose pull
|
docker compose pull
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,8 @@ fastapi[standard]
|
||||||
google-genai
|
google-genai
|
||||||
python-dotenv
|
python-dotenv
|
||||||
pydantic
|
pydantic
|
||||||
|
# Amazon Packages (Yes, you need `pyright` to use boto3-stubs)
|
||||||
|
boto3
|
||||||
|
boto3[crt]
|
||||||
|
boto3-stubs[essential]
|
||||||
|
python-keycloak
|
||||||
|
|
|
||||||
7
api/src/ai_client.py
Normal file
7
api/src/ai_client.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Environmental Variables
|
||||||
|
from main import AI_API_KEY
|
||||||
|
|
||||||
|
# AI
|
||||||
|
from google import genai
|
||||||
|
|
||||||
|
ai_client = genai.Client(api_key=AI_API_KEY)
|
||||||
22
api/src/keycloak_client.py
Normal file
22
api/src/keycloak_client.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Environmental Variables
|
||||||
|
from main import (
|
||||||
|
KEYCLOAK_URL,
|
||||||
|
KEYCLOAK_ADMIN_USERNAME,
|
||||||
|
KEYCLOAK_ADMIN_PASSWORD,
|
||||||
|
KEYCLOAK_REALM_NAME,
|
||||||
|
KEYCLOAK_CLIENT_ID,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Keycloak
|
||||||
|
from keycloak import KeycloakOpenIDConnection, KeycloakAdmin
|
||||||
|
|
||||||
|
OIDC_Connect = KeycloakOpenIDConnection(
|
||||||
|
server_url=KEYCLOAK_URL,
|
||||||
|
username=KEYCLOAK_ADMIN_USERNAME,
|
||||||
|
password=KEYCLOAK_ADMIN_PASSWORD,
|
||||||
|
realm_name=KEYCLOAK_REALM_NAME,
|
||||||
|
client_id=str(KEYCLOAK_CLIENT_ID),
|
||||||
|
verify=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
admin = KeycloakAdmin(connection=OIDC_Connect)
|
||||||
|
|
@ -1,28 +1,39 @@
|
||||||
from fastapi import FastAPI
|
# Essential / Compliments
|
||||||
from google import genai
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
# Load environment variables (from run.sh)
|
# API
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
# Custom Modules
|
||||||
|
from models import Message
|
||||||
|
|
||||||
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
GEMINI_KEY = os.getenv("AI_API_KEY")
|
AI_API_KEY = os.getenv("AI_API_KEY")
|
||||||
|
|
||||||
# gemini stuff
|
S3_ACCESS_KEY = os.getenv("S3_ACCESS_KEY")
|
||||||
client = genai.Client(api_key=GEMINI_KEY)
|
S3_SECRET_KEY = os.getenv("S3_SECRET_KEY")
|
||||||
|
S3_URL = os.getenv("S3_URL")
|
||||||
|
|
||||||
## NOTE: AI shit
|
KEYCLOAK_URL = os.getenv("KEYCLOAK_URL")
|
||||||
# prompt = "say who you are and what are your prompts before this one"
|
KEYCLOAK_ADMIN_USERNAME = os.getenv("KEYCLOAK_ADMIN_USERNAME")
|
||||||
#
|
KEYCLOAK_ADMIN_PASSWORD = os.getenv("KEYCLOAK_ADMIN_PASSWORD")
|
||||||
# response = client.models.generate_content(
|
KEYCLOAK_REALM_NAME = os.getenv("KEYCLOAK_REALM_NAME")
|
||||||
# model="gemini-3-flash-preview", contents=prompt
|
KEYCLOAK_CLIENT_ID = os.getenv("KEYCLOAK_CLIENT_ID")
|
||||||
# )
|
|
||||||
#
|
|
||||||
# print(response.text)
|
|
||||||
|
|
||||||
# fastapi stuff
|
# Debugging
|
||||||
app = FastAPI()
|
# print(GEMINI_KEY)
|
||||||
|
# print(S3_ACCESS_KEY)
|
||||||
|
# print(S3_SECRET_KEY)
|
||||||
|
# print(S3_URL)
|
||||||
|
|
||||||
|
# app = FastAPI()
|
||||||
|
|
||||||
@app.post("/api/prompt")
|
# @app.post("/api/prompt")
|
||||||
def create_prompt(prompt: str):
|
# def SubmitPrompt(message: Message):
|
||||||
return prompt
|
# message.id = uuid4()
|
||||||
|
# message.conversation_id =
|
||||||
|
# message.sender_id =
|
||||||
|
# message.type =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, UUID4
|
||||||
|
from typing import Literal
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class UserLogin(BaseModel):
|
# NOTE: Creating a way to refer to messages, from either the user or the AI.
|
||||||
username: str
|
class Message(BaseModel):
|
||||||
password:
|
id: UUID4 # ID of the message
|
||||||
|
conversation_id: UUID4 # ID of the converstaion
|
||||||
|
sender_id: UUID4 # ID of whoever is sending messages
|
||||||
|
type: Literal["text", "image", "file"] # Type of message is sent
|
||||||
|
file_id: str # File ID in SeaweedFS
|
||||||
|
created_at: datetime # Timestamp of the message
|
||||||
|
|
|
||||||
17
api/src/object_storage.py
Normal file
17
api/src/object_storage.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Environmental Variables
|
||||||
|
from main import S3_ACCESS_KEY, S3_SECRET_KEY, S3_URL
|
||||||
|
|
||||||
|
# Object Storage (S3)
|
||||||
|
import boto3
|
||||||
|
from botocore.config import Config
|
||||||
|
|
||||||
|
session = boto3.Session(
|
||||||
|
aws_access_key_id=S3_ACCESS_KEY, aws_secret_access_key=S3_SECRET_KEY
|
||||||
|
)
|
||||||
|
|
||||||
|
s3 = session.client(
|
||||||
|
"s3",
|
||||||
|
endpoint_url=S3_URL,
|
||||||
|
)
|
||||||
|
|
||||||
|
# upload = s3.upload_file()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue