DeepCodeGeniusWeb-vscode/tools/askcode_index_query.py

35 lines
815 B
Python
Raw Normal View History

import os
import sys
2023-10-11 23:51:57 +08:00
from chat.ask_codebase.chains.smart_qa import SmartQA
2023-10-11 23:51:57 +08:00
def query(question, lsp_brige_port):
root_path = os.getcwd()
2023-10-11 23:51:57 +08:00
# Create an instance of SmartQA
smart_qa = SmartQA(root_path)
2023-10-11 23:51:57 +08:00
# Use SmartQA to get the answer
answer = smart_qa.run(question=question, verbose=False, dfs_depth=3, dfs_max_visit=10, bridge_url=f'http://localhost:{lsp_brige_port}' )
2023-10-11 23:51:57 +08:00
# Print the answer
print(answer[0])
def main():
try:
2023-10-11 23:51:57 +08:00
if len(sys.argv) < 4:
print("Usage: python index_and_query.py query [question] [port]")
sys.exit(1)
2023-10-11 23:51:57 +08:00
question = sys.argv[2]
port = sys.argv[3]
query(question, port)
sys.exit(0)
except Exception as e:
print(e)
sys.exit(1)
if __name__ == "__main__":
2023-10-11 23:51:57 +08:00
main()