Skip to content

Commit

Permalink
chore(versioning): versioning and linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 13, 2024
1 parent cfbf3fc commit 3115fb6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
42 changes: 31 additions & 11 deletions arcan/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
from fastapi import Depends, FastAPI, Form, HTTPException, Request, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse

# %%
from fastapi.security import (HTTPAuthorizationCredentials, HTTPBearer,
OAuth2PasswordBearer, OAuth2PasswordRequestForm)
from fastapi.security import (
HTTPAuthorizationCredentials,
HTTPBearer,
OAuth2PasswordBearer,
OAuth2PasswordRequestForm,
)
from langchain_core.messages import AIMessage, FunctionMessage, HumanMessage
from langserve import add_routes
from langserve.pydantic_v1 import BaseModel, Field
Expand All @@ -22,14 +27,25 @@
from arcan.api.datamodel import get_db, get_db_context
from arcan.api.datamodel.chat_history import ChatHistory
from arcan.api.datamodel.conversation import Conversation
from arcan.api.datamodel.user import (ACCESS_TOKEN_EXPIRE_MINUTES, TokenModel,
User, UserInDB, UserModel,
UserRepository, UserService,
oauth2_scheme, pwd_context)
from arcan.api.datamodel.user import (
ACCESS_TOKEN_EXPIRE_MINUTES,
TokenModel,
User,
UserInDB,
UserModel,
UserRepository,
UserService,
oauth2_scheme,
pwd_context,
)
from arcan.api.session import ArcanSession, run_agent

# from arcan.api.session.auth import requires_auth
from arcan.spells.vector_search import (get_per_user_retriever,
per_req_config_modifier, pgVectorStore)
from arcan.spells.vector_search import (
get_per_user_retriever,
per_req_config_modifier,
pgVectorStore,
)

auth_scheme = HTTPBearer()

Expand Down Expand Up @@ -60,7 +76,6 @@ async def index():
return {"message": "Arcan is Running!"}



# %%


Expand Down Expand Up @@ -168,12 +183,17 @@ async def read_users_me(
enabled_endpoints=["invoke"],
)

#%%
# %%


# @requires_auth
@app.get("/api/chat")
async def chat(user_id: str, query: str, current_user: Annotated[UserModel, Depends(get_current_active_user_from_request)], db: Session = Depends(get_db)):
async def chat(
user_id: str,
query: str,
current_user: Annotated[UserModel, Depends(get_current_active_user_from_request)],
db: Session = Depends(get_db),
):
arcan_session = ArcanSession(db)
response = run_agent(session=arcan_session, user_id=current_user, query=query)
return {"response": response}
Expand Down
4 changes: 3 additions & 1 deletion arcan/api/datamodel/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def create_access_token(self, data: dict, expires_delta: timedelta | None = None
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt

async def get_current_user(self, token: Annotated[str, Depends(oauth2_scheme)]) -> str:
async def get_current_user(
self, token: Annotated[str, Depends(oauth2_scheme)]
) -> str:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
Expand Down

0 comments on commit 3115fb6

Please sign in to comment.