devank2000 commited on
Commit
3366ea9
·
verified ·
1 Parent(s): 45b0535
README.md CHANGED
@@ -99,7 +99,7 @@ This system is provider-agnostic: the runnable app uses Groq by default, and the
99
  ### Groq (Application Default)
100
 
101
  Copy `project/.env.example` to `project/.env` and set `GROQ_API_KEY`.
102
- `GROQ_MODEL` defaults to `llama-3.3-70b-versatile`, with tool calling and
103
  streaming through `langchain-groq`. Embeddings still run locally; Groq is
104
  not used as an embedding service.
105
 
 
99
  ### Groq (Application Default)
100
 
101
  Copy `project/.env.example` to `project/.env` and set `GROQ_API_KEY`.
102
+ `GROQ_MODEL` defaults to `openai/gpt-oss-20b`, with tool calling and
103
  streaming through `langchain-groq`. Embeddings still run locally; Groq is
104
  not used as an embedding service.
105
 
project/.env.example CHANGED
@@ -1,7 +1,7 @@
1
  # Groq chat model (required). Never put this key in frontend code.
2
  # Get a key at https://console.groq.com/keys
3
  GROQ_API_KEY=
4
- GROQ_MODEL=llama-3.3-70b-versatile
5
 
6
  # MiniLM embeddings use ZeroGPU on HF and CPU locally.
7
  # Changing embeddings requires clearing and re-indexing existing documents.
 
1
  # Groq chat model (required). Never put this key in frontend code.
2
  # Get a key at https://console.groq.com/keys
3
  GROQ_API_KEY=
4
+ GROQ_MODEL=openai/gpt-oss-20b
5
 
6
  # MiniLM embeddings use ZeroGPU on HF and CPU locally.
7
  # Changing embeddings requires clearing and re-indexing existing documents.
project/README.md CHANGED
@@ -150,7 +150,7 @@ SPARSE_VECTOR_NAME = "sparse" # Named sparse vector field (BM25)
150
  # Default: single model configuration
151
  DENSE_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
152
  SPARSE_MODEL = "Qdrant/bm25"
153
- LLM_MODEL = os.environ.get("GROQ_MODEL", "llama-3.3-70b-versatile")
154
  JUDGE_MODEL = "ministral-3:3b-instruct-2512-q8_0"
155
  LLM_TEMPERATURE = 0 # 0 = deterministic, 1 = creative
156
  LLM_SEED = 42
@@ -369,7 +369,7 @@ ACTIVE_LLM_CONFIG = "google" # Switch to Gemini Pro
369
 
370
  | Provider | Environment Variable | Import Statement | Example Models |
371
  |----------|---------------------|------------------|----------------|
372
- | Groq | `GROQ_API_KEY` | `from langchain_groq import ChatGroq` | `llama-3.3-70b-versatile` |
373
  | OpenAI | `OPENAI_API_KEY` | `from langchain_openai import ChatOpenAI` | `gpt-5.2`, `gpt-5-mini` |
374
  | Anthropic | `ANTHROPIC_API_KEY` | `from langchain_anthropic import ChatAnthropic` | `claude-opus-4-6`, `claude-sonnet-4-6` |
375
  | Google | `GOOGLE_API_KEY` | `from langchain_google_genai import ChatGoogleGenerativeAI` | `gemini-2.5-pro`, `gemini-2.5-flash` |
@@ -662,12 +662,20 @@ Once running, open `http://localhost:7860`.
662
  `project` folder (including `project/requirements.txt`).
663
  Do not upload `.env`, `.venv`, local documents, or local database files.
664
  3. Under **Settings > Variables and secrets**, add `GROQ_API_KEY` as a
665
- **secret**, optionally `GROQ_MODEL` as a variable, and both authentication
 
666
  values as secrets if the Space is public.
667
  4. Wait for the build and first model download, then open the **App** tab.
668
  Upload a small Markdown/PDF file under **Documents**, click **Add Documents**,
669
  and ask a question under **Chat**.
670
 
 
 
 
 
 
 
 
671
  The app loads MiniLM on **CUDA** at startup when HF sets `SPACES_ZERO_GPU=true`.
672
  Dense embedding inference runs inside `@spaces.GPU(duration=30)`, both during
