Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
e9a1f72
Add top bar to prompt to code panel
intitni Aug 23, 2023
cbf25db
Support detaching prompt to code from selection range
intitni Aug 23, 2023
832d7b7
Add a command dedicated to accept prompt to code suggestion
intitni Aug 23, 2023
22019c5
Move FocusedCodeFinder to Tool
intitni Aug 23, 2023
9090237
Add focusedEditorContent to XcodeInspector
intitni Aug 24, 2023
ebaebb3
Add attach to code to prompt to code service
intitni Aug 24, 2023
33f4d78
Update prompt to code
intitni Aug 24, 2023
18203a5
Change re-attach to attach to the initial selection range
intitni Aug 25, 2023
cf3a879
Migrate prompt to code to use TCA
intitni Aug 25, 2023
a5e0935
Hook up the service
intitni Aug 26, 2023
07b1c96
Setup promptToCodeAcceptHandler
intitni Aug 26, 2023
0baa394
Fix accepting when detached
intitni Aug 26, 2023
9402028
Disable text field when responding
intitni Aug 26, 2023
e8b8fbd
Add animation to toggle
intitni Aug 26, 2023
acd7965
Merge branch 'feature/prompt-to-code-detach' into develop
intitni Aug 26, 2023
b75cbcf
Update
intitni Aug 26, 2023
34e6cee
Merge branch 'main' into develop
intitni Aug 26, 2023
ecb962c
Support command+l to focus on chat tab input field
intitni Aug 28, 2023
2f0be3f
Fix keyboard shortcut conflicts in chat tabs
intitni Aug 28, 2023
8171174
Merge branch 'feature/commnad-l-to-focus' into develop
intitni Aug 28, 2023
34ecb5d
Add a tiny reject/close button to compact suggestion panel
intitni Aug 28, 2023
91980c0
Support Codeium enterprise
intitni Aug 28, 2023
b526087
Merge branch 'feature/codeium-enterprise' into develop
intitni Aug 28, 2023
b504b9b
Update chat tab to build it's own tab item
intitni Aug 28, 2023
22c8056
Support editing bookmark
intitni Aug 28, 2023
45581f8
Support reordering bookmarks
intitni Aug 28, 2023
dcc56b4
Split chat tab item and menu
intitni Aug 29, 2023
4a589e7
Update browser tab
intitni Aug 29, 2023
b9de177
Fix warnings
intitni Aug 29, 2023
87c2339
Make RealtimeSuggestionController an actor
intitni Sep 1, 2023
2046e85
Merge tag '0.22.3' into develop
intitni Sep 2, 2023
b639bbc
Update
intitni Sep 2, 2023
c6a870a
Migrate extension service to use new way to setup model
intitni Sep 1, 2023
bdb8ee0
WIP
intitni Sep 1, 2023
6efa867
Change migrate version
intitni Sep 2, 2023
1c6af3f
Add apiKey Keychain
intitni Sep 2, 2023
012d188
Add chat model management view
intitni Sep 2, 2023
7050a2e
Add chat model and embedding model settings view
intitni Sep 3, 2023
51a45c7
Fix Keychain.getAll, change scope implementation
intitni Sep 4, 2023
7cb8e6e
Fix migrateTo240 to apply even if the settings already has a default …
intitni Sep 4, 2023
70a1ab6
Add test to test plan
intitni Sep 4, 2023
fb8470b
Fix
intitni Sep 4, 2023
fdf5256
Remove the scroll view wrapper
intitni Sep 4, 2023
c8e720c
Adjust AIModelManagementView style
intitni Sep 4, 2023
40eba80
Sort api key names
intitni Sep 4, 2023
60cfdf4
Adjust implementation of text field with picker
intitni Sep 4, 2023
80a03d0
Trim white spaces and newlines from suggested base urls
intitni Sep 4, 2023
3bce5a8
Trim whitespaces and newlines
intitni Sep 4, 2023
90b72d1
Fix max token display
intitni Sep 4, 2023
2346fad
Update chat settings to use new models
intitni Sep 4, 2023
8dc12f0
Add support to store api keys in user defaults
intitni Sep 4, 2023
bc43b91
Disable function calling for models that don't support it
intitni Sep 4, 2023
de604b1
Remove AzureView and OpenAIView
intitni Sep 4, 2023
192d3be
Remove unused dependency
intitni Sep 4, 2023
3675e8a
Pass configuration to DynamicContextController
intitni Sep 4, 2023
eb42acd
Add feature flag
intitni Sep 4, 2023
3267270
Update target dependency
intitni Sep 4, 2023
95b5b84
Fix default max tokens for embedding models
intitni Sep 4, 2023
5ef37ab
Merge branch 'feature/new-way-to-setup-models' into develop
intitni Sep 4, 2023
eb8a5ea
Update
intitni Sep 4, 2023
06a98fd
Fix accepting suggestions from the middle of a line
intitni Sep 4, 2023
6a7cab7
Merge branch 'feature/fix-suggestion-acception-0904' into develop
intitni Sep 4, 2023
da44c76
Reimplement suffix recovering
intitni Sep 4, 2023
205c9b3
Remove the first adjacent placeholder when accepting suggestions
intitni Sep 4, 2023
e17bdd4
Update
intitni Sep 5, 2023
2486200
Remove existed chat tabs before restoring
intitni Sep 5, 2023
2815292
Fix suggestion panel position Y
intitni Sep 5, 2023
6a690f7
Adjust prompt to code panel
intitni Sep 5, 2023
d89e949
Fix system promt
intitni Sep 5, 2023
efcaa94
Change api of PromptToCodeServiceType
intitni Sep 6, 2023
ecd74a8
Pass line annotations to prompt to code service
intitni Sep 6, 2023
8f9bc5c
Support indentation recovering in prompt to code service
intitni Sep 6, 2023
4fddb24
Merge branch 'feature/prompt-to-code-with-line-annotation' into develop
intitni Sep 6, 2023
7225b05
Bump version to 0.23.0
intitni Sep 6, 2023
7b61ab8
Adjust transitions
intitni Sep 6, 2023
c591718
Make every field of CompletionStreamDataTrunk optional
intitni Sep 6, 2023
dc0b117
If there is no selection, automatically detach
intitni Sep 6, 2023
0fa3fac
Update README.md
intitni Sep 6, 2023
b7017e4
Update DEVELOPMENT.md
intitni Sep 6, 2023
1fed399
Fix prompt
intitni Sep 6, 2023
8ba71c5
Update
intitni Sep 6, 2023
03fcec5
Add debug buttons
intitni Sep 6, 2023
350a91d
Tweak base url picker
intitni Sep 6, 2023
b2b6bf0
Make Xcode active when cancelling prompt to code
intitni Sep 6, 2023
c0746aa
Update appcast
intitni Sep 6, 2023
f91cbe5
Merge branch 'release/0.23.0'
intitni Sep 6, 2023
5db1cf2
Fix unit test
intitni Sep 6, 2023
a964bf6
Adjust selection text
intitni Sep 6, 2023
d06f430
Bump version to 0.23.1
intitni Sep 6, 2023
cbe4dc2
Update appcast.xml
intitni Sep 6, 2023
919a60c
Merge branch 'hotfix/fix-tests'
intitni Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change api of PromptToCodeServiceType
  • Loading branch information
