MCPcopy Create free account
hub / github.com/RomanHotsiy/commitgpt / getMessages

Function getMessages

index.ts:84–110  ·  view source on GitHub ↗
(api: ChatGPTClient, request: string)

Source from the content-addressed store, hash-verified

82}
83
84async function getMessages(api: ChatGPTClient, request: string) {
85 spinner.start("Asking ChatGPT 🤖 for commit messages...");
86
87 // send a message and wait for the response
88 try {
89 const response = await api.getAnswer(request);
90 // find json array of strings in the response
91 const messages = response
92 .split("\n")
93 .map(normalizeMessage)
94 .filter((l) => l.length > 1);
95
96 spinner.stop();
97
98 debug("response: ", response);
99
100 messages.push(CUSTOM_MESSAGE_OPTION);
101 return messages;
102 } catch (e) {
103 spinner.stop();
104 if (e.message === "Unauthorized") {
105 return getMessages(api, request);
106 } else {
107 throw e;
108 }
109 }
110}
111
112function normalizeMessage(line: string) {
113 return line

Callers 1

runFunction · 0.85

Calls 2

debugFunction · 0.85
getAnswerMethod · 0.80

Tested by

no test coverage detected