Skip to content

Commit

Permalink
Merge pull request #389 from fishshi/main
Browse files Browse the repository at this point in the history
Revert fileContents and add meta filter
  • Loading branch information
rjmacarthy authored Nov 14, 2024
2 parents a57566c + f3cd447 commit acda4da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { CodeLanguageDetails } from "../common/languages"
import { logger } from "../common/logger"
import {
FileItem,
Message,
RequestBodyBase,
ServerMessage,
Expand Down Expand Up @@ -529,8 +530,23 @@ export class ChatService extends Base {
return combinedContext.trim() || null
}

private async loadFileContents(files: FileItem[]): Promise<string> {
if (!files?.length) return ""
let fileContents = ""
for (const file of files) {
try {
const content = await fs.readFile(file.path, "utf-8")
fileContents += `File: ${file.name}\n\n${content}\n\n`
} catch (error) {
console.error(`Error reading file ${file.path}:`, error)
}
}
return fileContents.trim()
}

public async streamChatCompletion(
messages: Message[],
filePaths: FileItem[]
) {
this._completion = ""
this.sendEditorLanguage()
Expand Down Expand Up @@ -561,6 +577,14 @@ export class ChatService extends Base {
additionalContext += `Additional Context:\n${ragContext}\n\n`
}

filePaths = filePaths.filter((filepath) =>
filepath.name !== "workspace" && filepath.name !== "problems"
)
const fileContents = await this.loadFileContents(filePaths)
if (fileContents) {
additionalContext += `File Contents:\n${fileContents}\n\n`
}

const provider = this.getProvider()

if (!provider) return
Expand Down
2 changes: 2 additions & 0 deletions src/extension/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { logger } from "../../common/logger"
import {
ApiModel,
ClientMessage,
FileItem,
InferenceRequest,
Message,
ServerMessage
Expand Down Expand Up @@ -354,6 +355,7 @@ export class BaseProvider {

this._chatService?.streamChatCompletion(
data.data || [],
data.meta as FileItem[]
)
}

Expand Down

0 comments on commit acda4da

Please sign in to comment.