673
  document indexing and query retrieval. Only texts and embedding results cross
 
150
  # Default: single model configuration
151
  DENSE_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
152
  SPARSE_MODEL = "Qdrant/bm25"
153
+ LLM_MODEL = os.environ.get("GROQ_MODEL", "openai/gpt-oss-20b")
154
  JUDGE_MODEL = "ministral-3:3b-instruct-2512-q8_0"
155
  LLM_TEMPERATURE = 0 # 0 = deterministic, 1 = creative
156
  LLM_SEED = 42
 
369
 
370
  | Provider | Environment Variable | Import Statement | Example Models |
371
  |----------|---------------------|------------------|----------------|
372
+ | Groq | `GROQ_API_KEY` | `from langchain_groq import ChatGroq` | `openai/gpt-oss-20b` |
373
  | OpenAI | `OPENAI_API_KEY` | `from langchain_openai import ChatOpenAI` | `gpt-5.2`, `gpt-5-mini` |
374
  | Anthropic | `ANTHROPIC_API_KEY` | `from langchain_anthropic import ChatAnthropic` | `claude-opus-4-6`, `claude-sonnet-4-6` |
375
  | Google | `GOOGLE_API_KEY` | `from langchain_google_genai import ChatGoogleGenerativeAI` | `gemini-2.5-pro`, `gemini-2.5-flash` |
 
662
  `project` folder (including `project/requirements.txt`).
663
  Do not upload `.env`, `.venv`, local documents, or local database files.
664
  3. Under **Settings > Variables and secrets**, add `GROQ_API_KEY` as a
665
+ **secret**, set `GROQ_MODEL=openai/gpt-oss-20b` as a variable (or remove an
666
+ old override to use this default), and add both authentication
667
  values as secrets if the Space is public.
668
  4. Wait for the build and first model download, then open the **App** tab.
669
  Upload a small Markdown/PDF file under **Documents**, click **Add Documents**,
670
  and ask a question under **Chat**.
671
 
672
+ The public Gradio API is named `/chat`. Document-management callbacks are
673
+ UI-only (`api_visibility="private"`), so API clients do not select the file
674
+ upload callback when sending text. This is not per-user document isolation.
675
+ After a rebuild, hard-refresh open app tabs to discard stale event IDs and
676
+ queue sessions. A queue-stream 404 can mean that its session no longer exists;
677
+ it is not evidence of a missing document or a Groq failure.
678
+
679
  The app loads MiniLM on **CUDA** at startup when HF sets `SPACES_ZERO_GPU=true`.
680
  Dense embedding inference runs inside `@spaces.GPU(duration=30)`, both during
681
  document indexing and query retrieval. Only texts and embedding results cross
project/config.py CHANGED
@@ -15,7 +15,7 @@ SPARSE_VECTOR_NAME = "sparse"
15
  # --- Model Configuration ---
16
  DENSE_MODEL = os.environ.get("DENSE_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
17
  SPARSE_MODEL = "Qdrant/bm25"
18
- LLM_MODEL = os.environ.get("GROQ_MODEL", "llama-3.3-70b-versatile")
19
  JUDGE_MODEL = "ministral-3:3b-instruct-2512-q8_0"
20
  LLM_TEMPERATURE = 0
21
  LLM_SEED = 42
 
15
  # --- Model Configuration ---
16
  DENSE_MODEL = os.environ.get("DENSE_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
17
  SPARSE_MODEL = "Qdrant/bm25"
18
+ LLM_MODEL = os.environ.get("GROQ_MODEL", "openai/gpt-oss-20b")
19
  JUDGE_MODEL = "ministral-3:3b-instruct-2512-q8_0"
20
  LLM_TEMPERATURE = 0
21
  LLM_SEED = 42
project/db/dense_embeddings.py CHANGED
@@ -11,7 +11,7 @@ class DenseEmbeddings(Embeddings):
11
  model_name,
12
  device="cuda" if is_zero_gpu else "cpu",
13
  )
14
- dimension = model.get_sentence_embedding_dimension()
15
  if not isinstance(dimension, int) or dimension <= 0:
16
  raise ValueError(f"Cannot determine embedding dimension for '{model_name}'.")
17
  self.vector_size = dimension
 
11
  model_name,
12
  device="cuda" if is_zero_gpu else "cpu",
13
  )
