Skip to content

Commit

Permalink
style: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jul 18, 2024
1 parent 5c29152 commit ff3a8e2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/cz-commitlint": "^19.2.0",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"@langchain/core": "0.2.16",
"@langchain/openai": "^0.2.3",
"@langchain/core": "0.2.17",
"@langchain/openai": "^0.2.4",
"@types/fs-extra": "^11.0.4",
"@types/global-agent": "^2.1.3",
"@types/node": "^20.14.11",
Expand Down Expand Up @@ -286,7 +286,7 @@
},
"pnpm": {
"overrides": {
"@langchain/core": "0.2.16"
"@langchain/core": "0.2.17"
}
},
"commitlint": {
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 19 additions & 13 deletions src/ai/model-providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,31 @@ export abstract class BaseModelProvider<Model extends BaseChatModel> {
return prompt
}

async getHistory(
sessionId: string,
appendHistoryMessages?: BaseMessage[]
): Promise<InMemoryChatMessageHistory> {
if (BaseModelProvider.sessionIdHistoriesMap[sessionId] === undefined) {
const messageHistory = new InMemoryChatMessageHistory()

if (appendHistoryMessages && appendHistoryMessages.length > 0) {
await messageHistory.addMessages(appendHistoryMessages)
}

BaseModelProvider.sessionIdHistoriesMap[sessionId] = messageHistory
}

return BaseModelProvider.sessionIdHistoriesMap[sessionId]!
}

createRunnableWithMessageHistory<Chunk extends AIMessageChunk>(
chain: Runnable<any, Chunk, RunnableConfig>,
historyMessages: BaseMessage[]
) {
return new RunnableWithMessageHistory({
runnable: chain,
getMessageHistory: async sessionId => {
if (BaseModelProvider.sessionIdHistoriesMap[sessionId] === undefined) {
const messageHistory = new InMemoryChatMessageHistory()

if (historyMessages.length > 0) {
await messageHistory.addMessages(historyMessages)
}

BaseModelProvider.sessionIdHistoriesMap[sessionId] = messageHistory
}

return BaseModelProvider.sessionIdHistoriesMap[sessionId]!
},
getMessageHistory: async sessionId =>
await this.getHistory(sessionId, historyMessages),
inputMessagesKey: 'input',
historyMessagesKey: 'history'
})
Expand Down
11 changes: 5 additions & 6 deletions src/commands/smart-paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { getFileOrFoldersPromptInfo } from '@/file-utils/get-fs-prompt-info'
import { insertTextAtSelection } from '@/file-utils/insert-text-at-selection'
import { streamingCompletionWriter } from '@/file-utils/stream-completion-writer'
import { logger } from '@/logger'
import { getCurrentWorkspaceFolderEditor } from '@/utils'
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base'
import type { RunnableConfig } from '@langchain/core/runnables'
Expand Down Expand Up @@ -43,11 +42,11 @@ const buildConvertPrompt = async ({
const { promptFullContent: referenceFileContent } =
await getFileOrFoldersPromptInfo(referencePaths, workspaceFolder.uri.fsPath)

logger.log('smart-paste', {
referencePaths,
currentFileRelativePath,
clipboardContent
})
// console.log('smart-paste', {
// referencePaths,
// currentFileRelativePath,
// clipboardContent
// })

const prompt = `
I will provide the content of the current file, as well as the content of several most useful files related to the currently edited file, to you.
Expand Down
2 changes: 1 addition & 1 deletion src/enable-global-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const enableGlobalProxy = () => {
setGlobalDispatcher(dispatcher)
}
} catch (err) {
logger.log('Failed to enable global proxy', err)
logger.warn('Failed to enable global proxy', err)
}
}

Expand Down

0 comments on commit ff3a8e2

Please sign in to comment.