-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.py
executable file
·96 lines (81 loc) · 2.53 KB
/
cli.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import argparse
import asyncio
import os
from codypy.client_info import AgentSpecs
from codypy.cody_py import CodyAgent, CodyServer
async def async_main():
parser = argparse.ArgumentParser(description="Cody Agent Python CLI")
parser.add_argument("chat", help="Initialize the chat conversation")
parser.add_argument(
"--binary_path",
type=str,
required=True,
default=os.getenv("BINARY_PATH"),
help="The path to the Cody Agent binary. (Required)",
)
parser.add_argument(
"--access_token",
type=str,
required=True,
default=os.getenv("SRC_ACCESS_TOKEN"),
help="The Sourcegraph access token. (Needs to be exported as SRC_ACCESS_TOKEN) (Required)",
)
parser.add_argument(
"-m",
"--message",
type=str,
required=True,
help="The chat message to send. (Required)",
)
parser.add_argument(
"--workspace_root_uri",
type=str,
default=os.path.abspath(os.getcwd()),
help=f"The current working directory. Default={os.path.abspath(os.getcwd())}",
)
parser.add_argument(
"-ec",
"--enhanced-context",
type=bool,
default=True,
help="Use enhanced context if in a git repo (needs remote repo configured). Default=True",
)
parser.add_argument(
"-sc",
"--show-context",
type=bool,
default=False,
help="Show the inferred context files from the message if any. Default=True",
)
args = parser.parse_args()
await chat(args)
async def chat(args):
cody_server: CodyServer = await CodyServer.init(
binary_path=args.binary_path,
version="5.5.14",
)
# Create an AgentSpecs instance with the specified workspace root URI and extension configuration.
agent_specs = AgentSpecs(
workspaceRootUri=args.workspace_root_uri,
extensionConfiguration={
"accessToken": args.access_token,
"codebase": "", # github.com/sourcegraph/cody",
"customConfiguration": {},
},
)
cody_agent: CodyAgent = await cody_server.initialize_agent(agent_specs=agent_specs)
await cody_agent.new_chat()
response = await cody_agent.chat(
message=args.message,
enhanced_context=args.ec,
show_context_files=args.sc,
)
if response == "":
return
print(response)
await cody_server.cleanup_server()
return None
def main():
asyncio.run(async_main())
if __name__ == "__main__":
main()