Spaces:
Paused
Paused
Update backend/autocomplete.py
Browse files- backend/autocomplete.py +3 -28
backend/autocomplete.py
CHANGED
|
@@ -1,30 +1,5 @@
|
|
| 1 |
-
# Fixed autocomplete.py
|
| 2 |
-
autocomplete_py = '''from typing import List
|
| 3 |
from model_router import route_autocomplete
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
try:
|
| 9 |
-
completion = await route_autocomplete(
|
| 10 |
-
model=req.model,
|
| 11 |
-
prefix=req.prefix,
|
| 12 |
-
suffix=req.suffix,
|
| 13 |
-
max_tokens=req.max_tokens,
|
| 14 |
-
)
|
| 15 |
-
# Clean up the response
|
| 16 |
-
completion = completion.strip()
|
| 17 |
-
if completion.startswith("```"):
|
| 18 |
-
lines = completion.split("\n")
|
| 19 |
-
if len(lines) > 2:
|
| 20 |
-
completion = "\n".join(lines[1:-1])
|
| 21 |
-
else:
|
| 22 |
-
completion = completion.replace("```", "").strip()
|
| 23 |
-
return [completion]
|
| 24 |
-
except Exception as e:
|
| 25 |
-
return [f"// Error: {str(e)}"]
|
| 26 |
-
'''
|
| 27 |
-
|
| 28 |
-
with open('/mnt/agents/output/autocomplete.py', 'w') as f:
|
| 29 |
-
f.write(autocomplete_py)
|
| 30 |
-
print("autocomplete.py written successfully")
|
|
|
|
|
|
|
|
|
|
| 1 |
from model_router import route_autocomplete
|
| 2 |
|
| 3 |
+
async def generate_autocomplete(req):
|
| 4 |
+
completion = await route_autocomplete(req.model, req.prefix, req.suffix, req.max_tokens)
|
| 5 |
+
return [{"text": completion}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|