Skip to content

Commit 086444d

Browse files
committed
adds LICENSE, updates README and file renames
1 parent dfcc4f7 commit 086444d

File tree

3 files changed

+71
-19
lines changed

3 files changed

+71
-19
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Josh grenon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# PerplexityApiSwift
22

3+
<p>
4+
<img src="https://img.shields.io/badge/iOS-16.0+-blue.svg" />
5+
<img src="https://img.shields.io/badge/Swift-5.5+-ff69b4.svg" />
6+
<img src="https://img.shields.io/badge/License-MIT-green.svg" />
7+
<a href="https://twitter.com/joshgrenon">
8+
<img src="https://img.shields.io/badge/[email protected]?style=flat" alt="Twitter: @joshgrenon" />
9+
</a>
10+
</p>
11+
312
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.
413

514
## Features
@@ -9,31 +18,53 @@ PerplexityApiSwift is a Swift framework that provides a convenient wrapper for t
918
- Asynchronous API calls using Swift's modern concurrency features
1019
- Built-in error handling for common API issues
1120

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+
import PerplexityApiSwift
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 = try await api.chatCompletion(messages: messages, model: .sonarLarge)
37+
print(response.choices.first?.message.content ?? "No response")
38+
} catch {
39+
print("Error: \(error)")
40+
}
41+
```
42+
43+
**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:
1348

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`
1856

19-
2. Make a chat completion request:
20-
```swift
21-
let messages = [Message(role: "user", content: "Hello, AI!")]
22-
let response = try await api.chatCompletion(messages: messages, model: .sonarLarge)
23-
```
57+
## Error Handling
2458

25-
## Models
59+
PerplexityApiSwift defines a `PerplexityError` enum for common errors:
2660

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
3364

3465
## Documentation
3566

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:
3768

3869
[Perplexity AI API Documentation](https://docs.perplexity.ai/)
3970

Sources/PerplexityApiSwift/PerplexityApiSwift.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
// MARK: - Perplexity API Client
44

5-
public class PerplexityAPI {
5+
public class PerplexityApiSwift {
66
private var bearerToken: String?
77

88
public init(token: String? = nil) {

0 commit comments

Comments
 (0)