-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathxAI.APISpecification.RequestBodies.swift
More file actions
144 lines (120 loc) · 6.82 KB
/
xAI.APISpecification.RequestBodies.swift
File metadata and controls
144 lines (120 loc) · 6.82 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
}
}
}