Skip to content

Commit 2460302

Browse files
authored
Merge pull request #50 from yml-org/feature/CM-1217/edits
feat: Add Edits API
2 parents 9b6440b + 11651fe commit 2460302

File tree

41 files changed

+790
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+790
-22
lines changed

README.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
# YChat
77

8-
YChat is a Kotlin Multiplatform (KMP) project that provides a simple API for integrating the powerful ChatGPT language model developed by OpenAI into mobile applications running on both iOS and Android. The goal of this project is to abstract all the API call logic from ChatGPT, allowing developers to easily leverage the capabilities of the language model in their mobile applications.
8+
YChat is a Kotlin Multiplatform (KMP) project that provides a simple API for integrating the powerful ChatGPT language model developed by OpenAI into mobile applications running on multi platforms. The goal of this project is to abstract all the API call logic from ChatGPT, allowing developers to easily leverage the capabilities of the language model in their mobile applications.
99

1010
The repository contains the source code for the YChat library, along with examples and documentation for getting started with the library. The YChat library provides a consistent interface for interacting with ChatGPT, regardless of the platform, and makes it easy to generate human-like text based on a given prompt or context.
1111

12-
The library uses Kotlin Multiplatform to generate artifacts for both iOS and Android, allowing developers to write code once and use it on both platforms. The project is open source and actively maintained, with contributions from the community encouraged. Overall, YChat provides a convenient and powerful way for mobile developers to incorporate the advanced natural language processing capabilities of ChatGPT into their applications.
12+
The library uses Kotlin Multiplatform to generate artifacts for both iOS, Android and JVM, allowing developers to write code once and use it on multiple platforms. The project is open source and actively maintained, with contributions from the community encouraged. Overall, YChat provides a convenient and powerful way for mobile developers to incorporate the advanced natural language processing capabilities of ChatGPT into their applications.
1313

14+
## ⚡️ Getting Started
1415

15-
## iOS setup
16+
### iOS setup
1617

1718
- Go to your project’s file settings and click "Add Package":
1819

@@ -24,7 +25,7 @@ The library uses Kotlin Multiplatform to generate artifacts for both iOS and And
2425

2526
Once you have found the package click the "Add Package" button to add it to your project. Now you can start using the SDK in your iOS project!
2627

27-
See the code snippet below on how to initialize and use it:
28+
See the code snippet below on how to initialize and use it one of the supported feature:
2829

2930
```swift
3031
var yChat: YChat {
@@ -43,7 +44,7 @@ do {
4344
}
4445
```
4546

46-
## Android setup
47+
### Android/JVM setup
4748

4849
Add the following line to import the library via Gradle. First, make sure Maven Central has been added:
4950

@@ -55,13 +56,13 @@ repositories {
5556
}
5657
```
5758

58-
Then, simply import the dependency to your common source-set dependencies:
59+
Then, simply import the dependency to your `build.gradle` dependencies:
5960

6061
```kotlin
61-
implementation("co.yml:ychat:1.0.0")
62+
implementation("co.yml:ychat:1.1.0")
6263
```
6364

64-
In the snippet below, you can see how to initialize the object and perform a first search:
65+
Take a look at the Kotlin code snippet below for an example of how to initialize and use one of the supported features:
6566

6667

6768
```kotlin
@@ -82,11 +83,28 @@ try {
8283
}
8384
```
8485

86+
### Features
87+
88+
- [Completions](guides/Features.md#completion)
89+
- [ChatCompletions](guides/Features.md#chatcompletions)
90+
- [ImageGenerations](guides/Features.md#imagegenerations)
91+
- [Edits](guides/Features.md#edits)
92+
93+
## ℹ️ Sample apps
94+
95+
Take a look at our sample apps to learn how to use the SDK on different platforms:
96+
97+
[Android Sample](https://github.com/yml-org/ychat/tree/main/sample/android)
98+
<br />
99+
[iOS Sample](https://github.com/yml-org/ychat/tree/main/sample/ios)
100+
<br />
101+
[JVM Sample](https://github.com/yml-org/ychat/tree/main/sample/jvm)
102+
85103
## 🤝 Contributions
86104

87105
Feel free to make a suggestion or if you find any error in this project, please open an issue. Make sure to read our [contribution guidelines](https://github.com/yml-org/ychat/blob/main/CONTRIBUTING.md) before.
88106

89-
## License
107+
## 📄 License
90108

91109
```
92110
Copyright 2023 YML

YChat-1.0.0.zip

-8.17 MB
Binary file not shown.

YChat-1.1.0.zip

10.7 MB
Binary file not shown.