intitni committed Sep 6, 2023
commit efcaa94d9b58953579059523a3bb2db86d26bb9a
51 changes: 33 additions & 18 deletions Core/Sources/PromptToCodeService/OpenAIPromptToCodeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Foundation
import OpenAIService
import Preferences
import SuggestionModel
import XcodeInspector

public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
var service: (any ChatGPTServiceType)?

public init() {}

public func stopResponding() {
Expand All @@ -14,13 +15,9 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {

public func modifyCode(
code: String,
language: CodeLanguage,
indentSize: Int,
usesTabsForIndentation: Bool,
requirement: String,
projectRootURL: URL,
fileURL: URL,
allCode: String,
source: PromptToCodeSource,
isDetached: Bool,
extraSystemPrompt: String?,
generateDescriptionRequirement: Bool?
) async throws -> AsyncThrowingStream<(code: String, description: String), Error> {
Expand All @@ -34,6 +31,22 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
return userPreferredLanguage.isEmpty ? "" : " in \(userPreferredLanguage)"
}()

let editor: EditorInformation = XcodeInspector.shared.focusedEditorContent ?? .init(
editorContent: .init(
content: source.allCode,
lines: [],
selections: [source.range],
cursorPosition: .outOfScope,
lineAnnotations: []
),
selectedContent: code,
selectedLines: [],
documentURL: source.documentURL,
projectURL: source.projectRootURL,
relativePath: "",
language: source.language
)

let rule: String = {
func generateDescription(index: Int) -> String {
let generateDescription = generateDescriptionRequirement ?? UserDefaults.shared
Expand All @@ -46,7 +59,7 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
"""
: "\(index). Reply with the result."
}
switch language {
switch editor.language {
case .builtIn(.markdown), .plaintext:
if code.isEmpty {
return """
Expand Down Expand Up @@ -82,20 +95,20 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
}()

let systemPrompt = {
switch language {
switch editor.language {
case .builtIn(.markdown), .plaintext:
if code.isEmpty {
return """
You are good at writing in \(language.rawValue).
The active file is: \(fileURL.lastPathComponent).
You are good at writing in \(editor.language.rawValue).
The active file is: \(editor.documentURL.lastPathComponent).
\(extraSystemPrompt ?? "")

\(rule)
"""
} else {
return """
You are good at writing in \(language.rawValue).
The active file is: \(fileURL.lastPathComponent).
You are good at writing in \(editor.language.rawValue).
The active file is: \(editor.documentURL.lastPathComponent).
\(extraSystemPrompt ?? "")

\(rule)
Expand All @@ -104,16 +117,16 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
default:
if code.isEmpty {
return """
You are a senior programer in writing in \(language.rawValue).
The active file is: \(fileURL.lastPathComponent).
You are a senior programer in writing in \(editor.language.rawValue).
The active file is: \(editor.documentURL.lastPathComponent).
\(extraSystemPrompt ?? "")

\(rule)
"""
} else {
return """
You are a senior programer in writing in \(language.rawValue).
The active file is: \(fileURL.lastPathComponent).
You are a senior programer in writing in \(editor.language.rawValue).
The active file is: \(editor.documentURL.lastPathComponent).
\(extraSystemPrompt ?? "")

\(rule)
Expand All @@ -125,6 +138,7 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
let firstMessage: String? = {
if code.isEmpty { return nil }
switch language {
switch editor.language {
case .builtIn(.markdown), .plaintext:
return """
```
Expand Down Expand Up @@ -161,9 +175,10 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
if let firstMessage {
await memory.mutateHistory { history in
history.append(.init(role: .user, content: firstMessage))
history.append(.init(role: .assistant, content: secondMessage))
}
}
let stream = try await chatGPTService.send(content: secondMessage)
let stream = try await chatGPTService.send(content: requirement)
return .init { continuation in
Task {
var content = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ public final class PreviewPromptToCodeService: PromptToCodeServiceType {

public func modifyCode(
code: String,
language: CodeLanguage,
indentSize: Int,
usesTabsForIndentation: Bool,
requirement: String,
projectRootURL: URL,
fileURL: URL,
allCode: String,
source: PromptToCodeSource,
isDetached: Bool,
extraSystemPrompt: String?,
generateDescriptionRequirement: Bool?
) async throws -> AsyncThrowingStream<(code: String, description: String), Error> {
Expand Down
30 changes: 24 additions & 6 deletions Core/Sources/PromptToCodeService/PromptToCodeServiceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,38 @@ import SuggestionModel
public protocol PromptToCodeServiceType {
func modifyCode(
code: String,
language: CodeLanguage,
indentSize: Int,
usesTabsForIndentation: Bool,
requirement: String,
projectRootURL: URL,
fileURL: URL,
allCode: String,
source: PromptToCodeSource,
isDetached: Bool,
extraSystemPrompt: String?,
generateDescriptionRequirement: Bool?
) async throws -> AsyncThrowingStream<(code: String, description: String), Error>

func stopResponding()
}

public struct PromptToCodeSource {
public var language: CodeLanguage
public var documentURL: URL
public var projectRootURL: URL
public var allCode: String
public var range: CursorRange

public init(
language: CodeLanguage,
documentURL: URL,
projectRootURL: URL,
allCode: String,
range: CursorRange
) {
self.language = language
self.documentURL = documentURL
self.projectRootURL = projectRootURL
self.allCode = allCode
self.range = range
}
}

public struct PromptToCodeServiceDependencyKey: DependencyKey {
public static let liveValue: PromptToCodeServiceType = PreviewPromptToCodeService()
public static let previewValue: PromptToCodeServiceType = PreviewPromptToCodeService()
Expand Down
14 changes: 8 additions & 6 deletions Core/Sources/Service/GUI/ChatTabFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ enum ChatTabFactory {

let result = try await service.modifyCode(
code: prompt,
language: .plaintext,
indentSize: 4,
usesTabsForIndentation: true,
requirement: instruction ?? "Modify content.",
projectRootURL: .init(fileURLWithPath: "/"),
fileURL: .init(fileURLWithPath: "/"),
allCode: prompt,
source: .init(
language: .plaintext,
documentURL: .init(fileURLWithPath: "/"),
projectRootURL: .init(fileURLWithPath: "/"),
allCode: prompt,
range: .outOfScope
),
isDetached: true,
extraSystemPrompt: extraSystemPrompt,
generateDescriptionRequirement: false
)
Expand Down
16 changes: 9 additions & 7 deletions Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public struct PromptToCode: ReducerProtocol {
@BindingState public var prompt: String
@BindingState public var isContinuous: Bool
@BindingState public var isAttachedToSelectionRange: Bool

public var filename: String { documentURL.lastPathComponent }
public var canRevert: Bool { history != .empty }

Expand Down Expand Up @@ -156,13 +156,15 @@ public struct PromptToCode: ReducerProtocol {
do {
let stream = try await promptToCodeService.modifyCode(
code: copiedState.code,
language: copiedState.language,
indentSize: copiedState.indentSize,
usesTabsForIndentation: copiedState.usesTabsForIndentation,
requirement: copiedState.prompt,
projectRootURL: copiedState.projectRootURL,
fileURL: copiedState.documentURL,
allCode: copiedState.allCode,
source: .init(
language: copiedState.language,
documentURL: copiedState.documentURL,
projectRootURL: copiedState.projectRootURL,
allCode: copiedState.allCode,
range: copiedState.selectionRange ?? .outOfScope
),
isDetached: !copiedState.isAttachedToSelectionRange,
extraSystemPrompt: copiedState.extraSystemPrompt,
generateDescriptionRequirement: copiedState
.generateDescriptionRequirement
Expand Down