Skip to content

Commit

Permalink
mention file context and large clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Sep 6, 2024
1 parent e28fc1d commit 1b4a90c
Show file tree
Hide file tree
Showing 45 changed files with 1,143 additions and 1,077 deletions.
18 changes: 0 additions & 18 deletions scripts/install_onyx_model.sh

This file was deleted.

3 changes: 2 additions & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const EVENT_NAME = {
twinnySetWorkspaceContext: 'twinny-set-workspace-context',
twinnyStopGeneration: 'twinny-stop-generation',
twinnyTextSelection: 'twinny-text-selection',
twinnyWorkspaceContext: 'twinny-workspace-context'
twinnyGetWorkspaceContext: 'twinny-workspace-context'
}

export const TWINNY_COMMAND_NAME = {
Expand All @@ -95,6 +95,7 @@ export const TWINNY_COMMAND_NAME = {
manageProviders: 'twinny.manageProviders',
manageTemplates: 'twinny.manageTemplates',
newConversation: 'twinny.newConversation',
openPanelChat: 'twinny.openPanelChat',
openChat: 'twinny.openChat',
refactor: 'twinny.refactor',
sendTerminalText: 'twinny.sendTerminalText',
Expand Down
66 changes: 33 additions & 33 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface StreamResponse {
prompt_eval_duration: number
eval_count: number
eval_duration: number
type? : string
type?: string
choices: [
{
text: string
Expand All @@ -60,8 +60,8 @@ export interface LanguageType {
}

export interface ClientMessage<T = string | boolean | Message[], Y = unknown> {
data?: T,
meta?: Y,
data?: T
meta?: Y
type?: string
key?: string
}
Expand Down Expand Up @@ -150,7 +150,7 @@ export interface StreamRequest {
onEnd?: () => void
onStart?: (controller: AbortController) => void
onError?: (error: Error) => void
onData: <T = StreamResponse>(streamResponse: T) => void
onData: <T = StreamResponse>(streamResponse: T) => void
}

export interface UiTabs {
Expand Down Expand Up @@ -216,47 +216,47 @@ export interface InferenceProvider {
}

export interface Peer {
publicKey: Buffer;
write: (value: string) => boolean;
on: (key: string, cb: (data: Buffer) => void) => void;
once: (key: string, cb: (data: Buffer) => void) => void;
writable: boolean;
key: string;
discovery_key: string;
publicKey: Buffer
write: (value: string) => boolean
on: (key: string, cb: (data: Buffer) => void) => void
once: (key: string, cb: (data: Buffer) => void) => void
writable: boolean
key: string
discovery_key: string
}

export interface SymmetryMessage<T> {
key: string;
data: T;
key: string
data: T
}

export type ServerMessageKey = keyof typeof SYMMETRY_DATA_MESSAGE;
export type ServerMessageKey = keyof typeof SYMMETRY_DATA_MESSAGE

export interface SymmetryConnection {
sessionToken?: string
discoveryKey?: string
modelName?: string
name: string;
provider: string;
id: string;
name: string
provider: string
id: string
}

export interface SymmetryModelProvider {
connections: number | null;
data_collection_enabled: number;
id: number;
last_seen: string;
max_connections: number;
model_name: string;
name: string;
online: number;
provider: string;
public: number;
connections: number | null
data_collection_enabled: number
id: number
last_seen: string
max_connections: number
model_name: string
name: string
online: number
provider: string
public: number
}

export interface InferenceRequest {
key: string;
messages: Message[];
key: string
messages: Message[]
}

export interface ChunkOptions {
Expand All @@ -276,11 +276,11 @@ export type EmbeddedDocument = {
}

export interface FileItem {
name: string;
path: string;
name: string
path: string
}

export interface MentionType {
name: string;
path: string;
name: string
path: string
}
15 changes: 15 additions & 0 deletions src/extension.global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ declare module 'hypercore-crypto' {

export = hyperCoreCrypto
}

declare module '*.css'

declare module '*.css' {
const content: Record<string, string>
export default content
}

interface Window {
acquireVsCodeApi: <T = unknown>() => {
getState: () => T
setState: (data: T) => void
postMessage: (msg: unknown) => void
}
}
32 changes: 16 additions & 16 deletions src/extension/cache.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { PrefixSuffix } from '../common/types'

export class LRUCache<T = string> {
private capacity: number
private cache: Map<string, T | null>
private _capacity: number
private _cache: Map<string, T | null>

constructor(capacity: number) {
this.capacity = capacity
this.cache = new Map()
this._capacity = capacity
this._cache = new Map()
}

getAll(): Map<string, T | null> {
return this.cache
return this._cache
}

get(key: string): T | null | undefined {
if (!this.cache.has(key)) return undefined
if (!this._cache.has(key)) return undefined

const value = this.cache.get(key)
this.cache.delete(key)
const value = this._cache.get(key)
this._cache.delete(key)
if (value !== undefined) {
this.cache.set(key, value)
this._cache.set(key, value)
}
return value
}

delete(key: string): void {
this.cache.delete(key)
this._cache.delete(key)
}

set(key: string, value: T | null): void {
if (this.cache.has(key)) {
this.cache.delete(key)
} else if (this.cache.size === this.capacity) {
const firstKey = this.cache.keys().next().value
this.cache.delete(firstKey)
if (this._cache.has(key)) {
this._cache.delete(key)
} else if (this._cache.size === this._capacity) {
const firstKey = this._cache.keys().next().value
this._cache.delete(firstKey)
}
this.cache.set(key, value)
this._cache.set(key, value)
}

normalize(src: string): string {
Expand Down
45 changes: 23 additions & 22 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
StatusBarItem,
WebviewView,
commands,
window,
workspace,
ExtensionContext,
languages,
DiagnosticSeverity
DiagnosticSeverity,
Webview
} from 'vscode'
import * as path from 'path'
import * as fs from 'fs/promises'
Expand Down Expand Up @@ -67,19 +67,19 @@ export class ChatService {
private _symmetryService?: SymmetryService
private _temperature = this._config.get('temperature') as number
private _templateProvider?: TemplateProvider
private _view?: WebviewView
private _sessionManager: SessionManager
private _webView?: Webview
private _sessionManager: SessionManager | undefined

constructor(
statusBar: StatusBarItem,
templateDir: string,
templateDir: string | undefined,
extensionContext: ExtensionContext,
view: WebviewView,
webView: Webview,
db: EmbeddingDatabase | undefined,
sessionManager: SessionManager,
sessionManager: SessionManager | undefined,
symmetryService: SymmetryService
) {
this._view = view
this._webView = webView
this._statusBar = statusBar
this._templateProvider = new TemplateProvider(templateDir)
this._reranker = new Reranker()
Expand All @@ -101,7 +101,7 @@ export class ChatService {
this._symmetryService?.on(
SYMMETRY_EMITTER_KEY.inference,
(completion: string) => {
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnCompletion,
value: {
completion: completion.trimStart(),
Expand Down Expand Up @@ -345,7 +345,7 @@ export class ChatService {
const data = getChatDataFromProvider(provider.provider, streamResponse)
this._completion = this._completion + data
if (onEnd) return
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnCompletion,
value: {
completion: this._completion.trimStart(),
Expand All @@ -368,12 +368,12 @@ export class ChatService {
)
if (onEnd) {
onEnd(this._completion)
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd
} as ServerMessage)
return
}
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd,
value: {
completion: this._completion.trimStart(),
Expand All @@ -384,7 +384,7 @@ export class ChatService {
}

private onStreamError = (error: Error) => {
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd,
value: {
error: true,
Expand All @@ -400,7 +400,7 @@ export class ChatService {
EXTENSION_CONTEXT_NAME.twinnyGeneratingText,
true
)
this._view?.webview.onDidReceiveMessage((data: { type: string }) => {
this._webView?.onDidReceiveMessage((data: { type: string }) => {
if (data.type === EVENT_NAME.twinnyStopGeneration) {
this._controller?.abort()
}
Expand All @@ -415,7 +415,7 @@ export class ChatService {
EXTENSION_CONTEXT_NAME.twinnyGeneratingText,
true
)
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd,
value: {
completion: this._completion.trimStart(),
Expand Down Expand Up @@ -466,7 +466,7 @@ export class ChatService {
}

private sendEditorLanguage = () => {
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnySendLanguage,
value: {
data: getLanguage()
Expand All @@ -475,7 +475,7 @@ export class ChatService {
}

private focusChatTab = () => {
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnySetTab,
value: {
data: WEBUI_TABS.chat
Expand Down Expand Up @@ -514,7 +514,7 @@ export class ChatService {

const problemsMentioned = text?.includes('@problems')

const ragContextKey = `${EVENT_NAME.twinnyWorkspaceContext}-${EXTENSION_CONTEXT_NAME.twinnyEnableRag}`
const ragContextKey = `${EVENT_NAME.twinnyGetWorkspaceContext}-${EXTENSION_CONTEXT_NAME.twinnyEnableRag}`
const isRagEnabled = this._context?.workspaceState.get(ragContextKey)

if (symmetryConnected) return null
Expand All @@ -532,7 +532,7 @@ export class ChatService {
let relevantCode: string | null = ''

if (workspaceMentioned || isRagEnabled) {
updateLoadingMessage(this._view, 'Exploring knowledge base')
updateLoadingMessage(this._webView, 'Exploring knowledge base')
relevantFiles = await this.getRelevantFiles(prompt)
relevantCode = await this.getRelevantCode(prompt, relevantFiles)
}
Expand All @@ -559,6 +559,7 @@ export class ChatService {
}

private async loadFileContents(files: FileItem[]): Promise<string> {
if (!files?.length) return ''
let fileContents = '';

for (const file of files) {
Expand Down Expand Up @@ -622,7 +623,7 @@ export class ChatService {
content: cleanedText
})
}
updateLoadingMessage(this._view, 'Thinking')
updateLoadingMessage(this._webView, 'Thinking')
const request = this.buildStreamRequest(updatedMessages)
if (!request) return
const { requestBody, requestOptions } = request
Expand All @@ -648,10 +649,10 @@ export class ChatService {

if (!skipMessage) {
this.focusChatTab()
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinnyOnLoading
})
this._view?.webview.postMessage({
this._webView?.postMessage({
type: EVENT_NAME.twinngAddMessage,
value: {
completion: kebabToSentence(template) + '\n\n' + '```\n' + selection,
Expand Down
Loading

0 comments on commit 1b4a90c

Please sign in to comment.