Skip to content

Commit 7acd76d

Browse files
authored
remove refact-lsp and related logic (we dont use it) (#487)
* remove refact-lsp and related logic (we dont use it) * remove lsp config and unneded hack * remove lsp proxy
1 parent 5dcb91b commit 7acd76d

File tree

12 files changed

+9
-354
lines changed

12 files changed

+9
-354
lines changed

Dockerfile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ RUN curl https://downloads.apache.org/cassandra/KEYS | apt-key add -
3232
RUN apt-get update
3333
RUN apt-get install cassandra -y
3434

35-
# refact lsp requisites
36-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
37-
ENV PATH="${PATH}:/root/.cargo/bin"
38-
RUN git clone https://github.com/smallcloudai/refact-lsp.git /tmp/refact-lsp
39-
RUN echo "refact-lsp $(git -C /tmp/refact-lsp rev-parse HEAD)" >> /refact-build-info.txt
40-
RUN cd /tmp/refact-lsp \
41-
&& cargo install --path . \
42-
&& rm -rf /tmp/refact-lsp
43-
4435
# to ping hf
4536
RUN apt-get install -y iputils-ping
4637

refact_webgui/webgui/selfhost_fastapi_completions.py

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def __init__(self,
207207
self.add_api_route("/v1/embeddings", self._embeddings_style_openai, methods=["POST"])
208208
self.add_api_route("/v1/chat/completions", self._chat_completions, methods=["POST"])
209209

210-
self.add_api_route("/v1/models", self._models, methods=["GET"])
211210
self.add_api_route("/tokenizer/{model_name}", self._tokenizer, methods=["GET"])
212211

213212
self._inference_queue = inference_queue
@@ -483,35 +482,6 @@ async def _embeddings_style_openai(self, post: EmbeddingsStyleOpenAI, authorizat
483482
"usage": {"prompt_tokens": -1, "total_tokens": -1}
484483
}
485484

486-
async def _models(self, authorization: str = Header(None)):
487-
await self._account_from_bearer(authorization)
488-
try:
489-
async with aiohttp.ClientSession() as session:
490-
async with session.get("http://127.0.0.1:8001/v1/caps") as resp:
491-
lsp_server_caps = await resp.json()
492-
except aiohttp.ClientConnectorError as e:
493-
err_msg = f"LSP server is not ready yet: {e}"
494-
log(err_msg)
495-
raise HTTPException(status_code=401, detail=err_msg)
496-
completion_models = set()
497-
for model, caps in lsp_server_caps["code_completion_models"].items():
498-
completion_models.update({model, *caps["similar_models"]})
499-
chat_models = set()
500-
for model, caps in lsp_server_caps["code_chat_models"].items():
501-
chat_models.update({model, *caps["similar_models"]})
502-
data = [
503-
{
504-
"id": model, "root": model, "object": "model",
505-
"created": 0, "owned_by": "", "permission": [], "parent": None,
506-
"completion": model in completion_models, "chat": model in chat_models,
507-
}
508-
for model in lsp_server_caps["running_models"]
509-
]
510-
return {
511-
"object": "list",
512-
"data": data,
513-
}
514-
515485
async def _chat_completions(self, post: ChatContext, authorization: str = Header(None)):
516486
def compose_usage_dict(model_dict, prompt_tokens_n, generated_tokens_n) -> Dict[str, Any]:
517487
usage_dict = dict()
@@ -543,6 +513,7 @@ def _wrap_output(output: str) -> str:
543513
return prefix + output + postfix
544514

545515
model_dict = self._model_assigner.models_db_with_passthrough.get(post.model, {})
516+
assert model_dict.get('backend') == 'litellm'
546517

547518
async def litellm_streamer():
548519
generated_tokens_n = 0
@@ -613,47 +584,14 @@ async def litellm_non_streamer():
613584
log(err_msg)
614585
yield json.dumps(_patch_caps_version({"error": err_msg}))
615586

616-
async def chat_completion_streamer():
617-
post_url = "http://127.0.0.1:8001/v1/chat"
618-
payload = {
619-
"messages": messages,
620-
"stream": True,
621-
"model": post.model,
622-
"parameters": {
623-
"temperature": post.temperature,
624-
"max_new_tokens": post.actual_max_tokens,
625-
}
626-
}
627-
async with aiohttp.ClientSession() as session:
628-
try:
629-
async with session.post(post_url, json=payload) as response:
630-
finish_reason = None
631-
async for data, _ in response.content.iter_chunks():
632-
try:
633-
data = data.decode("utf-8")
634-
data = json.loads(data[len(prefix):-len(postfix)])
635-
finish_reason = data["choices"][0]["finish_reason"]
636-
data["choices"][0]["finish_reason"] = None
637-
except json.JSONDecodeError:
638-
data = {"choices": [{"finish_reason": finish_reason}]}
639-
yield _wrap_output(json.dumps(_patch_caps_version(data)))
640-
except aiohttp.ClientConnectorError as e:
641-
err_msg = f"LSP server is not ready yet: {e}"
642-
log(err_msg)
643-
yield _wrap_output(json.dumps(_patch_caps_version({"error": err_msg})))
644-
645-
if model_dict.get('backend') == 'litellm':
646-
model_name = model_dict.get('resolve_as', post.model)
647-
if model_name not in litellm.model_list:
648-
log(f"warning: requested model {model_name} is not in the litellm.model_list (this might not be the issue for some providers)")
649-
log(f"chat/completions: model resolve {post.model} -> {model_name}")
650-
prompt_tokens_n = litellm.token_counter(model_name, messages=messages)
651-
if post.tools:
652-
prompt_tokens_n += litellm.token_counter(model_name, text=json.dumps(post.tools))
653-
response_streamer = litellm_streamer() if post.stream else litellm_non_streamer()
654-
else:
655-
# TODO: unused refact-lsp logic, remove ASAP
656-
response_streamer = chat_completion_streamer()
587+
model_name = model_dict.get('resolve_as', post.model)
588+
if model_name not in litellm.model_list:
589+
log(f"warning: requested model {model_name} is not in the litellm.model_list (this might not be the issue for some providers)")
590+
log(f"chat/completions: model resolve {post.model} -> {model_name}")
591+
prompt_tokens_n = litellm.token_counter(model_name, messages=messages)
592+
if post.tools:
593+
prompt_tokens_n += litellm.token_counter(model_name, text=json.dumps(post.tools))
594+
response_streamer = litellm_streamer() if post.stream else litellm_non_streamer()
657595

658596
return StreamingResponse(response_streamer, media_type="text/event-stream")
659597

refact_webgui/webgui/selfhost_login.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ def header_authenticate(self, authorization: str) -> str:
110110
if len(bearer_hdr) != 2 or bearer_hdr[0] != "Bearer":
111111
raise ValueError("Invalid authorization header")
112112
api_key = bearer_hdr[1]
113-
# TODO: this is a hack for chat handler, wee need to pass real user's api key
114-
if api_key == "refact-dummy-chat-key":
115-
return "refact-chat"
116113
if self._token == api_key:
117114
return "user"
118115
raise ValueError("API key mismatch")

refact_webgui/webgui/selfhost_lsp_proxy.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

refact_webgui/webgui/selfhost_plugins.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def __init__(self):
1010
{"label": "Stats", "tab": "stats"},
1111
{"label": "Projects", "tab": "upload"},
1212
{"label": "Finetune", "tab": "finetune"},
13-
# {"label": "Chat", "tab": "chat"},
1413
{"label": "Credentials", "tab": "settings", "hamburger": True},
1514
{"label": "Server Logs", "tab": "server-logs", "hamburger": True},
1615
{"label": "About", "tab": "about", "hamburger": True},

refact_webgui/webgui/selfhost_static.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class StaticRouter(APIRouter):
1414
def __init__(self, *args, **kwargs):
1515
super().__init__(*args, **kwargs)
1616
super().add_api_route("/", self._index, methods=["GET"])
17-
super().add_api_route("/chat", self._chat, methods=["GET"])
1817
super().add_api_route("/{file_path:path}", self._static_file, methods=["GET"])
1918
super().add_api_route("/ping", self._ping_handler, methods=["GET"])
2019
self.static_folders = [
@@ -29,13 +28,6 @@ async def _index(self):
2928
return FileResponse(fn, media_type="text/html")
3029
raise HTTPException(404, "No index.html found")
3130

32-
async def _chat(self):
33-
for spath in self.static_folders:
34-
fn = os.path.join(spath, "tab-chat.html")
35-
if os.path.exists(fn):
36-
return FileResponse(fn, media_type="text/html")
37-
raise HTTPException(404, "No tab-chat.html found")
38-
3931
async def _static_file(self, file_path: str):
4032
for spath in self.static_folders:
4133
try:

0 commit comments

Comments
 (0)