Skip to content

Commit 4fef393

Browse files
committed
Minor improvements in ollama code, ensure dir busting process is cleaned up, run_unix_command instructions.
1 parent cd8cc58 commit 4fef393

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ chroma-haystack~=3.3.0
33
numpy<2
44
ollama-haystack~=5.1.0
55
google-genai-haystack~=2.1.1
6-
mcp-haystack~=0.5.0
6+
mcp-haystack~=0.6.0
77
chardet~=5.2.0
88
sentence-transformers~=5.1.0
99
prompt_toolkit~=3.0.51
10-
mcp[cli]~=1.13.1
10+
mcp[cli]~=1.14.1
1111
httpx~=0.28.1
12-
uv~=0.8.6
12+
uv~=0.8.18
1313
tldextract~=5.3.0
1414
validators~=0.35.0
1515
more-itertools~=10.8.0
@@ -26,4 +26,4 @@ html5lib~=1.1
2626
optimum~=1.27.0
2727
ddgs~=9.5.2
2828
pycryptodome~=3.23.0
29-
psutil~=7.0.0
29+
psutil~=7.1.0

shyhurricane/generator_config.py

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from typing import Optional, Dict, Any, Union, List
55

6+
import requests
67
from google.genai import Client
78
from google.genai.types import HttpOptions, HttpRetryOptions
89
from haystack.components.generators import OpenAIGenerator
@@ -36,6 +37,7 @@ def add_generator_args(ap: argparse.ArgumentParser):
3637

3738

3839
TEMPERATURE_DEFAULT: float = 0.2
40+
OLLAMA_HOST_DEFAULT = "localhost:11434"
3941

4042

