forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAskChatGPT.swift
More file actions
24 lines (22 loc) · 707 Bytes
/
Copy pathAskChatGPT.swift
File metadata and controls
24 lines (22 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Foundation
import OpenAIService
/// Quickly ask a question to ChatGPT.
public func askChatGPT(
systemPrompt: String,
question: String,
temperature: Double? = nil
) async throws -> String? {
let configuration = UserPreferenceChatGPTConfiguration()
.overriding(.init(temperature: temperature))
let memory = AutoManagedChatGPTMemory(
systemPrompt: systemPrompt,
configuration: configuration,
functionProvider: NoChatGPTFunctionProvider(),
maxNumberOfMessages: .max
)
let service = LegacyChatGPTService(
memory: memory,
configuration: configuration
)
return try await service.sendAndWait(content: question)
}