
TrustedSec LLM लाइब्रेरी एक Python लाइब्रेरी है जो टूल उपयोग का समर्थन करने वाले स्थानीय LLM के साथ इंटरैक्ट करने के लिए है। यह स्थानीय LLM एंडपॉइंट और MCP (Model Context Protocol) एकीकरण का लाभ उठाकर बड़े वर्कफ़्लो चलाने में सक्षम बनाती है जो परंपरागत रूप से केवल फ्रंटियर मॉडल के साथ संभव थे।
# Clone or copy the repository
git clone https://github.com/trustedsec/ts_llmlib.git
cd ts_llmlib
# Install with pip
pip install -e .
ts_llmlib/ निर्देशिका को अपने प्रोजेक्ट में कॉपी करें:
cp -rf ts_llmlib /path/to/your/project/
from ts_llmlib import ChatSession
# Initialize with defaults (connects to http://localhost:1234/v1/chat/completions)
chat = ChatSession()
# Run a prompt
response = chat.run_prompt("What files are in the current directory?")
print(response['content'])
from ts_llmlib import ChatSession
# Configure with custom settings
chat = ChatSession(
system_prompt="You are a helpful assistant that uses file tools.",
tool_list=[], # Empty = use default file tools
mcp_servers={
"default": "http://localhost:3000/mcp"
},
llm_endpoint_url="http://localhost:1234/v1/chat/completions",
model_name="qwen3-coder-next",
timeout=60,
max_runtime=300
)
response = chat.run_prompt("Write 'hello' to /tmp/greeting.txt")
print(response['content'])
from ts_llmlib import ChatSession
chat = ChatSession()
history = [
{"role": "user", "content": "What is 2+2?"},
{"role": "assistant", "content": "The answer is 4."}
]
response = chat.run_prompt("Can you write that to a file?", history=history)
MCP (Model Context Protocol) बाहरी टूल और सेवाओं के साथ एकीकरण सक्षम करता है। जब MCP सर्वर कॉन्फ़िगर किए जाते हैं, तो ts_llmlib:
from ts_llmlib import ChatSession
chat = ChatSession(
mcp_servers={
"ghidraSvr": "http://localhost:8081/sse"
},
llm_endpoint_url="http://localhost:1234/v1/chat/completions",
model_name="qwen3-coder-next"
)
# The chat session will automatically fetch and integrate Ghidra tools
# such as list_methods, decompile_function, get_xrefs_to, etc.
ts_llmlib RPC-शैली और SSE (Server-Sent Events) दोनों एंडपॉइंट का समर्थन करता है:
http://localhost:3000/mcphttp://localhost:3000/sse (RPC कॉल के लिए स्वचालित रूप से /mcp में परिवर्तित होता है)ChatSession(
system_prompt: str | None = None,
tool_list: list | None = None,
mcp_servers: dict[str, str] | None = None,
llm_endpoint_url: str = "http://localhost:1234/v1/chat/completions",
model_name: str = "default",
timeout: int = 60,
max_runtime: int = 300
)
पैरामीटर:
system_prompt (str | None): कस्टम सिस्टम प्रॉम्प्ट। डिफ़ॉल्ट एक न्यूनतम सहायक प्रॉम्प्ट है।tool_list (list | None): कस्टम टूल परिभाषाओं की सूची। खाली सूची अंतर्निहित टूल का उपयोग करती है।mcp_servers (dict[str, str] | None): सर्वर नामों को URL से मैप करने वाली डिक्शनरी।llm_endpoint_url (str): LLM API एंडपॉइंट का URL।model_name (str): LLM एंडपॉइंट के लिए मॉडल पहचानकर्ता।timeout (int): HTTP अनुरोध टाइमआउट सेकंड में।max_runtime (int): प्रॉम्प्ट के लिए अधिकतम निष्पादन समय सेकंड में।response = chat.run_prompt(
user_prompt: str,
conversation_history: list[dict] | None = None,
disable_tools: list[str] | None = None,
max_runtime: int | None = None
) -> dict
पैरामीटर:
user_prompt (str): उपयोगकर्ता का संदेश या प्रश्न।conversation_history (list[dict] | None): वैकल्पिक वार्तालाप इतिहास role/content जोड़ियों की सूची के रूप में।disable_tools (list[str] | None): इस कॉल के लिए अक्षम किए जाने वाले टूल नामों की सूची।max_runtime (int | None): इस विशेष कॉल के लिए डिफ़ॉल्ट अधिकतम रनटाइम ओवरराइड करें।रिटर्न:
{
"content": str, # LLM response text
"tool_calls": list, # List of tool calls made (if any)
"usage": dict | None, # Token usage if available from the LLM
"error": str | None # Error message if failed
}
ToolRegistry चैट सत्र के लिए उपलब्ध सभी टूल प्रबंधित करता है:
tool_list पैरामीटर के माध्यम से उपयोगकर्ता-परिभाषित टूलडिफ़ॉल्ट पथों को ओवरराइड करने के लिए आप निम्नलिखित वेरिएबल सेट कर सकते हैं, इन्हें ChatSession में जाँचा जाता है।
TS_LLM_MODEL=qwen3-coder-next TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions
# Example usage
export TS_LLM_MODEL=qwen3-coder-next
export TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions
ts_llmlib-redclippy
# OR
TS_LLM_MODEL=qwen3-coder-next TS_LLM_ENDPOINT=http://HOSTNAME:1234/v1/chat/completions ts_llmlib-redclippy
सुरक्षा भेद्यताओं के लिए C/C++ सोर्स फ़ाइलों का विश्लेषण करता है:
ts_llmlib-cpp-analyze <source_folder> <output_folder>
Ghidra एकीकरण के साथ रिवर्स इंजीनियरिंग बाइनरी विश्लेषण:
# Basic analysis
ts_llmlib-ghidra-analyze <output_folder>
# Rename-only mode (first pass)
ts_llmlib-ghidra-analyze --rename_only <output_folder>
# Process only previously unnamed functions
ts_llmlib-ghidra-analyze --process_unnamed_only <output_folder>
# Grouped analysis for call relationship grouping
ts_llmlib-ghidra-analyze --grouped <output_folder>
यदि --rename_only नहीं कर रहे हैं तो चलाने के बाद आप संरचना को साफ कर सकते हैं:
ts_llmlib-ghidra-cleanup <input_folder> <output_folder>
JSON समीक्षा फ़ाइलों से स्वरूपित भेद्यता रिपोर्ट उत्पन्न करें:
ts_llmlib-ghidra-report <review_folder>
RedClippy Qt-आधारित चैट इंटरफ़ेस चलाएं (ध्यान दें: इस उदाहरण के लिए pyside6 आवश्यक है):
ts_llmlib-redclippy
ts_llmlib किसी भी OpenAI-संगत API एंडपॉइंट से कनेक्ट होता है। सामान्य स्थानीय LLM सर्वर:
| सर्वर | डिफ़ॉल्ट URL |
|---|---|
| Ollama | http://localhost:11434/v1/chat/completions |
| LM Studio | http://localhost:1234/v1/chat/completions |
| vLLM | http://localhost:8000/v1/chat/completions |
दो टाइमआउट सेटिंग्स निष्पादन को नियंत्रित करती हैं:
timeout): एकल API अनुरोध के लिए अधिकतम समयmax_runtime): प्रॉम्प्ट प्रोसेसिंग के लिए अनुमत कुल वास्तविक समय (टूल कॉल सहित)यदि कोई भी सीमा पार हो जाती है, तो प्रतिक्रिया में एक त्रुटि संदेश होगा।
सभी त्रुटियाँ प्रतिक्रिया डिक्शनरी में लौटाई जाती हैं:
response = chat.run_prompt("Some prompt")
if response.get('error'):
print(f"Error: {response['error']}")
else:
print(response['content'])
max_runtime सीमा पार कर दीts_llmlib/
├── __init__.py # Package initialization, exports ChatSession
├── client.py # LLMClient for HTTP requests to LLM endpoints
├── chat.py # ChatSession class (main API)
├── mcp.py # MCPClient for Model Context Protocol integration
├── tools.py # ToolRegistry for tool management
├── HOW_TO_TS_LLMLIB.md # Original documentation
└── examples/ # Example scripts
├── c_cpp_analyze.py # C/C++ vulnerability analysis script
├── redclippy.py # Qt-based GUI chat application
├── ghidra_analyze.py # Ghidra binary analysis with MCP integration
├── ghidra_vuln_report.py # Vulnerability report generator
├── ghidra_cleanup.py # Output file reorganization utility
└── example_ts_llmlib.py # Example script demonstrating library usage
pyproject.toml # Modern Python package configuration (scripts defined here)
LICENSE.txt # BSD-3-Clause License
README.md # This file
BSD-3-Clause लाइसेंस - विवरण के लिए LICENSE.txt फ़ाइल देखें।
योगदान का स्वागत है! कृपया बेझिझक Pull Request सबमिट करें।
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)| टूल | पैरामीटर | विवरण |
|---|
read_local_file | path: str | स्थानीय फ़ाइल से सामग्री पढ़ें |
write_local_file | path: str, content: str | स्थानीय फ़ाइल में सामग्री लिखें |
list_directory | path: str | किसी पथ में फ़ाइलों और निर्देशिकाओं की सूची बनाएं |