Skip to content
Draft
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let package = Package(
"ElevenLabs",
"_Gemini",
"Groq",
"xAI",
"HuggingFace",
"Jina",
"Mistral",
Expand Down Expand Up @@ -150,6 +151,21 @@ let package = Package(
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.target(
name: "xAI",
dependencies: [
"CorePersistence",
"CoreMI",
"LargeLanguageModels",
"Merge",
"NetworkKit",
"Swallow"
],
path: "Sources/xAI",
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.target(
name: "Ollama",
dependencies: [
Expand Down Expand Up @@ -275,6 +291,7 @@ let package = Package(
"Mistral",
"_Gemini",
"Groq",
"xAI",
"Ollama",
"OpenAI",
"Perplexity",
Expand Down Expand Up @@ -345,6 +362,17 @@ let package = Package(
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.testTarget(
name: "xAITests",
dependencies: [
"AI",
"Swallow"
],
path: "Tests/xAI",
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.testTarget(
name: "PerplexityTests",
dependencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension ModelIdentifier {
case _Fal
case _Mistral
case _Groq
case _xAI
case _Ollama
case _OpenAI
case _Gemini
Expand Down Expand Up @@ -47,6 +48,10 @@ extension ModelIdentifier {
Self._Groq
}

public static var xAI: Self {
Self._xAI
}

public static var gemini: Self {
Self._Gemini
}
Expand Down Expand Up @@ -92,6 +97,8 @@ extension ModelIdentifier.Provider: CustomStringConvertible {
return "Mistral"
case ._Groq:
return "Groq"
case ._xAI:
return "xAI"
case ._Ollama:
return "Ollama"
case ._OpenAI:
Expand Down Expand Up @@ -129,6 +136,8 @@ extension ModelIdentifier.Provider: RawRepresentable {
return "mistral"
case ._Groq:
return "groq"
case ._xAI:
return "xai"
case ._Ollama:
return "ollama"
case ._OpenAI:
Expand Down Expand Up @@ -164,6 +173,8 @@ extension ModelIdentifier.Provider: RawRepresentable {
self = ._Mistral
case Self._Groq.rawValue:
self = ._Groq
case Self._xAI.rawValue:
self = ._xAI
case Self._OpenAI.rawValue:
self = ._OpenAI
case Self._Gemini.rawValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ extension _MIServiceTypeIdentifier {
public static let _VoyageAI = _MIServiceTypeIdentifier(rawValue: "hajat-fufoh-janaf-disam")
public static let _Cohere = _MIServiceTypeIdentifier(rawValue: "guzob-fipin-navij-duvon")
public static let _TogetherAI = _MIServiceTypeIdentifier(rawValue: "pafob-vopoj-lurig-zilur")
public static let _xAI = _MIServiceTypeIdentifier(rawValue: "niluj-futol-guhaj-pabas")
}
4 changes: 2 additions & 2 deletions Sources/ElevenLabs/Intramodular/ElevenLabs.Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension ElevenLabs.Model: CustomStringConvertible {

extension ElevenLabs.Model: ModelIdentifierRepresentable {
public init(from identifier: ModelIdentifier) throws {
guard identifier.provider == ._Groq, identifier.revision == nil else {
guard identifier.provider == ._ElevenLabs, identifier.revision == nil else {
throw Never.Reason.illegal
}

Expand All @@ -46,7 +46,7 @@ extension ElevenLabs.Model: ModelIdentifierRepresentable {

public func __conversion() -> ModelIdentifier {
ModelIdentifier(
provider: ._Groq,
provider: ._ElevenLabs,
name: rawValue,
revision: nil
)
Expand Down
144 changes: 144 additions & 0 deletions Sources/xAI/Intramodular/API/xAI.APISpecification.RequestBodies.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@


import Foundation

extension xAI.APISpecification.RequestBodies {

/* https://docs.x.ai/api/endpoints#chat-completions */
struct ChatCompletions: Codable, Hashable, Sendable {
private enum CodingKeys: String, CodingKey {
case model
case messages
case temperature
case topProbabilityMass = "top_p"
case choices = "n"
case stream
case stop
case maxTokens = "max_tokens"
case presencePenalty = "presence_penalty"
case frequencyPenalty = "frequency_penalty"
case logprobs = "logprobs"
case logitBias = "logit_bias"
case seed = "seed"
case topLogprobs = "top_logprobs"
case user
case tools
}

/* Model name for the model to use. */
var model: xAI.Model

/* A list of messages that make up the the chat conversation. Different models support different message types, such as image and text.*/
var messages: [xAI.ChatMessage]

/* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.*/
var temperature: Double?

/* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommended to alter this or `temperature` but not both.*/
var topProbabilityMass: Double?

/*The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.*/
var maxTokens: Int?

/* If set, partial message deltas will be sent. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message.*/
var stream: Bool?

/* If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.*/
var seed: Int?

/* Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. */
var frequencyPenalty: Double?

/* A JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.*/
var logitBias: [String: Int]?

/* Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message. */
var logprobs: Bool?

/* How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs. */
var choices: Int?

/* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. */
var presencePenalty: Double?

/* Up to 4 sequences where the API will stop generating further tokens. */
var stop: [String]?

/* An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. */
var topLogprobs: Int?

/* A unique identifier representing your end-user, which can help xAI to monitor and detect abuse. */
var user: String?

/* A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported. */
var tools: [xAI.Tool]?

init(
messages: [xAI.ChatMessage],
model: xAI.Model,
frequencyPenalty: Double? = nil,
logitBias: [String : Int]? = nil,
logprobs: Bool? = nil,
topLogprobs: Int? = nil,
maxTokens: Int? = nil,
choices: Int? = nil,
presencePenalty: Double? = nil,
seed: Int? = nil,
stop: [String]? = nil,
stream: Bool? = nil,
temperature: Double? = nil,
topProbabilityMass: Double? = nil,
user: String? = nil,
functions: [xAI.ChatFunctionDefinition]? = nil
) {
self.messages = messages
self.model = model
self.frequencyPenalty = frequencyPenalty
self.logitBias = logitBias
self.logprobs = logprobs
self.topLogprobs = topLogprobs
self.maxTokens = maxTokens
self.choices = choices
self.presencePenalty = presencePenalty
self.seed = seed
self.stop = stop
self.stream = stream
self.temperature = temperature
self.topProbabilityMass = topProbabilityMass
self.user = user
self.tools = functions?.map { xAI.Tool.function($0) }

}

init(
user: String?,
messages: [xAI.ChatMessage],
model: xAI.Model,
temperature: Double?,
topProbabilityMass: Double?,
choices: Int?,
stream: Bool?,
stop: [String]?,
maxTokens: Int?,
presencePenalty: Double?,
frequencyPenalty: Double?
) {
self.user = user
self.messages = messages
self.model = model
self.temperature = temperature
self.topProbabilityMass = topProbabilityMass
self.choices = choices
self.stream = stream
self.stop = stop
self.maxTokens = maxTokens
self.presencePenalty = presencePenalty
self.frequencyPenalty = frequencyPenalty

self.logitBias = nil
self.logprobs = nil
self.topLogprobs = nil
self.seed = nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import Foundation

extension xAI.APISpecification.ResponseBodies {

}
Loading
Loading