Bläddra i källkod

Continue search in same chat stream.

Pass recent chat messages into the job search request so follow-up queries keep conversational context instead of acting like a fresh chat.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 3 veckor sedan
förälder
incheckning
37771add99
1 ändrade filer med 21 tillägg och 3 borttagningar
  1. 21 3
      App for Indeed/Views/DashboardView.swift

+ 21 - 3
App for Indeed/Views/DashboardView.swift

@@ -1203,7 +1203,8 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1203 1203
         isAwaitingResponse = true
1204 1204
         chatStatusLabel.stringValue = "Thinking..."
1205 1205
         setInputEnabled(false)
1206
-        jobSearchService.searchJobs(query: prompt) { [weak self] result in
1206
+        let contextMessages = chatMessages
1207
+        jobSearchService.searchJobs(query: prompt, conversation: contextMessages) { [weak self] result in
1207 1208
             DispatchQueue.main.async {
1208 1209
                 guard let self else { return }
1209 1210
                 self.isAwaitingResponse = false
@@ -1556,7 +1557,7 @@ private final class OpenAIJobSearchService {
1556 1557
     private let endpoint = URL(string: "https://api.openai.com/v1/responses")!
1557 1558
     private let session = URLSession(configuration: .ephemeral)
1558 1559
 
1559
-    func searchJobs(query: String, completion: @escaping (Result<JobSearchOutput, Error>) -> Void) {
1560
+    func searchJobs(query: String, conversation: [ChatMessage], completion: @escaping (Result<JobSearchOutput, Error>) -> Void) {
1560 1561
         let apiKey = OpenAIConfiguration.apiKey
1561 1562
         guard OpenAIConfiguration.hasAPIKey else {
1562 1563
             completion(.failure(NSError(
@@ -1573,8 +1574,25 @@ private final class OpenAIJobSearchService {
1573 1574
         request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
1574 1575
         request.timeoutInterval = 45
1575 1576
 
1577
+        let recentContext = conversation.suffix(8)
1578
+            .map { "\($0.role.uppercased()): \($0.content)" }
1579
+            .joined(separator: "\n")
1580
+        let contextBlock: String
1581
+        if recentContext.isEmpty {
1582
+            contextBlock = "No prior conversation context."
1583
+        } else {
1584
+            contextBlock = recentContext
1585
+        }
1586
+
1576 1587
         let instructions = """
1577
-        Search the web for currently available jobs related to this role query: "\(query)".
1588
+        Continue this same job-search conversation. Use prior context when useful, and prioritize the latest user query.
1589
+
1590
+        Conversation context:
1591
+        \(contextBlock)
1592
+
1593
+        Latest user query: "\(query)"
1594
+
1595
+        Search the web for currently available jobs related to the latest query (and relevant context above).
1578 1596
         Return ONLY strict JSON that matches this schema:
1579 1597
         {
1580 1598
           "jobs": [