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
PerplexityApiSwift is a Swift framework that provides a convenient wrapper for the Perplexity AI API. This framework simplifies the process of making chat completion requests to Perplexity's advanced language models.
4
13
5
14
## Features
@@ -9,31 +18,53 @@ PerplexityApiSwift is a Swift framework that provides a convenient wrapper for t
9
18
- Asynchronous API calls using Swift's modern concurrency features
10
19
- Built-in error handling for common API issues
11
20
12
-
## Quick Start
21
+
## Basic usage
22
+
23
+
To use PerplexityApiSwift, you need to create an instance of `PerplexityAPI` with your API token and then make chat completion requests. Here's a basic example:
24
+
25
+
```swift
26
+
importPerplexityApiSwift
27
+
28
+
// Initialize the API client
29
+
let api =PerplexityAPI(token: "your_api_token_here")
30
+
31
+
// Create a message
32
+
let messages = [Message(role: "user", content: "What is the capital of France?")]
33
+
34
+
// Make a chat completion request
35
+
do {
36
+
let response =tryawait api.chatCompletion(messages: messages, model: .sonarLarge)
**Important:** You need to obtain an API token from Perplexity AI to use this framework. Make sure to keep your token secure and never share it publicly.
44
+
45
+
## Available Models
46
+
47
+
The framework supports various Perplexity AI models through the `PerplexityModel` enum:
13
48
14
-
1. Initialize the API client with your token:
15
-
```swift
16
-
let api =PerplexityAPI(token: "your_api_token_here")
17
-
```
49
+
-`.sonar`
50
+
-`.sonarMedium`
51
+
-`.sonarLarge`
52
+
-`.codellama34b`
53
+
-`.llama2_70b`
54
+
-`.mistral7b`
55
+
-`.mixtral8x7b`
18
56
19
-
2. Make a chat completion request:
20
-
```swift
21
-
let messages = [Message(role: "user", content: "Hello, AI!")]
22
-
let response =tryawait api.chatCompletion(messages: messages, model: .sonarLarge)
23
-
```
57
+
## Error Handling
24
58
25
-
## Models
59
+
PerplexityApiSwift defines a `PerplexityError` enum for common errors:
26
60
27
-
The framework supports various Perplexity AI models, including:
28
-
- Sonar (small, medium, large)
29
-
- CodeLlama-34b
30
-
- Llama-2-70b
31
-
- Mistral-7b
32
-
- Mixtral-8x7b
61
+
-`.tokenNotSet`: The API token has not been set
62
+
-`.invalidResponse(statusCode:)`: The API returned an invalid response with the given status code
63
+
-`.invalidResponseFormat`: The API response could not be decoded
33
64
34
65
## Documentation
35
66
36
-
For detailed information about the Perplexity AI API, including available endpoints, request/response formats, and model capabilities, please refer to the official documentation:
67
+
For more detailed information about the Perplexity AI API, please refer to the official documentation:
37
68
38
69
[Perplexity AI API Documentation](https://docs.perplexity.ai/)
0 commit comments