YChat.xcframework/Info.plist

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<key>AvailableLibraries</key>
66
<array>
77
<dict>
8+
<key>DebugSymbolsPath</key>
9+
<string>dSYMs</string>
810
<key>LibraryIdentifier</key>
911
<string>ios-arm64</string>
1012
<key>LibraryPath</key>
@@ -17,6 +19,8 @@
1719
<string>ios</string>
1820
</dict>
1921
<dict>
22+
<key>DebugSymbolsPath</key>
23+
<string>dSYMs</string>
2024
<key>LibraryIdentifier</key>
2125
<string>ios-x86_64-simulator</string>
2226
<key>LibraryPath</key>

YChat.xcframework/ios-arm64/YChat.framework/Headers/YChat.h

+69-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#import <Foundation/NSString.h>
77
#import <Foundation/NSValue.h>
88

9-
@class YChatKotlinThrowable, YChatYChatCompanion, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
9+
@class YChatKotlinThrowable, YChatYChatCompanion, YChatChatMessage, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
1010

11-
@protocol YChatCompletion, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
11+
@protocol YChatChatCompletions, YChatCompletion, YChatEdits, YChatImageGenerations, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
1212

1313
NS_ASSUME_NONNULL_BEGIN
1414
#pragma clang diagnostic push
@@ -147,7 +147,10 @@ __attribute__((swift_name("KotlinBoolean")))
147147
__attribute__((swift_name("YChat")))
148148
@protocol YChatYChat
149149
@required
150+
- (id<YChatChatCompletions>)chatCompletions __attribute__((swift_name("chatCompletions()")));
150151
- (id<YChatCompletion>)completion __attribute__((swift_name("completion()")));
152+
- (id<YChatEdits>)edits __attribute__((swift_name("edits()")));
153+
- (id<YChatImageGenerations>)imageGenerations __attribute__((swift_name("imageGenerations()")));
151154
@end
152155

153156
__attribute__((swift_name("YChatCallback")))
@@ -172,6 +175,20 @@ __attribute__((swift_name("YChatCompanion")))
172175
- (id<YChatYChat>)createApiKey:(NSString *)apiKey __attribute__((swift_name("create(apiKey:)")));
173176
@end
174177

178+
__attribute__((objc_subclassing_restricted))
179+
__attribute__((swift_name("ChatMessage")))
180+
@interface YChatChatMessage : YChatBase
181+
- (instancetype)initWithRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("init(role:content:)"))) __attribute__((objc_designated_initializer));
182+
- (NSString *)component1 __attribute__((swift_name("component1()"))) __attribute__((deprecated("use corresponding property instead")));
183+
- (NSString *)component2 __attribute__((swift_name("component2()"))) __attribute__((deprecated("use corresponding property instead")));
184+
- (YChatChatMessage *)doCopyRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("doCopy(role:content:)")));
185+
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
186+
- (NSUInteger)hash __attribute__((swift_name("hash()")));
187+
- (NSString *)description __attribute__((swift_name("description()")));
188+
@property (readonly) NSString *content __attribute__((swift_name("content")));
189+
@property (readonly) NSString *role __attribute__((swift_name("role")));
190+
@end
191+
175192
__attribute__((swift_name("KotlinThrowable")))
176193
@interface YChatKotlinThrowable : YChatBase
177194
- (instancetype)initWithMessage:(NSString * _Nullable)message __attribute__((swift_name("init(message:)"))) __attribute__((objc_designated_initializer));
@@ -209,6 +226,24 @@ __attribute__((swift_name("ChatGptException")))
209226
@property YChatInt * _Nullable statusCode __attribute__((swift_name("statusCode")));
210227
@end
211228

