-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
Tested following code on OpenRouter and it seems like it is not able to pick up any reasoning. Am I doing something wrong or is it a bug?
import Foundation
import SwiftOpenAI
Task {
let apiKey = "api-key"
let service = OpenAIServiceFactory.service(
apiKey: apiKey,
overrideBaseURL: "https://openrouter.ai",
proxyPath: "api",
)
let prompt = "What is the Manhattan project?"
let parameters = ChatCompletionParameters(
messages: [.init(role: .user, content: .text(prompt))],
model: .custom("google/gemini-2.5-pro")
)
var message = ""
var reasoningMessage = ""
var errorMessage: String? = nil
// Start the stream
do {
let stream = try await service.startStreamedChat(parameters: parameters)
for try await result in stream {
if let choice = result.choices?.first {
if let content = choice.delta?.content {
print("Message: \(content)")
message += content
}
if let reasoning = choice.delta?.reasoningContent {
print("Reasoning: \(reasoning)")
reasoningMessage += reasoning
}
}
}
print("Message: \(message)")
print("Reasoning: \(reasoningMessage)")
} catch APIError.responseUnsuccessful(let description, let statusCode) {
errorMessage = "Network error with status code: \(statusCode) and description: \(description)"
print(errorMessage!)
} catch {
errorMessage = error.localizedDescription
print(errorMessage!)
}
}
// Keep the program alive
RunLoop.main.run()
Metadata
Metadata
Assignees
Labels
No labels