feat: add IP geolocation tracking and include location in prompts
- Add GeoLite2-City.mmdb database for IP lookup - Create geoip.py module for IP location services - Extract client IP from requests and log location info - Pass location context to LLM prompts for enhanced responses
This commit is contained in:
@@ -1,10 +1,30 @@
|
||||
import { API_URL } from './config.js'
|
||||
|
||||
let cachedIP = null
|
||||
|
||||
async function getClientIP() {
|
||||
if (cachedIP) return cachedIP
|
||||
try {
|
||||
const controller = new AbortController()
|
||||
setTimeout(() => controller.abort(), 3000)
|
||||
const res = await fetch('https://api.ipify.org?format=json', { signal: controller.signal })
|
||||
const data = await res.json()
|
||||
cachedIP = data.ip
|
||||
return cachedIP
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchSuggestion(prefix, suffix, signal, apiUrl = API_URL) {
|
||||
try {
|
||||
const clientIP = await getClientIP()
|
||||
const headers = { 'Content-Type': 'application/json' }
|
||||
if (clientIP) headers['X-Client-IP'] = clientIP
|
||||
|
||||
const res = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers,
|
||||
body: JSON.stringify({ prefix, suffix, languageId: 'markdown' }),
|
||||
signal
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user