Replace the usage of services functions with IDEService client
This commit is contained in:
parent
5f1926fcdd
commit
ef1c9ef3cb
@ -6,7 +6,7 @@ from chat.ask_codebase.chains.smart_qa import SmartQA
|
|||||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "libs"))
|
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "libs"))
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "libs"))
|
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "libs"))
|
||||||
|
|
||||||
from ide_services import get_lsp_brige_port # noqa: E402
|
from ide_services import IDEService # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
def query(question, lsp_brige_port):
|
def query(question, lsp_brige_port):
|
||||||
@ -59,7 +59,7 @@ def main():
|
|||||||
print("Usage: python index_and_query.py query [question] [port]")
|
print("Usage: python index_and_query.py query [question] [port]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
port = get_lsp_brige_port()
|
port = IDEService().get_lsp_brige_port()
|
||||||
|
|
||||||
question = sys.argv[2]
|
question = sys.argv[2]
|
||||||
query(question, port)
|
query(question, port)
|
||||||
|
@ -9,7 +9,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "libs"))
|
|||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
from chatmark import Checkbox, Form, TextEditor # noqa: E402
|
from chatmark import Checkbox, Form, TextEditor # noqa: E402
|
||||||
from ide_services.services import log_info
|
from ide_services import IDEService # noqa: E402
|
||||||
from llm_api import chat_completion_stream # noqa: E402
|
from llm_api import chat_completion_stream # noqa: E402
|
||||||
|
|
||||||
diff_too_large_message_en = (
|
diff_too_large_message_en = (
|
||||||
@ -67,17 +67,19 @@ def read_prompt_from_file(filename):
|
|||||||
- FileNotFoundError: If the file does not exist.
|
- FileNotFoundError: If the file does not exist.
|
||||||
- Exception: If any other error occurs during file reading.
|
- Exception: If any other error occurs during file reading.
|
||||||
"""
|
"""
|
||||||
|
s = IDEService()
|
||||||
try:
|
try:
|
||||||
with open(filename, "r", encoding="utf-8") as file:
|
with open(filename, "r", encoding="utf-8") as file:
|
||||||
return file.read().strip()
|
return file.read().strip()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
log_info(
|
s.ide_logging(
|
||||||
|
"info",
|
||||||
f"File {filename} not found. "
|
f"File {filename} not found. "
|
||||||
"Please make sure it exists in the same directory as the script."
|
"Please make sure it exists in the same directory as the script.",
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_info(f"An error occurred while reading the file {filename}: {e}")
|
s.ide_logging("info", f"An error occurred while reading the file {filename}: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
from .services import (
|
from .service import IDEService
|
||||||
get_lsp_brige_port,
|
|
||||||
ide_language,
|
|
||||||
ide_logging,
|
|
||||||
install_python_env,
|
|
||||||
update_slash_commands,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"get_lsp_brige_port",
|
"IDEService",
|
||||||
"install_python_env",
|
|
||||||
"update_slash_commands",
|
|
||||||
"ide_language",
|
|
||||||
"ide_logging",
|
|
||||||
]
|
]
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
from typing import List
|
|
||||||
import os
|
import os
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from .types import Location, SymbolNode
|
from typing import List
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from .types import Location, SymbolNode
|
||||||
|
|
||||||
BASE_SERVER_URL = os.environ.get("DEVCHAT_IDE_SERVICE_URL", "http://localhost:3000")
|
BASE_SERVER_URL = os.environ.get("DEVCHAT_IDE_SERVICE_URL", "http://localhost:3000")
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +49,15 @@ def rpc_method(f):
|
|||||||
|
|
||||||
|
|
||||||
class IDEService:
|
class IDEService:
|
||||||
|
"""
|
||||||
|
Client for IDE service
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
client = IDEService()
|
||||||
|
res = client.ide_language()
|
||||||
|
res = client.ide_logging("info", "some message")
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._result = None
|
self._result = None
|
||||||
|
|
||||||
@ -78,7 +89,5 @@ class IDEService:
|
|||||||
return [SymbolNode.parse_obj(node) for node in self._result]
|
return [SymbolNode.parse_obj(node) for node in self._result]
|
||||||
|
|
||||||
@rpc_method
|
@rpc_method
|
||||||
def find_type_def_locations(
|
def find_type_def_locations(self, abspath: str, line: int, character: int) -> List[Location]:
|
||||||
self, abspath: str, line: int, character: int
|
|
||||||
) -> List[Location]:
|
|
||||||
return [Location.parse_obj(loc) for loc in self._result]
|
return [Location.parse_obj(loc) for loc in self._result]
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
from typing import List
|
|
||||||
|
|
||||||
from .rpc import rpc_call
|
|
||||||
from .types import Location, SymbolNode
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def get_lsp_brige_port() -> str:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def install_python_env(command_name: str, requirements_file: str) -> str:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def update_slash_commands() -> bool:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def ide_language() -> str:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def ide_logging(level: str, message: str) -> bool:
|
|
||||||
"""
|
|
||||||
level: "info" | "warn" | "error" | "debug"
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def get_document_symbols(abspath: str) -> List[SymbolNode]:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@rpc_call
|
|
||||||
def find_type_def_locations(abspath: str, line: int, character: int) -> List[Location]:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# NOTE: for compatibility, remove this after all usages are replaced with ide_logging
|
|
||||||
def log_info(message) -> bool:
|
|
||||||
return ide_logging("info", message)
|
|
@ -1,4 +1,5 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
|||||||
|
|
||||||
|
|
||||||
from chatmark import Checkbox, Form, TextEditor # noqa: #402
|
from chatmark import Checkbox, Form, TextEditor # noqa: #402
|
||||||
from ide_services.services import log_info # noqa: #402
|
|
||||||
|
|
||||||
|
|
||||||
class MissEditConfirmFieldException(Exception):
|
class MissEditConfirmFieldException(Exception):
|
||||||
|
@ -9,7 +9,7 @@ from .openai import chat_call_completion_stream
|
|||||||
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
|
||||||
from chatmark import Checkbox, Form, Radio, TextEditor # noqa: #402
|
from chatmark import Checkbox, Form, Radio, TextEditor # noqa: #402
|
||||||
from ide_services.services import log_info, log_warn # noqa: #402
|
from ide_services import IDEService # noqa: #402
|
||||||
|
|
||||||
|
|
||||||
class MissToolsFieldException(Exception):
|
class MissToolsFieldException(Exception):
|
||||||
@ -191,9 +191,10 @@ def chat_tools(
|
|||||||
# call function
|
# call function
|
||||||
functions = {tool.function_name: tool for tool in tools}
|
functions = {tool.function_name: tool for tool in tools}
|
||||||
for call in response["all_calls"]:
|
for call in response["all_calls"]:
|
||||||
log_info(
|
IDEService().ide_logging(
|
||||||
|
"info",
|
||||||
f"try to call function tool: {call['function_name']} "
|
f"try to call function tool: {call['function_name']} "
|
||||||
f"with {call['parameters']}"
|
f"with {call['parameters']}",
|
||||||
)
|
)
|
||||||
tool = functions[call["function_name"]]
|
tool = functions[call["function_name"]]
|
||||||
result = tool(**json.loads(call["parameters"]))
|
result = tool(**json.loads(call["parameters"]))
|
||||||
|
@ -10,7 +10,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "..", "libs"))
|
|||||||
from chatmark import Checkbox, Form, Step, TextEditor # noqa: E402
|
from chatmark import Checkbox, Form, Step, TextEditor # noqa: E402
|
||||||
from find_reference_tests import find_reference_tests
|
from find_reference_tests import find_reference_tests
|
||||||
from i18n import TUILanguage, get_translation
|
from i18n import TUILanguage, get_translation
|
||||||
from ide_services import ide_language # noqa: E402
|
from ide_services import IDEService # noqa: E402
|
||||||
from model import (
|
from model import (
|
||||||
FuncToTest,
|
FuncToTest,
|
||||||
TokenBudgetExceededException,
|
TokenBudgetExceededException,
|
||||||
@ -214,7 +214,8 @@ def main(input: str):
|
|||||||
user_prompt = f"Help me write unit tests for the `{func_name}` function"
|
user_prompt = f"Help me write unit tests for the `{func_name}` function"
|
||||||
|
|
||||||
repo_root = os.getcwd()
|
repo_root = os.getcwd()
|
||||||
ide_lang = ide_language()
|
ide_lang = IDEService().ide_language()
|
||||||
|
|
||||||
tui_lang = TUILanguage.from_str(ide_lang)
|
tui_lang = TUILanguage.from_str(ide_lang)
|
||||||
_i = get_translation(tui_lang)
|
_i = get_translation(tui_lang)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user