-
Notifications
You must be signed in to change notification settings - Fork 564
Expand file tree
/
Copy pathcustom_search.py
More file actions
52 lines (47 loc) · 1.31 KB
/
custom_search.py
File metadata and controls
52 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from mistralrs import (
Runner,
Which,
ChatCompletionRequest,
Architecture,
WebSearchOptions,
)
import os
def local_search(query: str):
results = []
for root, _, files in os.walk("."):
for f in files:
if query in f:
path = os.path.join(root, f)
try:
content = open(path).read()
except Exception:
content = ""
results.append(
{
"title": f,
"description": path,
"url": path,
"content": content,
}
)
results.sort(key=lambda r: r["title"], reverse=True)
return results
runner = Runner(
which=Which.Plain(
model_id="NousResearch/Hermes-3-Llama-3.1-8B",
arch=Architecture.Llama,
),
enable_search=True,
search_callback=local_search,
)
res = runner.send_chat_completion_request(
ChatCompletionRequest(
model="default",
messages=[{"role": "user", "content": "Where is Cargo.toml in this repo?"}],
max_tokens=64,
web_search_options=WebSearchOptions(
search_description="Local filesystem search"
),
)
)
print(res.choices[0].message.content)