Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Edits API #50

Merged
merged 6 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

# YChat

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.
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.

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.

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.
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.

## ⚡️ Getting Started

## iOS setup
### iOS setup

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

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

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!

See the code snippet below on how to initialize and use it:
See the code snippet below on how to initialize and use it one of the supported feature:

```swift
var yChat: YChat {
Expand All @@ -43,7 +44,7 @@ do {
}
```

## Android setup
### Android/JVM setup

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

Expand All @@ -55,13 +56,13 @@ repositories {
}
```

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

```kotlin
implementation("co.yml:ychat:1.0.0")
implementation("co.yml:ychat:1.1.0")
```

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


```kotlin
Expand All @@ -82,11 +83,28 @@ try {
}
```

### Features

- [Completions](guides/Features.md#completion)
- [ChatCompletions](guides/Features.md#chatcompletions)
- [ImageGenerations](guides/Features.md#imagegenerations)
- [Edits](guides/Features.md#edits)

## ℹ️ Sample apps

Take a look at our sample apps to learn how to use the SDK on different platforms:

[Android Sample](https://github.com/yml-org/ychat/tree/main/sample/android)
<br />
[iOS Sample](https://github.com/yml-org/ychat/tree/main/sample/ios)
<br />
[JVM Sample](https://github.com/yml-org/ychat/tree/main/sample/jvm)

## 🤝 Contributions

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.

## License
## 📄 License

```
Copyright 2023 YML
Expand Down
Binary file removed YChat-1.0.0.zip
Binary file not shown.
Binary file added YChat-1.1.0.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions YChat.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<key>AvailableLibraries</key>
<array>
<dict>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
Expand All @@ -17,6 +19,8 @@
<string>ios</string>
</dict>
<dict>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-x86_64-simulator</string>
<key>LibraryPath</key>
Expand Down
71 changes: 69 additions & 2 deletions YChat.xcframework/ios-arm64/YChat.framework/Headers/YChat.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>

@class YChatKotlinThrowable, YChatYChatCompanion, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
@class YChatKotlinThrowable, YChatYChatCompanion, YChatChatMessage, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;

@protocol YChatCompletion, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
@protocol YChatChatCompletions, YChatCompletion, YChatEdits, YChatImageGenerations, YChatYChat, YChatYChatCallback, YChatKotlinIterator;

NS_ASSUME_NONNULL_BEGIN
#pragma clang diagnostic push
Expand Down Expand Up @@ -147,7 +147,10 @@ __attribute__((swift_name("KotlinBoolean")))
__attribute__((swift_name("YChat")))
@protocol YChatYChat
@required
- (id<YChatChatCompletions>)chatCompletions __attribute__((swift_name("chatCompletions()")));
- (id<YChatCompletion>)completion __attribute__((swift_name("completion()")));
- (id<YChatEdits>)edits __attribute__((swift_name("edits()")));
- (id<YChatImageGenerations>)imageGenerations __attribute__((swift_name("imageGenerations()")));
@end

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

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("ChatMessage")))
@interface YChatChatMessage : YChatBase
- (instancetype)initWithRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("init(role:content:)"))) __attribute__((objc_designated_initializer));
- (NSString *)component1 __attribute__((swift_name("component1()"))) __attribute__((deprecated("use corresponding property instead")));
- (NSString *)component2 __attribute__((swift_name("component2()"))) __attribute__((deprecated("use corresponding property instead")));
- (YChatChatMessage *)doCopyRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("doCopy(role:content:)")));
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
- (NSUInteger)hash __attribute__((swift_name("hash()")));
- (NSString *)description __attribute__((swift_name("description()")));
@property (readonly) NSString *content __attribute__((swift_name("content")));
@property (readonly) NSString *role __attribute__((swift_name("role")));
@end

__attribute__((swift_name("KotlinThrowable")))
@interface YChatKotlinThrowable : YChatBase
- (instancetype)initWithMessage:(NSString * _Nullable)message __attribute__((swift_name("init(message:)"))) __attribute__((objc_designated_initializer));
Expand Down Expand Up @@ -209,6 +226,24 @@ __attribute__((swift_name("ChatGptException")))
@property YChatInt * _Nullable statusCode __attribute__((swift_name("statusCode")));
@end

