Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Dec 13, 2024
1 parent 3535ba6 commit 47a0a9c
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StatusBarItem,
Webview,
window,
workspace,
workspace
} from "vscode"

import {
Expand All @@ -22,7 +22,7 @@ import {
SYMMETRY_EMITTER_KEY,
SYSTEM,
USER,
WEBUI_TABS,
WEBUI_TABS
} from "../common/constants"
import { CodeLanguageDetails } from "../common/languages"
import { logger } from "../common/logger"
Expand All @@ -33,7 +33,7 @@ import {
ServerMessage,
StreamRequestOptions,
StreamResponse,
TemplateData,
TemplateData
} from "../common/types"
import { kebabToSentence } from "../webview/utils"

Expand All @@ -49,7 +49,7 @@ import { TemplateProvider } from "./template-provider"
import {
getChatDataFromProvider,
getLanguage,
updateLoadingMessage,
updateLoadingMessage
} from "./utils"

export class ChatService extends Base {
Expand Down Expand Up @@ -94,8 +94,8 @@ export class ChatService extends Base {
type: EVENT_NAME.twinnyOnCompletion,
value: {
completion: completion.trimStart(),
data: getLanguage(),
},
data: getLanguage()
}
} as ServerMessage)
}
)
Expand All @@ -119,11 +119,7 @@ export class ChatService extends Base {
const relevantFileCount = Number(stored) || DEFAULT_RELEVANT_FILE_COUNT

const filePaths =
(await this._db.getDocuments(
embedding,
relevantFileCount,
table,
)) || []
(await this._db.getDocuments(embedding, relevantFileCount, table)) || []

if (!filePaths.length) return []

Expand Down Expand Up @@ -235,7 +231,7 @@ export class ChatService extends Base {
(await this._db.getDocuments(
embedding,
Math.round(relevantCodeCount / 2),
table,
table
)) || []

const documents = [...embeddedDocuments, ...queryEmbeddedDocuments]
Expand Down Expand Up @@ -293,17 +289,20 @@ export class ChatService extends Base {
protocol: provider.apiProtocol,
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: provider?.apiKey ? `Bearer ${provider.apiKey}` : undefined,
},
"Content-Type": "application/json"
}
}

if (provider.apiKey) {
requestOptions.headers["Authorization"] = `Bearer ${provider.apiKey}`
}

const requestBody = createStreamRequestBody(provider.provider, {
model: provider.modelName,
numPredictChat: this.config.numPredictChat,
temperature: this.config.temperature,
messages,
keepAlive: this.config.keepAlive,
keepAlive: this.config.keepAlive
})

return { requestOptions, requestBody }
Expand All @@ -325,8 +324,8 @@ export class ChatService extends Base {
value: {
completion: this._completion.trimStart(),
data: getLanguage(),
type: this._promptTemplate,
},
type: this._promptTemplate
}
} as ServerMessage)
} catch (error) {
console.error("Error parsing JSON:", error)
Expand All @@ -344,7 +343,7 @@ export class ChatService extends Base {
if (onEnd) {
onEnd(this._completion)
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd,
type: EVENT_NAME.twinnyOnEnd
} as ServerMessage)
return
}
Expand All @@ -353,8 +352,8 @@ export class ChatService extends Base {
value: {
completion: this._completion.trimStart(),
data: getLanguage(),
type: this._promptTemplate,
},
type: this._promptTemplate
}
} as ServerMessage)
}

Expand All @@ -363,8 +362,8 @@ export class ChatService extends Base {
type: EVENT_NAME.twinnyOnEnd,
value: {
error: true,
errorMessage: `==## ERROR ##== : ${error.message}`, // Highlight errors on webview
},
errorMessage: `==## ERROR ##== : ${error.message}` // Highlight errors on webview
}
} as ServerMessage)
}

