Skip to content

Commit

Permalink
development > main (#399)
Browse files Browse the repository at this point in the history
* zh-CN (#397)

* translate zh-HK (#396)

* zh-HK

* zh-HK reserve sapce in the last line for linting

* add onStart and controller to review-service (#401)

* fix that empty message following timeout message (#402)

* Fix something in Chat and ChatService (#403)

* Adjust the order of save and request in handleSubmitForm

* Fix issue when filePaths is undefined.

* add locale switcher

* 3.19.7

* lint

---------

Co-authored-by: Incarnation-of-Wasted-souls <[email protected]>
Co-authored-by: fishshi <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 31b856c commit e1c9696
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

30 changes: 23 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.19.6",
"version": "3.19.7",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down Expand Up @@ -286,35 +286,51 @@
},
"markdownDescription": "Specifies which languages to enable completions with Twinny for. Use `*` as the default for all languages. Example:\n```json\n{\n \"*\": true,\n \"python\": true,\n \"javascript\": false\n}\n```"
},
"twinny.autoSuggestEnabled": {
"twinny.locale": {
"order": 2,
"type": "string",
"enum": [
"en",
"zh-CN",
"zh-HK"
],
"enumDescriptions": [
"English",
"Chinese (Simplified)",
"Chinese (Hong Kong)"
],
"default": "en",
"markdownDescription": "Sets the locale for Twinny. The default is `en` (English)."
},
"twinny.autoSuggestEnabled": {
"order": 3,
"type": "boolean",
"default": true,
"markdownDescription": "When `true`, Twinny will automatically suggest completions. You can still manually trigger completions using the default shortcut (`Alt+\\`)."
},
"twinny.contextLength": {
"order": 3,
"order": 4,
"type": "number",
"default": 100,
"markdownDescription": "Specifies how many lines of context (before and after the current line) to include in Fill-in-Middle (FIM) prompts. A higher number provides more context but may slow down completions.",
"required": true
},
"twinny.debounceWait": {
"order": 4,
"order": 5,
"type": "number",
"default": 300,
"markdownDescription": "Sets the delay (in milliseconds) before triggering the next completion. This helps reduce API calls and improve performance.",
"required": true
},
"twinny.temperature": {
"order": 5,
"order": 6,
"type": "number",
"default": 0.2,
"markdownDescription": "Controls the randomness of the model's output. Lower values (e.g., 0.2) produce more focused and deterministic outputs, while higher values (e.g., 0.8) lead to more diverse and creative completions.",
"required": true
},
"twinny.multilineCompletionsEnabled": {
"order": 6,
"order": 7,
"type": "boolean",
"default": true,
"markdownDescription": "When `true`, Twinny will attempt to generate multi-line completions. This is an experimental feature and may not work perfectly in all scenarios."
Expand All @@ -323,7 +339,7 @@
"dependencies": {
"twinny.multilineCompletionsEnabled": true
},
"order": 7,
"order": 8,
"type": "number",
"default": 30,
"markdownDescription": "Sets the maximum number of lines for multi-line completions. Only applies when `twinny.multilineCompletionsEnabled` is `true`."
Expand Down
4 changes: 3 additions & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const defaultChunkOptions = {
}

export const EVENT_NAME = {
twinntGetLocale: "twinnt-get-locale",
twinnyAcceptSolution: "twinny-accept-solution",
twinnyAddMessage: "twinny-add-message",
twinnyChat: "twinny-chat",
Expand All @@ -43,6 +44,7 @@ export const EVENT_NAME = {
twinnyConnectSymmetry: "twinny-connect-symmetry",
twinnyDisconnectedFromSymmetry: "twinny-disconnected-from-symmetry",
twinnyDisconnectSymmetry: "twinny-disconnect-symmetry",
twinnyEditDefaultTemplates: "twinny-edit-default-templates",
twinnyEmbedDocuments: "twinny-embed-documents",
twinnyEnableModelDownload: "twinny-enable-model-download",
twinnyFetchOllamaModels: "twinny-fetch-ollama-models",
Expand Down Expand Up @@ -72,11 +74,11 @@ export const EVENT_NAME = {
twinnySessionContext: "twinny-session-context",
twinnySetConfigValue: "twinny-set-config-value",
twinnySetGlobalContext: "twinny-set-global-context",
twinnySetLocale: "twinny-set-locale",
twinnySetOllamaModel: "twinny-set-ollama-model",
twinnySetSessionContext: "twinny-set-session-context",
twinnySetTab: "twinny-set-tab",
twinnySetWorkspaceContext: "twinny-set-workspace-context",
twinnyEditDefaultTemplates: "twinny-edit-default-templates",
twinnyStartSymmetryProvider: "twinny-start-symmetry-provider",
twinnyStopGeneration: "twinny-stop-generation",
twinnyStopSymmetryProvider: "twinny-stop-symmetry-provider",
Expand Down
13 changes: 5 additions & 8 deletions src/extension/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ export async function streamResponse(request: StreamRequest) {
const { signal } = controller

const timeOut = setTimeout(() => {
controller.abort()
onError?.(new Error("Request timed out"))
log.logConsoleError(
Logger.ErrorType.Timeout,
"Failed to establish connection",
new Error("Request timed out")
)
}, 25000)
controller.abort(new DOMException("Request timed out", "TimeoutError"))
}, 60000)

try {
const url = `${options.protocol}://${options.hostname}${
Expand Down Expand Up @@ -102,6 +96,9 @@ export async function streamResponse(request: StreamRequest) {
if (error instanceof Error) {
if (error.name === "AbortError") {
onEnd?.()
} else if (error.name === "TimeoutError") {
onError?.(error)
log.logConsoleError(Logger.ErrorType.Timeout, "Failed to establish connection", error)
} else {
log.logConsoleError(Logger.ErrorType.Fetch_Error, "Fetch error", error)
onError?.(error)
Expand Down
6 changes: 3 additions & 3 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class ChatService extends Base {
return combinedContext.trim() || null
}

private async loadFileContents(files: FileItem[]): Promise<string> {
private async loadFileContents(files?: FileItem[]): Promise<string> {
if (!files?.length) return ""
let fileContents = ""
for (const file of files) {
Expand All @@ -546,7 +546,7 @@ export class ChatService extends Base {

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

filePaths = filePaths.filter((filepath) =>
filePaths = filePaths?.filter((filepath) =>
filepath.name !== "workspace" && filepath.name !== "problems"
)
const fileContents = await this.loadFileContents(filePaths)
Expand Down
12 changes: 12 additions & 0 deletions src/extension/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,24 @@ export class BaseProvider {
[EVENT_NAME.twinnyFileListRequest]: this.fileListRequest,
[EVENT_NAME.twinnyNewConversation]: this.twinnyNewConversation,
[EVENT_NAME.twinnyEditDefaultTemplates]: this.editDefaultTemplates,
[EVENT_NAME.twinntGetLocale]: this.sendLocaleToWebView,
[TWINNY_COMMAND_NAME.settings]: this.openSettings
}
this.webView?.onDidReceiveMessage((message: ClientMessage<Message[]>) => {
const eventHandler = eventHandlers[message.type as string]
if (eventHandler) eventHandler(message)
})
vscode.workspace.onDidChangeConfiguration((event) => {
if (!event.affectsConfiguration("twinny")) return
this.sendLocaleToWebView()
})
}

private sendLocaleToWebView = () => {
this.webView?.postMessage({
type: EVENT_NAME.twinnySetLocale,
data: vscode.workspace.getConfiguration("twinny").get("locale") as string
})
}

private handleThemeChange = () => {
Expand Down
9 changes: 9 additions & 0 deletions src/extension/review-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getChatDataFromProvider, updateLoadingMessage } from "./utils"
export class GithubService extends ConversationHistory {
private _completion = ""
private _templateProvider: TemplateProvider
private _controller?: AbortController

constructor(
context: ExtensionContext,
Expand Down Expand Up @@ -190,6 +191,14 @@ export class GithubService extends ConversationHistory {
return streamResponse({
body: requestBody,
options: requestOptions,
onStart: (controller: AbortController) => {
this._controller = controller
this.webView?.onDidReceiveMessage((data: { type: string }) => {
if (data.type === EVENT_NAME.twinnyStopGeneration) {
this._controller?.abort()
}
})
},
onData: (streamResponse) => {
const provider = this.getProvider()
if (!provider) return
Expand Down
91 changes: 91 additions & 0 deletions src/webview/assets/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"accept-solution": "接受解决方案",
"api-key-placeholder": "在这里输入您的API密钥",
"api-key": "API密钥",
"api-path-placeholder": "输入主机名,例如 'localhost'",
"api-path": "API路径",
"applicable-ollama": "适用于Ollama等一些接口提供者",
"auto-connect-as-provider": "作为接口提供者自动连接",
"automatic": "自动化",
"cancel-edit": "取消编辑",
"cancel": "取消",
"chat": "聊天",
"clear-conversations": "清除对话",
"connect": "连接",
"connected": "已连接!",
"connecting": "正在连接...",
"connection-failed": "连接失败!请检查您的连接后重试。",
"consumer-connection": "用户连接",
"conversation-history": "对话历史",
"copy-code": "复制代码",
"copy-provider": "复制接口提供者",
"delete-message": "删除消息",
"delete-provider": "删除接口提供者",
"disconnect": "断开连接",
"edit-default-templates-description": "编辑在Twinny扩展中使用的默认模板。",
"edit-default-templates": "编辑默认模板",
"edit-message": "编辑消息",
"edit-provider": "编辑接口提供者",
"embed-documents": "嵌入文档",
"embedding-provider": "嵌入接口提供者",
"fim-template": "FIM模板",
"fim": "中间填充",
"hostname-placeholder": "输入主机名,例如 'localhost'",
"hostname": "主机名",
"label-placeholder": "为您的接口提供者输入一个标签。",
"label": "标签",
"loading-available-models": "正在加载可用模型...",
"max-chunk-size": "最大块大小",
"min-chunk-size": "最小块大小",
"model-name-placeholder": "输入模型名称,例如 'llama3'",
"model-name": "模型名称",
"new-conversation": "新对话",
"new-document": "新文档",
"no-connections-found": "未找到连接。请添加新连接以开始。",
"no-result": "无结果",
"nothing-to-see-here": "这里没什么可看的。",
"number-code-filepaths": "用作上下文的文件路径数量。",
"number-code-snippets": "用作上下文的代码片段数量。",
"open-diff": "打开差异比较视图",
"open-template-editor": "打开模板编辑器",
"overlap-size": "重叠大小",
"owner-repo-name": "此标签将帮助您审查您的存储库中的拉取请求,输入下面的所有者和存储库名称以开始。目前仅支持GitHub,请在设置标签中设置您的GitHub令牌以开始。",
"path": "路径",
"placeholder": "Twinny今天能怎么帮助您?",
"port-placeholder": "输入端口号,例如 '11434'",
"port": "端口",
"protocol": "协议",
"provider-connection": "接口提供者连接",
"provider-name": "接口提供者名称",
"provider-placeholder": "输入接口提供者名称",
"provider-type": "接口提供者类型",
"provider": "接口提供者",
"providers": "接口提供者们",
"pull-requests": "拉取请求",
"regenerate-message": "重新生成消息",
"relevant-code-snippets": "相关代码片段",
"relevant-file-paths": "相关文件路径",
"repository-level": "存储库级别",
"rerank-probability-threshold": "重新排名概率阈值",
"rerank-threshold-description": "阈值越低,结果越有可能被包含。",
"rerank-threshold": "重新排名阈值",
"reset-providers": "重置接口提供者",
"reset-to-default": "重置为默认",
"review-pull-requests": "审查拉取请求",
"save-edit": "保存编辑",
"save": "保存",
"scroll-down": "滚动到底部",
"share-gpu-resources": "您也可以通过使用您的活跃Twinny接口提供者配置作为接口提供者连接到Symmetry来共享您的GPU资源。所有连接都是点对点的,端到端加密且安全的。",
"status": "状态",
"stop-generation": "停止生成",
"symmetry-description": "Symmetry是一个点对点AI推理网络,允许用户之间进行安全、直接的连接。当您作为消费者连接时,Symmetry会根据您的模型选择为您匹配接口提供者。",
"symmetry-inference-network": "Symmetry推理网络",
"template-settings-description": "选择您想要在聊天界面中使用的模板。",
"template-settings": "模板设置",
"thinking": "思考中...",
"toggle-auto-scroll": "开启/关闭自动滚动",
"toggle-embedding-options": "开启/关闭嵌入选项",
"toggle-provider-selection": "开启/关闭接口提供者选择",
"type": "类型"
}

Loading

0 comments on commit e1c9696

Please sign in to comment.