forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallAIFunction.swift
More file actions
31 lines (29 loc) · 1.03 KB
/
CallAIFunction.swift
File metadata and controls
31 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Foundation
import OpenAIService
/// This is a magic function that can do anything with no-code. See
/// https://github.com/Torantulino/AI-Functions for more info.
func callAIFunction(
function: String,
args: [Any?],
description: String
) async throws -> String? {
let args = args.map { arg -> String in
if let arg = arg {
return String(describing: arg)
} else {
return "None"
}
}
let argsString = args.joined(separator: ", ")
let configuration = UserPreferenceChatGPTConfiguration()
.overriding(.init(temperature: 0))
let service = ChatGPTService(
memory: AutoManagedChatGPTMemory(
systemPrompt: "You are now the following python function: ```# \(description)\n\(function)```\n\nOnly respond with your `return` value.",
configuration: configuration,
functionProvider: NoChatGPTFunctionProvider()
),
configuration: configuration
)
return try await service.sendAndWait(content: argsString)
}