diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 5b9d1375..d0153864 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -31,6 +31,22 @@ }); } + let region = null; + let city = null; + let countryName = null; + + fetch("https://ipapi.co/json") + .then(response => response.json()) + .then(data => { + region = data.region; + city = data.city; + countryName = data.country_name; + }) + .catch(err => { + console.log(err); + return; + }); + function formatDate(date) { // Format date in HH:MM, DD MMM YYYY format let time_string = date.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit', hour12: false }); @@ -337,7 +353,7 @@ // Generate backend API URL to execute query - let url = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}`; + let url = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}®ion=${region}&city=${city}&country=${countryName}`; const khojToken = await window.tokenAPI.getToken(); const headers = { 'Authorization': `Bearer ${khojToken}` }; diff --git a/src/interface/obsidian/src/chat_modal.ts b/src/interface/obsidian/src/chat_modal.ts index 6ad88b69..14ec48cb 100644 --- a/src/interface/obsidian/src/chat_modal.ts +++ b/src/interface/obsidian/src/chat_modal.ts @@ -10,6 +10,9 @@ export interface ChatJsonResult { export class KhojChatModal extends Modal { result: string; setting: KhojSetting; + region: string; + city: string; + countryName: string; constructor(app: App, setting: KhojSetting) { super(app); @@ -17,6 +20,19 @@ export class KhojChatModal extends Modal { // Register Modal Keybindings to send user message this.scope.register([], 'Enter', async () => { await this.chat() }); + + + fetch("https://ipapi.co/json") + .then(response => response.json()) + .then(data => { + this.region = data.region; + this.city = data.city; + this.countryName = data.country_name; + }) + .catch(err => { + console.log(err); + return; + }); } async chat() { @@ -354,7 +370,7 @@ export class KhojChatModal extends Modal { // Get chat response from Khoj backend let encodedQuery = encodeURIComponent(query); - let chatUrl = `${this.setting.khojUrl}/api/chat?q=${encodedQuery}&n=${this.setting.resultsCount}&client=obsidian&stream=true`; + let chatUrl = `${this.setting.khojUrl}/api/chat?q=${encodedQuery}&n=${this.setting.resultsCount}&client=obsidian&stream=true®ion=${this.region}&city=${this.city}&country=${this.countryName}`; let responseElement = this.createKhojResponseDiv(); // Temporary status message to indicate that Khoj is thinking diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index a1f0a0a2..28aed33f 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -173,6 +173,24 @@ async def create_user_by_google_token(token: dict) -> KhojUser: return user +def set_user_name(user: KhojUser, first_name: str, last_name: str) -> KhojUser: + user.first_name = first_name + user.last_name = last_name + user.save() + return user + + +def get_user_name(user: KhojUser): + full_name = user.get_full_name() + if not is_none_or_empty(full_name): + return full_name + google_profile: GoogleUser = GoogleUser.objects.filter(user=user).first() + if google_profile: + return google_profile.given_name + + return None + + def get_user_subscription(email: str) -> Optional[Subscription]: return Subscription.objects.filter(user__email=email).first() @@ -291,6 +309,17 @@ def delete_user_requests(window: timedelta = timedelta(days=1)): return UserRequests.objects.filter(created_at__lte=datetime.now(tz=timezone.utc) - window).delete() +async def aget_user_name(user: KhojUser): + full_name = user.get_full_name() + if not is_none_or_empty(full_name): + return full_name + google_profile: GoogleUser = await GoogleUser.objects.filter(user=user).afirst() + if google_profile: + return google_profile.given_name + + return None + + async def set_text_content_config(user: KhojUser, object: Type[models.Model], updated_config): deduped_files = list(set(updated_config.input_files)) if updated_config.input_files else None deduped_filters = list(set(updated_config.input_filter)) if updated_config.input_filter else None diff --git a/src/khoj/interface/web/assets/icons/user-silhouette.svg b/src/khoj/interface/web/assets/icons/user-silhouette.svg new file mode 100644 index 00000000..70a58f51 --- /dev/null +++ b/src/khoj/interface/web/assets/icons/user-silhouette.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/khoj/interface/web/base_config.html b/src/khoj/interface/web/base_config.html index eff69fb6..4126ad71 100644 --- a/src/khoj/interface/web/base_config.html +++ b/src/khoj/interface/web/base_config.html @@ -103,7 +103,7 @@ .section-title { margin: 0; - padding: 0 0 16px 0; + padding: 12px 0 16px 0; font-size: 32; font-weight: normal; } @@ -361,6 +361,11 @@ margin-right: 8px; } + input#profile_given_name { + width: 100%; + margin: 0; + } + @media screen and (max-width: 700px) { .section-cards { grid-template-columns: 1fr; diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index c6896e04..eb5a00ab 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -43,6 +43,22 @@ To get started, just start typing below. You can also type / to see a list of co }); } + let region = null; + let city = null; + let countryName = null; + + fetch("https://ipapi.co/json") + .then(response => response.json()) + .then(data => { + region = data.region; + city = data.city; + countryName = data.country_name; + }) + .catch(err => { + console.log(err); + return; + }); + function formatDate(date) { // Format date in HH:MM, DD MMM YYYY format let time_string = date.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit', hour12: false }); @@ -345,7 +361,7 @@ To get started, just start typing below. You can also type / to see a list of co } // Generate backend API URL to execute query - let url = `/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}`; + let url = `/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}®ion=${region}&city=${city}&country=${countryName}`; let new_response = document.createElement("div"); new_response.classList.add("chat-message", "khoj"); diff --git a/src/khoj/interface/web/config.html b/src/khoj/interface/web/config.html index d9829628..54a4de41 100644 --- a/src/khoj/interface/web/config.html +++ b/src/khoj/interface/web/config.html @@ -3,6 +3,25 @@
+

Profile

+
+
+
+ Profile Name +

+ Name +

+
+
+ +
+
+ +
+
+

Content