You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+23-16
Original file line number
Diff line number
Diff line change
@@ -146,12 +146,17 @@ You can now use `client` as an interface to an LLM as provided by the underlying
146
146
Each AI Client supports multiple models. For example:
147
147
148
148
```swift
149
-
// OpenAI Models
149
+
// OpenAI GPT Models
150
150
let gpt_4o_Model: OpenAI.Model = .gpt_4o
151
151
let gpt_4_Model: OpenAI.Model = .gpt_4
152
152
let gpt_3_5_Model: OpenAI.Model = .gpt_3_5
153
153
let otherGPTModels: OpenAI.Model = .chat(.gpt_OTHER_MODEL_OPTIONS)
154
154
155
+
// Open AI Text Embedding Models
156
+
let smallTextEmbeddingsModel: OpenAI.Model = .embedding(.text_embedding_3_small)
157
+
let largeTextEmbeddingsModel: OpenAI.Model = .embedding(.text_embedding_3_large)
158
+
let adaTextEmbeddingsModel: OpenAI.Model = .embedding(.text_embedding_ada_002)
159
+
155
160
// Anthropic Models
156
161
let caludeHaikuModel: Anthropic.Model = .haiku
157
162
let claudeSonnetModel: Anthropic.Model = .sonnet
@@ -186,12 +191,15 @@ You can use the `LLMRequestHandling.complete(_:model:)` function to generate a c
186
191
importAI
187
192
importOpenAI
188
193
189
-
let llm: any LLMRequestHandling = OpenAI.Client(apiKey: "YOUR_KEY")
194
+
let client: any LLMRequestHandling = OpenAI.Client(apiKey: "YOUR_KEY")
195
+
196
+
// the system prompt is optional
197
+
let systemPrompt: PromptLiteral ="You are an extremely intelligent assistant."
198
+
let userPrompt: PromptLiteral ="What is the meaning of life?"
190
199
191
200
let messages: [AbstractLLM.ChatMessage] = [
192
-
// the system prompt is optional
193
-
.system(PromptLiteral("You are an extremely intelligent assistant.")),
194
-
.user(PromptLiteral("What is the meaning of life?"))
201
+
.system(systemPrompt),
202
+
.user(userPrompt)
195
203
]
196
204
197
205
// Each of these is Optional
@@ -201,14 +209,13 @@ let parameters = AbstractLLM.ChatCompletionParameters(
201
209
// controls the randomness of the result
202
210
temperatureOrTopP: .temperature(1.2),
203
211
// stop sequences that indicate to the model when to stop generating further text
204
-
stops: ["\nUser:", "\nAssistant:"],
212
+
stops: ["END OF CHAPTER"],
205
213
// check the function calling section below
206
214
functions: nil)
207
215
208
-
let model=OpenAI.Model.gpt_4o
216
+
let model: OpenAI.Model=.gpt_4o
209
217
210
218
do {
211
-
212
219
let result: String=tryawait client.complete(
213
220
messages,
214
221
parameters: parameters,
@@ -230,20 +237,20 @@ import OpenAI
230
237
231
238
let client: any LLMRequestHandling = OpenAI.Client(apiKey: "YOUR_KEY")
232
239
233
-
let systemPrompt ="You are a VisionExpertGPT. You will receive an image. Your job is to list all the items in the image and write a one-sentence poem about each item. Make sure your poems are creative, capturing the essence of each item in an evocative and imaginative way."
240
+
let systemPrompt: PromptLiteral="You are a VisionExpertGPT. You will receive an image. Your job is to list all the items in the image and write a one-sentence poem about each item. Make sure your poems are creative, capturing the essence of each item in an evocative and imaginative way."
234
241
235
-
let userPrompt ="List the items in this image and write a short one-sentence poem about each item. Only reply with the items and poems. NOTHING MORE."
242
+
let userPrompt: PromptLiteral="List the items in this image and write a short one-sentence poem about each item. Only reply with the items and poems. NOTHING MORE."
236
243
237
244
// Image or NSImage is supported
238
245
let imageLiteral =tryPromptLiteral(image: imageInput)
239
246
240
247
let model = OpenAI.Model.gpt_4o
241
248
242
249
let messages: [AbstractLLM.ChatMessage] = [
243
-
.system(PromptLiteral(systemPrompt),
250
+
.system(systemPrompt),
244
251
.user {
245
252
.concatenate(separator: nil) {
246
-
PromptLiteral(userPrompt)
253
+
userPrompt
247
254
imageLiteral
248
255
}
249
256
}]
@@ -298,13 +305,13 @@ import OpenAI
298
305
let client:any LLMRequestHandling = OpenAI.Client(apiKey: "YOUR_KEY")
299
306
300
307
// supported models (Only OpenAI Embeddings Models are supported)
301
-
let smallTextEmbeddingsModel=OpenAI.Model.embedding(.text_embedding_3_small)
302
-
let largeTextEmbeddingsModel=OpenAI.Model.embedding(.text_embedding_3_large)
303
-
let adaTextEmbeddingsModel=OpenAI.Model.embedding(.text_embedding_ada_002)
308
+
let smallTextEmbeddingsModel:OpenAI.Model=.embedding(.text_embedding_3_small)
309
+
let largeTextEmbeddingsModel:OpenAI.Model=.embedding(.text_embedding_3_large)
310
+
let adaTextEmbeddingsModel:OpenAI.Model=.embedding(.text_embedding_ada_002)
304
311
305
312
let textInput ="Hello, Text Embeddings!"
306
313
307
-
let textEmbeddingsModel=OpenAI.Model.embedding(.text_embedding_3_small)
314
+
let textEmbeddingsModel:OpenAI.Model=.embedding(.text_embedding_3_small)
308
315
309
316
let embeddings =tryawait LLMManager.client.textEmbeddings(
0 commit comments