Expand Down Expand Up @@ -395,8 +394,8 @@ export class ChatService extends Base {
value: {
completion: this._completion.trimStart(),
data: getLanguage(),
type: this._promptTemplate,
},
type: this._promptTemplate
}
} as ServerMessage)
}

Expand All @@ -414,7 +413,7 @@ export class ChatService extends Base {
template,
{
code: selectionContext || "",
language: language?.langName || "unknown",
language: language?.langName || "unknown"
}
)
return { prompt: prompt || "", selection: selectionContext }
Expand All @@ -423,7 +422,7 @@ export class ChatService extends Base {
private streamResponse({
requestBody,
requestOptions,
onEnd,
onEnd
}: {
requestBody: RequestBodyBase
requestOptions: StreamRequestOptions
Expand All @@ -436,25 +435,25 @@ export class ChatService extends Base {
this.onStreamData(streamResponse as StreamResponse, onEnd),
onEnd: () => this.onStreamEnd(onEnd),
onStart: this.onStreamStart,
onError: this.onStreamError,
onError: this.onStreamError
})
}

private sendEditorLanguage = () => {
this._webView?.postMessage({
type: EVENT_NAME.twinnySendLanguage,
value: {
data: getLanguage(),
},
data: getLanguage()
}
} as ServerMessage)
}

private focusChatTab = () => {
this._webView?.postMessage({
type: EVENT_NAME.twinnySetTab,
value: {
data: WEBUI_TABS.chat,
},
data: WEBUI_TABS.chat
}
} as ServerMessage<string>)
}

Expand All @@ -469,7 +468,7 @@ export class ChatService extends Base {
lineNumber: diagnostic.range.start.line + 1,
character: diagnostic.range.start.character + 1,
source: diagnostic.source,
diagnosticCode: diagnostic.code,
diagnosticCode: diagnostic.code
}))
)
.map((problem) => JSON.stringify(problem))
Expand Down Expand Up @@ -560,7 +559,7 @@ export class ChatService extends Base {
role: SYSTEM,
content: await this._templateProvider?.readSystemMessageTemplate(
this._promptTemplate
),
)
}

let additionalContext = ""
Expand All @@ -577,8 +576,9 @@ export class ChatService extends Base {
additionalContext += `Additional Context:\n${ragContext}\n\n`
}

filePaths = filePaths?.filter((filepath) =>
filepath.name !== "workspace" && filepath.name !== "problems"
filePaths = filePaths?.filter(
(filepath) =>
filepath.name !== "workspace" && filepath.name !== "problems"
)
const fileContents = await this.loadFileContents(filePaths)
if (fileContents) {
Expand All @@ -601,12 +601,12 @@ export class ChatService extends Base {
const lastMessageContent = `${cleanedText}\n\n${additionalContext.trim()}`
conversation.push({
role: USER,
content: lastMessageContent,
content: lastMessageContent
})
} else {
conversation.push({
...lastMessage,
content: cleanedText,
content: cleanedText
})
}
updateLoadingMessage(this._webView, "Thinking")
Expand Down Expand Up @@ -636,22 +636,22 @@ export class ChatService extends Base {
if (!skipMessage) {
this.focusChatTab()
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnLoading,
type: EVENT_NAME.twinnyOnLoading
})
this._webView?.postMessage({
type: EVENT_NAME.twinnyAddMessage,
value: {
completion: kebabToSentence(template) + "\n\n" + "```\n" + selection,
data: getLanguage(),
},
data: getLanguage()
}
} as ServerMessage)
}

const systemMessage = {
role: SYSTEM,
content: await this._templateProvider?.readSystemMessageTemplate(
this._promptTemplate
),
)
}

let ragContext = undefined
Expand All @@ -672,7 +672,7 @@ export class ChatService extends Base {

conversation.push({
role: USER,
content: userContent,
content: userContent
})

if (!provider.modelName.includes("claude")) {
Expand Down

0 comments on commit 47a0a9c

Please sign in to comment.