14
+ dimension = model.get_embedding_dimension()
15
  if not isinstance(dimension, int) or dimension <= 0:
16
  raise ValueError(f"Cannot determine embedding dimension for '{model_name}'.")
17
  self.vector_size = dimension
project/ui/gradio_app.py CHANGED
@@ -42,15 +42,17 @@ def create_gradio_ui():
42
  return format_file_list()
43
 
44
  def chat_handler(msg, hist, thread_id):
 
45
  with rag_lock:
46
- yield from chat_interface.chat(msg, hist, thread_id)
 
47
 
48
  def clear_chat_handler(thread_id):
49
  with rag_lock:
50
  return chat_interface.clear_session(thread_id)
51
 
52
  with gr.Blocks(title="Document Chat") as demo:
53
- session_thread = gr.State(value=lambda: str(uuid.uuid4()))
54
  gr.Markdown(
55
  "# Document Chat\n"
56
  "Turn your documents into a conversation. Upload a PDF or Markdown file, "
@@ -88,9 +90,12 @@ def create_gradio_ui():
88
  refresh_btn = gr.Button("Refresh", size="md")
89
  clear_btn = gr.Button("Clear All", variant="stop", size="md")
90
 
91
- add_btn.click(upload_handler, [files_input], [files_input, file_list], show_progress="corner", concurrency_id="rag")
92
- refresh_btn.click(format_file_list, None, file_list)
93
- clear_btn.click(clear_handler, None, file_list, concurrency_id="rag")
 
 
 
94
 
95
  with gr.Tab("Chat"):
96
  chatbot = gr.Chatbot(
@@ -100,7 +105,10 @@ def create_gradio_ui():
100
  layout="bubble",
101
  elem_id="document-chat",
102
  )
103
- chatbot.clear(clear_chat_handler, [session_thread], [session_thread], concurrency_id="rag")
 
 
 
104
 
105
  gr.ChatInterface(
106
  fn=chat_handler,
@@ -111,7 +119,9 @@ def create_gradio_ui():
111
  elem_id="question-input",
112
  ),
113
  additional_inputs=[session_thread],
 
114
  concurrency_limit=1,
 
115
  )
116
  gr.Markdown(
117
  "Documents are shared with everyone who can access this app. "
 
42
  return format_file_list()
43
 
44
  def chat_handler(msg, hist, thread_id):
45
+ thread_id = thread_id or str(uuid.uuid4())
46
  with rag_lock:
47
+ for chunk in chat_interface.chat(msg, hist, thread_id):
48
+ yield chunk, thread_id
49
 
50
  def clear_chat_handler(thread_id):
51
  with rag_lock:
52
  return chat_interface.clear_session(thread_id)
53
 
54
  with gr.Blocks(title="Document Chat") as demo:
55
+ session_thread = gr.State(value=None)
56
  gr.Markdown(
57
  "# Document Chat\n"
58
  "Turn your documents into a conversation. Upload a PDF or Markdown file, "
 
90
  refresh_btn = gr.Button("Refresh", size="md")
91
  clear_btn = gr.Button("Clear All", variant="stop", size="md")
92
 
93
+ add_btn.click(
94
+ upload_handler, [files_input], [files_input, file_list],
95
+ show_progress="corner", concurrency_id="rag", api_visibility="private",
96
+ )
97
+ refresh_btn.click(format_file_list, None, file_list, api_visibility="private")
98
+ clear_btn.click(clear_handler, None, file_list, concurrency_id="rag", api_visibility="private")
99
 
100
  with gr.Tab("Chat"):
101
  chatbot = gr.Chatbot(
 
105
  layout="bubble",
106
  elem_id="document-chat",
107
  )
108
+ chatbot.clear(
109
+ clear_chat_handler, [session_thread], [session_thread],
110
+ concurrency_id="rag", api_visibility="private",
111
+ )
112
 
113
  gr.ChatInterface(
114
  fn=chat_handler,
 
119
  elem_id="question-input",
120
  ),
121
  additional_inputs=[session_thread],
122
+ additional_outputs=[session_thread],
123
  concurrency_limit=1,
124
+ api_name="chat",
125
  )
126
  gr.Markdown(
127
  "Documents are shared with everyone who can access this app. "