rkihacker commited on
Commit
47aabc6
·
verified ·
1 Parent(s): 3c9a1a6

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -6
main.py CHANGED
@@ -27,7 +27,7 @@ else:
27
  logger.info("LLM API Key loaded successfully.")
28
 
29
  # --- Constants & Headers ---
30
- SEARCH_API_URL = "https://search.privateinstance.com/api/text" # The new search provider
31
  LLM_API_URL = "https://api.typegpt.net/v1/chat/completions"
32
  LLM_MODEL = "gpt-4.1-mini"
33
  MAX_SOURCES_TO_PROCESS = 15
@@ -47,7 +47,7 @@ class DeepResearchRequest(BaseModel):
47
  app = FastAPI(
48
  title="AI Deep Research API",
49
  description="Provides robust, long-form, streaming deep research completions using the PrivateInstance Search API.",
50
- version="8.0.0" # Final Production Version with PrivateInstance API
51
  )
52
 
53
  # Enable CORS for all origins
@@ -70,13 +70,16 @@ async def call_privateinstance_search(session: aiohttp.ClientSession, query: str
70
  async with session.get(SEARCH_API_URL, params=params, timeout=15) as response:
71
  response.raise_for_status()
72
  data = await response.json()
73
- # The API might return results in a list directly or under a 'results' key.
74
  raw_results = data if isinstance(data, list) else data.get('results', [])
75
 
76
- # Map the API's response keys to our internal format
77
  results = [
78
- {'title': r.get('title'), 'link': r.get('url'), 'snippet': r.get('description')}
79
- for r in raw_results if r.get('url') and r.get('title') and r.get('description')
 
 
 
 
80
  ]
81
  logger.info(f"Found {len(results)} sources from PrivateInstance for: '{query}'")
82
  return results
 
27
  logger.info("LLM API Key loaded successfully.")
28
 
29
  # --- Constants & Headers ---
30
+ SEARCH_API_URL = "https://search.privateinstance.com/api/text"
31
  LLM_API_URL = "https://api.typegpt.net/v1/chat/completions"
32
  LLM_MODEL = "gpt-4.1-mini"
33
  MAX_SOURCES_TO_PROCESS = 15
 
47
  app = FastAPI(
48
  title="AI Deep Research API",
49
  description="Provides robust, long-form, streaming deep research completions using the PrivateInstance Search API.",
50
+ version="9.0.0" # Definitive Production Version
51
  )
52
 
53
  # Enable CORS for all origins
 
70
  async with session.get(SEARCH_API_URL, params=params, timeout=15) as response:
71
  response.raise_for_status()
72
  data = await response.json()
 
73
  raw_results = data if isinstance(data, list) else data.get('results', [])
74
 
75
+ # ***** THE DEFINITIVE FIX: Correctly map the API's response keys *****
76
  results = [
77
+ {
78
+ 'title': r.get('title'),
79
+ 'link': r.get('href'), # Use 'href' instead of 'url'
80
+ 'snippet': r.get('body') # Use 'body' instead of 'description'
81
+ }
82
+ for r in raw_results if r.get('href') and r.get('title') and r.get('body')
83
  ]
84
  logger.info(f"Found {len(results)} sources from PrivateInstance for: '{query}'")
85
  return results