MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / mainProcess

Function mainProcess

src/content.js:28–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 const { utility, animation, state, api, preferences } = window;
27
28 const mainProcess = async () => {
29 //Obtain the Textarea of the current input box
30 const activeTextarea = document.activeElement;
31
32 if (activeTextarea.tagName != "TEXTAREA"){
33 return
34 }
35
36 state.activeRequestTextarea = activeTextarea
37
38 // Obtain the current input box (cell) from the Textarea of the current input box
39 const activeCell = activeTextarea.parentElement.parentElement
40
41 const checkedMode = await preferences.getCheckedMode()
42
43 if (!checkedMode) {
44 alert("Please save your settings!")
45 return
46 }
47
48 const currctJupyterModel = state.currctJupyterModel
49 const requestType = state.requestType
50
51 // Retrieve the content of the active cell
52 const [code, isLastLine] = utility.getCodeFormat(checkedMode, currctJupyterModel, requestType);
53
54
55 if (!code) return;
56
57 if (activeCell) {
58 // Start Animation
59 const [animationInterval, animationElement, activeCellElement] = animation.startWaitingAnimation(activeCell)
60 state.isRequestInProgress = true
61
62 let suggestion;
63 // Deal with a series of problems such as network
64 try {
65
66 switch (checkedMode) {
67 case "OpenAI":
68 // Openai does not support fixing bugs
69 if (state.requestType == "fixBug") {
70 clearInterval(animationInterval)
71 activeCellElement.classList.remove('before-content')
72 state.isRequestInProgress = false
73 return
74 }
75
76 const apikey = await preferences.getOpenAIKey()
77 const GPTModelType = await preferences.getGPTModelType()
78 suggestion = await api.sendToOpenAI(code, apikey, GPTModelType, isLastLine)
79 break;
80
81 case "BigCode":
82 const bigCodeUrl = await preferences.getBigcodeServiceUrl()
83 const huggingfaceAccessToken = await preferences.getHuggingfaceApiKey()
84 const requestType = state.requestType
85 suggestion = await api.sendToBigcode(code, bigCodeUrl, huggingfaceAccessToken, isLastLine, requestType)

Callers 1

requestCodeKeyListenerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected