Skip to content
Open
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions Sources/GenKit/Types/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct Service: Codable, Identifiable {
case mistral
case ollama
case openAI
case groq
case perplexity
case fal
}
Expand Down Expand Up @@ -67,6 +68,8 @@ public struct Service: Codable, Identifiable {

extension Service {

static let groqEndpoint = URL(string: "https://api.groq.com/openai/v1")!

public func modelService() throws -> ModelService {
guard let credentials else {
throw ServiceError.missingCredentials
Expand All @@ -90,6 +93,9 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token, host: Self.groqEndpoint))
case .perplexity:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return PerplexityService(configuration: .init(token: token))
Expand Down Expand Up @@ -124,6 +130,9 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token, host: Self.groqEndpoint))
case .perplexity:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return PerplexityService(configuration: .init(token: token))
Expand Down Expand Up @@ -153,6 +162,8 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
throw ServiceError.unsupportedService
case .perplexity:
throw ServiceError.unsupportedService
case .fal:
Expand Down Expand Up @@ -184,6 +195,8 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
throw ServiceError.unsupportedService
case .perplexity:
throw ServiceError.unsupportedService
case .fal:
Expand Down Expand Up @@ -212,6 +225,8 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
throw ServiceError.unsupportedService
case .perplexity:
throw ServiceError.unsupportedService
case .fal:
Expand Down Expand Up @@ -243,6 +258,9 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token, host: Self.groqEndpoint))
case .perplexity:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return PerplexityService(configuration: .init(token: token))
Expand Down Expand Up @@ -274,6 +292,8 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
throw ServiceError.unsupportedService
case .perplexity:
throw ServiceError.unsupportedService
case .fal:
Expand Down Expand Up @@ -303,6 +323,8 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
throw ServiceError.unsupportedService
case .perplexity:
throw ServiceError.unsupportedService
case .fal:
Expand Down Expand Up @@ -335,6 +357,9 @@ extension Service {
case .openAI:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token))
case .groq:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return OpenAIService(configuration: .init(token: token, host: Self.groqEndpoint))
case .perplexity:
guard let token = credentials.token else { throw ServiceError.missingCredentials }
return PerplexityService(configuration: .init(token: token))
Expand Down