4143
class GoogleGenAIChatGeneratorWithRetry(GoogleGenAIChatGenerator):
@@ -173,6 +175,18 @@ def _thinking_convert_ollama_response_to_chatmessage(ollama_response: ChatRespon
173175
ollama_cg._convert_ollama_response_to_chatmessage = _thinking_convert_ollama_response_to_chatmessage
174176

175177

178+
def ollama_model_supports_thinking(ollama_host: str, ollama_model: str) -> bool:
179+
r = requests.post(f"http://{ollama_host}/api/chat", json={
180+
"model": ollama_model,
181+
"messages": [{"role": "user", "content": "ping"}],
182+
"think": True,
183+
"stream": False
184+
})
185+
data = r.json()
186+
supports_thinking = bool(data.get("message", {}).get("thinking"))
187+
return supports_thinking
188+
189+
176190
class GeneratorConfig(BaseModel):
177191
ollama_host: Optional[str] = Field(description="The location of the Ollama server", default=None)
178192
ollama_model: Optional[str] = Field(description="The name of the Ollama model", default=None)
@@ -203,6 +217,7 @@ def from_env():
203217
return generator_config
204218

205219
def apply_reasoning_default(self):
220+
self.ollama_host = self.ollama_host or OLLAMA_HOST_DEFAULT
206221
if self.ollama_model or self.gemini_model or self.openai_model:
207222
return self
208223
if os.environ.get("GEMINI_API_KEY", None) or os.environ.get("GOOGLE_API_KEY", None):
@@ -214,6 +229,7 @@ def apply_reasoning_default(self):
214229
return self
215230

216231
def apply_summarizing_default(self):
232+
self.ollama_host = self.ollama_host or OLLAMA_HOST_DEFAULT
217233
if self.ollama_model or self.gemini_model or self.openai_model:
218234
return self
219235
self.ollama_model = "llama3.2:3b"
@@ -235,10 +251,7 @@ def describe(self) -> str:
235251
elif self.gemini_model:
236252
return f"Gemini {self.gemini_model}"
237253
else:
238-
if self.ollama_host:
239-
return f"Ollama {self.ollama_model} at {self.ollama_host}"
240-
else:
241-
return f"Ollama {self.ollama_model}"
254+
return f"Ollama {self.ollama_model} at {self.ollama_host}"
242255

243256
def create_chat_generator(self,
244257
temperature: Optional[float] = None,
@@ -272,29 +285,20 @@ def create_chat_generator(self,
272285
"temperature": temperature or self.temperature,
273286
}
274287
ollama_timeout = int(os.environ.get("OLLAMA_TIMEOUT", "300"))
275-
if self.ollama_model.startswith("gpt-oss"):
288+
ollama_think = ollama_model_supports_thinking(self.ollama_host, self.ollama_model)
289+
if ollama_think:
276290
# OllamaChatGenerator docs say the think parameter can be a bool or "low", "medium", "high", but the client only supports bool
277291
# https://huggingface.co/docs/inference-providers/guides/gpt-oss
278292
_generation_kwargs["effort"] = "high"
279-
if self.ollama_host:
280-
logger.info("Using Ollama chat with model %s at %s", self.ollama_model, self.ollama_host)
281-
return OllamaChatGenerator(
282-
url="http://" + self.ollama_host,
283-
model=self.ollama_model,
284-
timeout=ollama_timeout,
285-
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
286-
tools=tools,
287-
think=True,
288-
)
289-
else:
290-
logger.info("Using Ollama chat with model %s", self.ollama_model)
291-
return OllamaChatGenerator(
292-
model=self.ollama_model,
293-
timeout=ollama_timeout,
294-
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
295-
tools=tools,
296-
think=True,
297-
)
293+
logger.info("Using Ollama chat with model %s at %s", self.ollama_model, self.ollama_host)
294+
return OllamaChatGenerator(
295+
url="http://" + (self.ollama_host or OLLAMA_HOST_DEFAULT),
296+
model=self.ollama_model,
297+
timeout=ollama_timeout,
298+
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
299+
tools=tools,
300+
think=ollama_think,
301+
)
298302
else:
299303
raise NotImplementedError
300304

@@ -326,19 +330,12 @@ def create_generator(self,
326330
_generation_kwargs = {
327331
"temperature": temperature or self.temperature,
328332
}
329-
if self.ollama_host:
330-
logger.info("Using Ollama generator with model %s at %s", self.ollama_model, self.ollama_host)
331-
return OllamaGenerator(
332-
url="http://" + self.ollama_host,
333-
model=self.ollama_model,
334-
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
335-
)
336-
else:
337-
logger.info("Using Ollama generator with model %s", self.ollama_model)
338-
return OllamaGenerator(
339-
model=self.ollama_model,
340-
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
341-
)
333+
logger.info("Using Ollama generator with model %s at %s", self.ollama_model, self.ollama_host)
334+
return OllamaGenerator(
335+
url="http://" + (self.ollama_host or OLLAMA_HOST_DEFAULT),
336+
model=self.ollama_model,
337+
generation_kwargs=_generation_kwargs | (generation_kwargs or {}),
338+
)
342339
else:
343340
raise NotImplementedError
344341

shyhurricane/mcp_server/tools/run_unix_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def run_unix_command(
7474
- Always set a timeout for potentially blocking commands (e.g., timeout 10s nmap ...). Use a timeout value appropriate for the command. For example, directory busting with a large word list may take 10 minutes, whereas a short wordlist may be 2 minutes.
7575
- Ensure commands can be complete without user interaction before execution.
7676
- The directly accessible filesystem is part of the containerized environment, not the target. Commands such as find, cat, etc. are not enumerating the target unless they are part of a command that connects to the target, such as ssh.
77-
- Files in the current working directory will persist across calls. Do not write to /tmp or /var/tmp. Do not save output to files outside of the current working directory.
77+
- Files in the current working directory will persist across calls. Prefer writing files to the current working directory.
7878
"""
7979
await log_tool_history(ctx, title="run_unix_command", command=command, additional_hosts=additional_hosts, env=env)
8080
server_ctx = await get_server_context()

shyhurricane/task_queue/dir_busting_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ def process_stdout(data: str):
168168
# logger.error("Dir busting errors %s", buster_proc.stderr.read())
169169
return None
170170
finally:
171-
mitmdump_proc.terminate()
172171
if result_queue:
173172
result_queue.put_nowait(None)
173+
subprocess.Popen(["docker", "rm", "-f", container_name], stdout=subprocess.DEVNULL,
174+
stderr=subprocess.DEVNULL)
174175

175176

176177
def _build_feroxbuster_command(

0 commit comments

Comments
 (0)