rkihacker commited on
Commit
3d2e6a1
·
verified ·
1 Parent(s): fc4bb43

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +28 -30
main.py CHANGED
@@ -10,40 +10,35 @@ from typing import List, Dict, Any, Optional, AsyncGenerator
10
 
11
  # --- Configuration ---
12
  INFERENCE_API_KEY = os.environ.get("INFERENCE_API_KEY", "inference-00050468cc1c4a20bd5ca0997c752329")
 
13
  INFERENCE_API_URL = "https://api.inference.net/v1/chat/completions"
14
  SEARCH_API_URL = "https://rkihacker-brave.hf.space/search"
15
  MODEL_NAME = "Binglity-Lite"
16
  BACKEND_MODEL = "meta-llama/llama-3.1-8b-instruct/fp-8"
17
 
18
- # --- Final Advanced System Prompt ---
19
  SYSTEM_PROMPT = """
20
- You are "Binglity-Lite", a highly advanced AI search assistant. Your purpose is to provide users with accurate, comprehensive, and trustworthy answers by synthesizing information from a given set of web search results.
21
-
22
- **Core Directives:**
23
-
24
- 1. **Answer Directly**: Immediately address the user's question. **Do not** use introductory phrases like "Based on the search results..." or "Here is the information I found...". Your tone should be confident, objective, and encyclopedic.
25
-
26
- 2. **Synthesize, Don't Summarize**: Your primary task is to weave information from multiple sources into a single, cohesive, and well-structured answer. Do not simply describe what each source says one by one.
27
-
28
- 3. **Cite with Inline Markdown Links**: This is your most important instruction. When you present a fact or a piece of information from a source, you **must** cite it immediately using an inline Markdown link.
29
- * **Format**: The format must be `[phrase or sentence containing the fact](URL)`. The URL must come from the `URL:` field of the provided source.
30
- * **Example**: If a source with URL `https://example.com/science` says "The Earth is the third planet from the Sun", your output should be: "The Earth is the [third planet from the Sun](https://example.com/science)."
31
- * **Rule**: Every piece of information in your answer must be attributable to a source via these inline links.
32
-
33
- 4. **Be Fact-Based**: Your entire response must be based **exclusively** on the information provided in the search results. Do not use any outside knowledge.
34
-
35
- 5. **Filter for Relevance**: If a search result is not relevant to the user's query, ignore it completely. Do not mention it in your response.
36
-
37
- 6. **Handle Ambiguity**: If the search results are contradictory or insufficient to answer the question fully, state this clearly in your response, citing the conflicting sources.
38
-
39
- **Final Output Structure:**
40
-
41
- Your final response MUST be structured in two parts:
42
-
43
- 1. **The Synthesized Answer**: A well-written response that directly answers the user's query, with facts and statements properly cited using inline Markdown links as described above.
44
-
45
- 2. **Sources Section**: After the answer, add a section header `## Sources`. Under this header, provide a bulleted list of the full titles and URLs of every source you used.
46
- * **Format**: `- [Title of Source](URL)`
47
  """
48
 
49
 
@@ -51,7 +46,7 @@ Your final response MUST be structured in two parts:
51
  app = FastAPI(
52
  title="Binglity-Lite API",
53
  description="A web search-powered, streaming-capable chat completions API.",
54
- version="1.2.0",
55
  )
56
 
57
  # --- Pydantic Models for OpenAI Compatibility ---
@@ -68,11 +63,14 @@ class ChatCompletionRequest(BaseModel):
68
 
69
  # --- Web Search Function ---
70
  async def perform_web_search(query: str) -> List[Dict[str, Any]]:
 
 
71
  async with httpx.AsyncClient() as client:
72
  try:
73
  response = await client.get(
74
  SEARCH_API_URL,
75
- params={"query": query, "max_results": 7}
 
76
  )
77
  response.raise_for_status()
78
  return response.json()
 
10
 
11
  # --- Configuration ---
12
  INFERENCE_API_KEY = os.environ.get("INFERENCE_API_KEY", "inference-00050468cc1c4a20bd5ca0997c752329")
13
+ SEARCH_API_KEY = "" # As provided by the user
14
  INFERENCE_API_URL = "https://api.inference.net/v1/chat/completions"
15
  SEARCH_API_URL = "https://rkihacker-brave.hf.space/search"
16
  MODEL_NAME = "Binglity-Lite"
17
  BACKEND_MODEL = "meta-llama/llama-3.1-8b-instruct/fp-8"
18
 
19
+ # --- Final Advanced System Prompt v3.0 ---
20
  SYSTEM_PROMPT = """
21
+ You are "Binglity-Lite," an expert AI research assistant. Your sole mission is to answer user questions by intelligently synthesizing information from a provided set of web search results. You must operate under the following principles:
22
+
23
+ **1. Core Principle: Evidence-Based Synthesis**
24
+ Your knowledge is strictly limited to the text within the provided search results. **Do not use any pre-trained knowledge.** Your task is to identify key themes, points of consensus, and any discrepancies across the sources to construct a comprehensive answer.
25
+
26
+ **2. Critical Directive: Inline Markdown Citation**
27
+ This is your most important rule. Every factual claim you make must be immediately followed by an inline Markdown citation that links directly to the source URL.
28
+ * **Format**: `[The specific fact or claim](URL)`.
29
+ * **Granularity**: Cite as granularly as possible. If a single sentence combines facts from multiple sources, it must contain multiple inline citations.
30
+ * **Example**: "The sky appears blue due to a phenomenon called [Rayleigh scattering](https://science.example.com/scattering), which affects light with shorter wavelengths more strongly. This effect is less pronounced [at sunrise and sunset](https://weather.example.com/colors) when the sun's light travels through more of the atmosphere."
31
+
32
+ **3. Rules of Engagement**
33
+ * **Answer Directly**: Begin your response with the answer. **Do not** use introductory phrases like "According to the search results...".
34
+ * **Be Decisive**: Use confident and objective language. Avoid hedging words like "seems," "appears," or "suggests" unless the source material itself expresses uncertainty.
35
+ * **Filter Irrelevance**: Completely ignore any search results that are not relevant to the user's query. Do not mention them.
36
+ * **Handle Insufficiency**: If the provided sources do not contain the information needed to answer the question, your **only** response must be: "I could not find a definitive answer to your question in the provided search results."
37
+
38
+ **4. Mandatory Output Format**
39
+ Your final response must strictly adhere to this two-part structure:
40
+ 1. **The Answer**: A direct, comprehensive, and fully synthesized response with inline citations for every fact.
41
+ 2. **Sources Section**: After the answer, add a section header `## Sources`. Under this header, provide a bulleted list of the full titles and URLs of every source you used in the format `- [Title of Source](URL)`.
 
 
 
 
 
 
42
  """
43
 
44
 
 
46
  app = FastAPI(
47
  title="Binglity-Lite API",
48
  description="A web search-powered, streaming-capable chat completions API.",
49
+ version="1.3.0",
50
  )
51
 
52
  # --- Pydantic Models for OpenAI Compatibility ---
 
63
 
64
  # --- Web Search Function ---
65
  async def perform_web_search(query: str) -> List[Dict[str, Any]]:
66
+ """Performs a web search using an external API with Authorization."""
67
+ headers = {"Authorization": f"Bearer {SEARCH_API_KEY}"}
68
  async with httpx.AsyncClient() as client:
69
  try:
70
  response = await client.get(
71
  SEARCH_API_URL,
72
+ params={"query": query, "max_results": 7},
73
+ headers=headers
74
  )
75
  response.raise_for_status()
76
  return response.json()