diff --git a/backend/app/db.py b/backend/app/db.py index 17e57d2..0d86b1e 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -127,3 +127,14 @@ def get_user_id_by_email_alias(self, app_email_alias: str): if len(result.data) != 1: return None return result.data[0]["id"] + + def get_user_profile_by_id(self, user_id: str): + result = ( + self._client.table("users") + .select("id, email, app_email_alias") + .eq("id", user_id) + .execute() + ) + if len(result.data) != 1: + return None + return result.data[0] diff --git a/backend/app/llm.py b/backend/app/llm.py index 661251e..81104c7 100644 --- a/backend/app/llm.py +++ b/backend/app/llm.py @@ -1,10 +1,14 @@ import json +from enum import Enum from typing import List, Generator, Any from openai import OpenAI client = OpenAI() -MODEL_16K = "gpt-3.5-turbo-16k" + +class Models(Enum): + GPT_4o_LATEST = "gpt-4o" + PROMPT_TEMPLATE = ( "A question and context documents are provided below." @@ -45,7 +49,7 @@ def answer_with_context(chunks: List[dict], question: str) -> Generator[str, Any ] stream = client.chat.completions.create( messages=messages, - model=MODEL_16K, + model=Models.GPT_4o_LATEST.value, stream=True, temperature=0, ) @@ -74,7 +78,7 @@ def summarise_text(text: str) -> str: ] result = client.chat.completions.create( messages=messages, - model=MODEL_16K, + model=Models.GPT_4o_LATEST.value, temperature=0, ) return result.choices[0].message.content diff --git a/backend/app/main.py b/backend/app/main.py index 3057126..051d090 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -53,14 +53,14 @@ def get_search_route(q: str, user=Depends(get_current_user)): @app.get("/api/ask") -def get_ask_route(q: str, id: str = None, user=Depends(get_current_user)): +async def get_ask_route(q: str, id: str = None, user=Depends(get_current_user)): user_id = user.id usage_count = db.increment_usage_counter() if usage_count > 1000: # TODO: handle this client side! raise HTTPException(429) - query_emb = NodeEmbedder.embed(q) + query_emb = await NodeEmbedder.embed(q) if id: # TODO: check this node belongs to the user requesting it! node = db.get_text_node(id) @@ -152,3 +152,12 @@ async def post_index_route(request: Request): await indexing_service.index(urls, user_id) except Exception as ex: raise HTTPException(500) from ex + + +@app.get("/api/me") +async def get_profile_route(user=Depends(get_current_user)): + user_id = user.id + profile = db.get_user_profile_by_id(user_id) + if not profile: + raise HTTPException(404) + return profile diff --git a/frontend/pages/profile.vue b/frontend/pages/profile.vue index 62dab10..bea1b26 100644 --- a/frontend/pages/profile.vue +++ b/frontend/pages/profile.vue @@ -1,10 +1,14 @@