Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Michalsky committed Mar 26, 2024
2 parents 9c6f325 + 2cdb631 commit 4695505
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ examples/sales_agent_bedrock.ipynb

*.log
**.env
.env.fe
.DS_Store
**__pycache__
/scratch
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ services:
- ./frontend:/usr/src/app
container_name: frontend
environment:
- NEXT_PUBLIC_API_URL_OLD=http://localhost:8000
- NEXT_PUBLIC_API_URL=http://localhost:8000
env_file: # Added line for specifying an environment file
- .env.fe # Specifying the .env.fe file
ports:
- "3000:3000"
depends_on:
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export function ChatInterface() {
const fetchBotName = async () => {
console.log("REACT_APP_API_URL:", process.env.NEXT_PUBLIC_API_URL); // Added console logging for debugging
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/botname`);

const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/botname`, {
method: 'GET', // Method is optional since GET is the default value
headers: {
'Authorization': `Bearer ${process.env.NEXT_PUBLIC_AUTH_KEY}`
},
});
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
Expand Down Expand Up @@ -124,6 +128,7 @@ export function ChatInterface() {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.NEXT_PUBLIC_AUTH_KEY}`
},
body: JSON.stringify(requestData),
});
Expand Down
20 changes: 17 additions & 3 deletions run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
allow_headers=["*"],
)

from fastapi import Header, HTTPException, Depends

class AuthenticatedResponse(BaseModel):
message: str

def get_auth_key(authorization: str = Header(...)) -> None:
auth_key = os.getenv("AUTH_KEY")
if not auth_key:
raise HTTPException(status_code=500, detail="AUTH_KEY not configured")
expected_header = f"Bearer {auth_key}"
if authorization != expected_header:
raise HTTPException(status_code=401, detail="Unauthorized")

@app.get("/")
async def say_hello():
Expand All @@ -45,9 +57,10 @@ class MessageList(BaseModel):
sessions = {}


@app.get("/botname")
async def get_bot_name():
@app.get("/botname", response_model=None)
async def get_bot_name(authorization: str = Header(...)):
load_dotenv()
get_auth_key(authorization)
sales_api = SalesGPTAPI(
config_path=os.getenv("CONFIG_PATH", "examples/example_agent_setup.json"),
product_catalog=os.getenv(
Expand All @@ -61,7 +74,7 @@ async def get_bot_name():


@app.post("/chat")
async def chat_with_sales_agent(req: MessageList, stream: bool = Query(False)):
async def chat_with_sales_agent(req: MessageList, stream: bool = Query(False), authorization: str = Header(...)):
"""
Handles chat interactions with the sales agent.
Expand All @@ -78,6 +91,7 @@ async def chat_with_sales_agent(req: MessageList, stream: bool = Query(False)):
Streaming functionality is planned but not yet available. The current implementation only supports synchronous responses.
"""
sales_api = None
get_auth_key(authorization)
# print(f"Received request: {req}")
if req.session_id in sessions:
print("Session is found!")
Expand Down

0 comments on commit 4695505

Please sign in to comment.