__attribute__((swift_name("ChatCompletions")))
@protocol YChatChatCompletions
@required
- (id<YChatChatCompletions>)addMessageRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("addMessage(role:content:)")));

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executeContent:(NSString *)content completionHandler:(void (^)(NSArray<YChatChatMessage *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(content:completionHandler:)")));
- (void)executeContent:(NSString *)content callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(content:callback:)")));
- (id<YChatChatCompletions>)setMaxResultsResults:(int32_t)results __attribute__((swift_name("setMaxResults(results:)")));
- (id<YChatChatCompletions>)setMaxTokensTokens:(int32_t)tokens __attribute__((swift_name("setMaxTokens(tokens:)")));
- (id<YChatChatCompletions>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
- (id<YChatChatCompletions>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
- (id<YChatChatCompletions>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("Completion")))
@protocol YChatCompletion
@required
Expand All @@ -227,6 +262,38 @@ __attribute__((swift_name("Completion")))
- (id<YChatCompletion>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("Edits")))
@protocol YChatEdits
@required

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executeInstruction:(NSString *)instruction completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(instruction:completionHandler:)")));
- (void)executeInstruction:(NSString *)instruction callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(instruction:callback:)")));
- (id<YChatEdits>)setInputInput:(NSString *)input __attribute__((swift_name("setInput(input:)")));
- (id<YChatEdits>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
- (id<YChatEdits>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
- (id<YChatEdits>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
- (id<YChatEdits>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("ImageGenerations")))
@protocol YChatImageGenerations
@required

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executePrompt:(NSString *)prompt completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(prompt:completionHandler:)")));
- (void)executePrompt:(NSString *)prompt callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(prompt:callback:)")));
- (id<YChatImageGenerations>)setResponseFormatResponseFormat:(NSString *)responseFormat __attribute__((swift_name("setResponseFormat(responseFormat:)")));
- (id<YChatImageGenerations>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
- (id<YChatImageGenerations>)setSizeSize:(NSString *)size __attribute__((swift_name("setSize(size:)")));
@end

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("KotlinArray")))
@interface YChatKotlinArray<T> : YChatBase
Expand Down
Binary file modified YChat.xcframework/ios-arm64/YChat.framework/YChat
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.co.yml.ychat.YChat</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>

@class YChatKotlinThrowable, YChatYChatCompanion, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;
@class YChatKotlinThrowable, YChatYChatCompanion, YChatChatMessage, YChatKotlinArray<T>, YChatKotlinException, YChatKotlinRuntimeException, YChatKotlinIllegalStateException;

@protocol YChatCompletion, YChatYChat, YChatYChatCallback, YChatKotlinIterator;
@protocol YChatChatCompletions, YChatCompletion, YChatEdits, YChatImageGenerations, YChatYChat, YChatYChatCallback, YChatKotlinIterator;

NS_ASSUME_NONNULL_BEGIN
#pragma clang diagnostic push
Expand Down Expand Up @@ -147,7 +147,10 @@ __attribute__((swift_name("KotlinBoolean")))
__attribute__((swift_name("YChat")))
@protocol YChatYChat
@required
- (id<YChatChatCompletions>)chatCompletions __attribute__((swift_name("chatCompletions()")));
- (id<YChatCompletion>)completion __attribute__((swift_name("completion()")));
- (id<YChatEdits>)edits __attribute__((swift_name("edits()")));
- (id<YChatImageGenerations>)imageGenerations __attribute__((swift_name("imageGenerations()")));
@end

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

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("ChatMessage")))
@interface YChatChatMessage : YChatBase
- (instancetype)initWithRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("init(role:content:)"))) __attribute__((objc_designated_initializer));
- (NSString *)component1 __attribute__((swift_name("component1()"))) __attribute__((deprecated("use corresponding property instead")));
- (NSString *)component2 __attribute__((swift_name("component2()"))) __attribute__((deprecated("use corresponding property instead")));
- (YChatChatMessage *)doCopyRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("doCopy(role:content:)")));
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
- (NSUInteger)hash __attribute__((swift_name("hash()")));
- (NSString *)description __attribute__((swift_name("description()")));
@property (readonly) NSString *content __attribute__((swift_name("content")));
@property (readonly) NSString *role __attribute__((swift_name("role")));
@end

