FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CodeHelperNET/backend/query_codehelper.py at main · AndNikDev/CodeHelperNET · GitHub
AndNikDev
/
CodeHelperNET
Public
forked from
gaby0398/CodeHelperNET
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CodeHelperNET
/
backend
/
query_codehelper.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (26 loc) · 1.23 KB
Breadcrumbs
CodeHelperNET
/
backend
/
query_codehelper.py
Copy path
File metadata and controls
34 lines (26 loc) · 1.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
sentence_transformers
import
SentenceTransformer
from
chromadb
import
PersistentClient
from
transformers
import
pipeline
# Conectar con la base vectorial
client
=
PersistentClient
(
path
=
"./vector_db"
)
collection
=
client
.
get_collection
(
"codehelper_csharp"
)
# Cargar modelo de embeddings
model
=
SentenceTransformer
(
"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
)
# Cargar traductor inglés → español
translator
=
pipeline
(
"translation_en_to_es"
,
model
=
"Helsinki-NLP/opus-mt-en-es"
)
# Pregunta del usuario
query
=
input
(
"Escribí tu pregunta sobre C# o .NET: "
)
# Generar embedding y buscar
embedding
=
model
.
encode
(
query
).
tolist
()
results
=
collection
.
query
(
query_embeddings
=
[
embedding
],
n_results
=
3
)
# Mostrar resultados con opción de ver original
print
(
"
\n
🔍 Resultados más relevantes (traducidos al español):"
)
for
i
,
doc
in
enumerate
(
results
[
"documents"
][
0
]):
print
(
f"
\n
🔹 Fragmento
{
i
+
1
}
:"
)
# Traducción al español
translated
=
translator
(
doc
[:
500
])[
0
][
"translation_text"
]
print
(
translated
)
# Preguntar si quiere ver el original
ver_original
=
input
(
"¿Querés ver el texto original en inglés? (s/n): "
).
strip
().
lower
()
if
ver_original
==
"s"
:
print
(
"
\n
Original:
\n
"
+
doc
[:
500
])
Back
|
FazBrowse Home
|
New Git URL