229+
__attribute__((swift_name("ChatCompletions")))
230+
@protocol YChatChatCompletions
231+
@required
232+
- (id<YChatChatCompletions>)addMessageRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("addMessage(role:content:)")));
233+
234+
/**
235+
* @note This method converts instances of CancellationException, ChatGptException to errors.
236+
* Other uncaught Kotlin exceptions are fatal.
237+
*/
238+
- (void)executeContent:(NSString *)content completionHandler:(void (^)(NSArray<YChatChatMessage *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(content:completionHandler:)")));
239+
- (void)executeContent:(NSString *)content callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(content:callback:)")));
240+
- (id<YChatChatCompletions>)setMaxResultsResults:(int32_t)results __attribute__((swift_name("setMaxResults(results:)")));
241+
- (id<YChatChatCompletions>)setMaxTokensTokens:(int32_t)tokens __attribute__((swift_name("setMaxTokens(tokens:)")));
242+
- (id<YChatChatCompletions>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
243+
- (id<YChatChatCompletions>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
244+
- (id<YChatChatCompletions>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
245+
@end
246+
212247
__attribute__((swift_name("Completion")))
213248
@protocol YChatCompletion
214249
@required
@@ -227,6 +262,38 @@ __attribute__((swift_name("Completion")))
227262
- (id<YChatCompletion>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
228263
@end
229264

265+
__attribute__((swift_name("Edits")))
266+
@protocol YChatEdits
267+
@required
268+
269+
/**
270+
* @note This method converts instances of CancellationException, ChatGptException to errors.
271+
* Other uncaught Kotlin exceptions are fatal.
272+
*/
273+
- (void)executeInstruction:(NSString *)instruction completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(instruction:completionHandler:)")));
274+
- (void)executeInstruction:(NSString *)instruction callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(instruction:callback:)")));
275+
- (id<YChatEdits>)setInputInput:(NSString *)input __attribute__((swift_name("setInput(input:)")));
276+
- (id<YChatEdits>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
277+
- (id<YChatEdits>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
278+
- (id<YChatEdits>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
279+
- (id<YChatEdits>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
280+
@end
281+
282+
__attribute__((swift_name("ImageGenerations")))
283+
@protocol YChatImageGenerations
284+
@required
285+
286+
/**
287+
* @note This method converts instances of CancellationException, ChatGptException to errors.
288+
* Other uncaught Kotlin exceptions are fatal.
289+
*/
290+
- (void)executePrompt:(NSString *)prompt completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(prompt:completionHandler:)")));
291+
- (void)executePrompt:(NSString *)prompt callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(prompt:callback:)")));
292+
- (id<YChatImageGenerations>)setResponseFormatResponseFormat:(NSString *)responseFormat __attribute__((swift_name("setResponseFormat(responseFormat:)")));
293+
- (id<YChatImageGenerations>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
294+
- (id<YChatImageGenerations>)setSizeSize:(NSString *)size __attribute__((swift_name("setSize(size:)")));
295+
@end
296+
230297
__attribute__((objc_subclassing_restricted))
231298
__attribute__((swift_name("KotlinArray")))
232299
@interface YChatKotlinArray<T> : YChatBase
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.apple.xcode.dsym.co.yml.ychat.YChat</string>
9+
<key>CFBundleInfoDictionaryVersion</key>
10+
<string>6.0</string>
11+
<key>CFBundlePackageType</key>
12+
<string>dSYM</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
</dict>
20+
</plist>

YChat.xcframework/ios-x86_64-simulator/YChat.framework/Headers/YChat.h

+69-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#import <Foundation/NSString.h>
77
#import <Foundation/NSValue.h>
88

9-
@class YChatKotlinThrowable, YChatYChatCompanion, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
9+
@class YChatKotlinThrowable, YChatYChatCompanion, YChatChatMessage, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
1010

11-
@protocol YChatCompletion, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
11+
@protocol YChatChatCompletions, YChatCompletion, YChatEdits, YChatImageGenerations, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
1212

1313
NS_ASSUME_NONNULL_BEGIN
1414
#pragma clang diagnostic push
@@ -147,7 +147,10 @@ __attribute__((swift_name("KotlinBoolean")))
147147
__attribute__((swift_name("YChat")))
148148
@protocol YChatYChat
149149
@required
150+
- (id<YChatChatCompletions>)chatCompletions __attribute__((swift_name("chatCompletions()")));
150151
- (id<YChatCompletion>)completion __attribute__((swift_name("completion()")));
152+
- (id<YChatEdits>)edits __attribute__((swift_name("edits()")));
153+
- (id<YChatImageGenerations>)imageGenerations __attribute__((swift_name("imageGenerations()")));
151154
@end
152155

153156
__attribute__((swift_name("YChatCallback")))
@@ -172,6 +175,20 @@ __attribute__((swift_name("YChatCompanion")))
172175
- (id<YChatYChat>)createApiKey:(NSString *)apiKey __attribute__((swift_name("create(apiKey:)")));
173176
@end
174177

178+
__attribute__((objc_subclassing_restricted))
179+
__attribute__((swift_name("ChatMessage")))
180+
@interface YChatChatMessage : YChatBase
181+
- (instancetype)initWithRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("init(role:content:)"))) __attribute__((objc_designated_initializer));
182+
- (NSString *)component1 __attribute__((swift_name("component1()"))) __attribute__((deprecated("use corresponding property instead")));
183+
- (NSString *)component2 __attribute__((swift_name("component2()"))) __attribute__((deprecated("use corresponding property instead")));
184+
- (YChatChatMessage *)doCopyRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("doCopy(role:content:)")));
185+
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
186+
- (NSUInteger)hash __attribute__((swift_name("hash()")));
187+
- (NSString *)description __attribute__((swift_name("description()")));
188+
@property (readonly) NSString *content __attribute__((swift_name("content")));
189+
@property (readonly) NSString *role __attribute__((swift_name("role")));
190+
@end
191+
175192
__attribute__((swift_name("KotlinThrowable")))
176193
@interface YChatKotlinThrowable : YChatBase
177194
- (instancetype)initWithMessage:(NSString * _Nullable)message __attribute__((swift_name("init(message:)"))) __attribute__((objc_designated_initializer));
@@ -209,6 +226,24 @@ __attribute__((swift_name("ChatGptException")))
209226
@property YChatInt * _Nullable statusCode __attribute__((swift_name("statusCode")));
210227
@end
211228

229+
__attribute__((swift_name("ChatCompletions")))
230+
@protocol YChatChatCompletions
231+
@required
232+
- (id<YChatChatCompletions>)addMessageRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("addMessage(role:content:)")));
233+
234+
/**
235+
* @note This method converts instances of CancellationException, ChatGptException to errors.
236+
* Other uncaught Kotlin exceptions are fatal.
237+
*/
238+
- (void)executeContent:(NSString *)content completionHandler:(void (^)(NSArray<YChatChatMessage *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(content:completionHandler:)")));
239+
- (void)executeContent:(NSString *)content callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(content:callback:)")));
240+
- (id<YChatChatCompletions>)setMaxResultsResults:(int32_t)results __attribute__((swift_name("setMaxResults(results:)")));
241+
- (id<YChatChatCompletions>)setMaxTokensTokens:(int32_t)tokens __attribute__((swift_name("setMaxTokens(tokens:)")));
242+
- (id<YChatChatCompletions>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
243+
- (id<YChatChatCompletions>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
244+
- (id<YChatChatCompletions>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
245+
@end
246+
212247
__attribute__((swift_name("Completion")))
213248
@protocol YChatCompletion
214249
@required
@@ -227,6 +262,38 @@ __attribute__((swift_name("Completion")))
227262
- (id<YChatCompletion>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
228263
@end
229264

265+
__attribute__((swift_name("Edits")))
266+
@protocol YChatEdits
267+
@required
268+
269+
/**
270+
* @note This method converts instances of CancellationException, ChatGptException to errors.
271+
* Other uncaught Kotlin exceptions are fatal.
272+
*/
273+
- (void)executeInstruction:(NSString *)instruction completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(instruction:completionHandler:)")));
274+
- (void)executeInstruction:(NSString *)instruction callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(instruction:callback:)")));
275+
- (id<YChatEdits>)setInputInput:(NSString *)input __attribute__((swift_name("setInput(input:)")));
276+
- (id<YChatEdits>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
277+
- (id<YChatEdits>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
278+
- (id<YChatEdits>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
279+
- (id<YChatEdits>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
280+
@end
281+
282+
__attribute__((swift_name("ImageGenerations")))
283+
@protocol YChatImageGenerations
284+
@required
285+
286+
/**
287+
* @note This method converts instances of CancellationException, ChatGptException to errors.
288+
* Other uncaught Kotlin exceptions are fatal.
289+
*/
290+
- (void)executePrompt:(NSString *)prompt completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(prompt:completionHandler:)")));
291+
- (void)executePrompt:(NSString *)prompt callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(prompt:callback:)")));
292+
- (id<YChatImageGenerations>)setResponseFormatResponseFormat:(NSString *)responseFormat __attribute__((swift_name("setResponseFormat(responseFormat:)")));
293+
- (id<YChatImageGenerations>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
294+
- (id<YChatImageGenerations>)setSizeSize:(NSString *)size __attribute__((swift_name("setSize(size:)")));
295+
@end
296+
230297
__attribute__((objc_subclassing_restricted))
231298
__attribute__((swift_name("KotlinArray")))
232299
@interface YChatKotlinArray<T> : YChatBase
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.apple.xcode.dsym.co.yml.ychat.YChat</string>
9+
<key>CFBundleInfoDictionaryVersion</key>
10+
<string>6.0</string>
11+
<key>CFBundlePackageType</key>
12+
<string>dSYM</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
</dict>
20+
</plist>

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kotlin.mpp.enableCInteropCommonization=true
1111
# Lib
1212
GROUP=co.yml
1313
POM_ARTIFACT_ID=ychat
14-
VERSION_NAME=1.0.0
14+
VERSION_NAME=1.1.0
1515
IOS_NAME=YChat
1616

1717
# OSS

0 commit comments

Comments
 (0)