Skip to content

Commit

Permalink
feat: send profile data back to the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ydennisy committed May 27, 2024
1 parent 8a84809 commit 3660be2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
11 changes: 11 additions & 0 deletions backend/app/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
10 changes: 7 additions & 3 deletions backend/app/llm.py
Original file line number Diff line number Diff line change
@@ -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."
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
13 changes: 11 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
18 changes: 15 additions & 3 deletions frontend/pages/profile.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<script setup lang="ts">
interface Profile {
name: string;
id: string;
email: string;
app_email_alias: string;
}
const profile = ref<Profile>({
name: '',
id: '',
email: '',
app_email_alias: '',
});
const config = useRuntimeConfig();
Expand All @@ -31,5 +35,13 @@ onMounted(async () => {
</script>

<template>
<p>{{ profile.name }}</p>
<div class="p-4">
<h1 class="text-2xl font-bold mb-4 text-slate-700">Profile</h1>
<p class="text-lg mb-2 text-slate-800">
<strong>Email:</strong> {{ profile.email }}
</p>
<p class="text-lg text-slate-800">
<strong>App Email Alias:</strong> {{ profile.app_email_alias }}
</p>
</div>
</template>

0 comments on commit 3660be2

Please sign in to comment.