__attribute__((swift_name("KotlinThrowable")))
@interface YChatKotlinThrowable : YChatBase
- (instancetype)initWithMessage:(NSString * _Nullable)message __attribute__((swift_name("init(message:)"))) __attribute__((objc_designated_initializer));
Expand Down Expand Up @@ -209,6 +226,24 @@ __attribute__((swift_name("ChatGptException")))
@property YChatInt * _Nullable statusCode __attribute__((swift_name("statusCode")));
@end

__attribute__((swift_name("ChatCompletions")))
@protocol YChatChatCompletions
@required
- (id<YChatChatCompletions>)addMessageRole:(NSString *)role content:(NSString *)content __attribute__((swift_name("addMessage(role:content:)")));

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executeContent:(NSString *)content completionHandler:(void (^)(NSArray<YChatChatMessage *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(content:completionHandler:)")));
- (void)executeContent:(NSString *)content callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(content:callback:)")));
- (id<YChatChatCompletions>)setMaxResultsResults:(int32_t)results __attribute__((swift_name("setMaxResults(results:)")));
- (id<YChatChatCompletions>)setMaxTokensTokens:(int32_t)tokens __attribute__((swift_name("setMaxTokens(tokens:)")));
- (id<YChatChatCompletions>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
- (id<YChatChatCompletions>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
- (id<YChatChatCompletions>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("Completion")))
@protocol YChatCompletion
@required
Expand All @@ -227,6 +262,38 @@ __attribute__((swift_name("Completion")))
- (id<YChatCompletion>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("Edits")))
@protocol YChatEdits
@required

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executeInstruction:(NSString *)instruction completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(instruction:completionHandler:)")));
- (void)executeInstruction:(NSString *)instruction callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(instruction:callback:)")));
- (id<YChatEdits>)setInputInput:(NSString *)input __attribute__((swift_name("setInput(input:)")));
- (id<YChatEdits>)setModelModel:(NSString *)model __attribute__((swift_name("setModel(model:)")));
- (id<YChatEdits>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
- (id<YChatEdits>)setTemperatureTemperature:(double)temperature __attribute__((swift_name("setTemperature(temperature:)")));
- (id<YChatEdits>)setTopPTopP:(double)topP __attribute__((swift_name("setTopP(topP:)")));
@end

__attribute__((swift_name("ImageGenerations")))
@protocol YChatImageGenerations
@required

/**
* @note This method converts instances of CancellationException, ChatGptException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)executePrompt:(NSString *)prompt completionHandler:(void (^)(NSArray<NSString *> * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("execute(prompt:completionHandler:)")));
- (void)executePrompt:(NSString *)prompt callback:(id<YChatYChatCallback>)callback __attribute__((swift_name("execute(prompt:callback:)")));
- (id<YChatImageGenerations>)setResponseFormatResponseFormat:(NSString *)responseFormat __attribute__((swift_name("setResponseFormat(responseFormat:)")));
- (id<YChatImageGenerations>)setResultsResults:(int32_t)results __attribute__((swift_name("setResults(results:)")));
- (id<YChatImageGenerations>)setSizeSize:(NSString *)size __attribute__((swift_name("setSize(size:)")));
@end

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("KotlinArray")))
@interface YChatKotlinArray<T> : YChatBase
Expand Down
Binary file modified YChat.xcframework/ios-x86_64-simulator/YChat.framework/YChat
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.co.yml.ychat.YChat</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kotlin.mpp.enableCInteropCommonization=true
# Lib
GROUP=co.yml
POM_ARTIFACT_ID=ychat
VERSION_NAME=1.0.0
VERSION_NAME=1.1.0
IOS_NAME=YChat

# OSS
Expand Down
Loading