Skip to content

Commit 95a4bd3

Browse files
committed
doc: enhance readme
1 parent 7105856 commit 95a4bd3

File tree

3 files changed

+204
-10
lines changed

3 files changed

+204
-10
lines changed

README.md

Lines changed: 26 additions & 8 deletions
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
6162
implementation("co.yml:ychat:1.0.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

guides/Features.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Features
2+
3+
- [Completion](#completion)
4+
- [ChatCompletions](#chatcompletions)
5+
- [ImageGenerations](#imagegenerations)
6+
- [Edits](#edits)
7+
8+
## Completion
9+
10+
The completions api can be used for a wide variety of tasks. You input some text as a prompt, and the model will generate a text completion that attempts to match whatever context or pattern you gave it. For example, if you give the API the prompt, "As Descartes said, I think, therefore", it will return the completion " I am" with high probability.
11+
12+
### Swift
13+
14+
```swift
15+
var yChat: YChat {
16+
YChatCompanion.shared.create(apiKey: "your-api-key")
17+
}
18+
19+
do {
20+
let result = try await chatGpt.completion()
21+
.setInput(input: "Say this is a test.")
22+
.setMaxTokens(tokens: 1024)
23+
.set... // you can set more parameters
24+
.execute()
25+
} catch {
26+
// catch any error that may occurs on api call.
27+
}
28+
```
29+
30+
### Kotlin
31+
32+
```kotlin
33+
val yChat by lazy {
34+
YChat.create("your-api-key")
35+
}
36+
37+
try {
38+
val result = yChat.completion()
39+
.setInput("Say this is a test.")
40+
.setMaxTokens(1024)
41+
.set... // you can set more parameters
42+
.execute()
43+
44+
} catch (e: exception) {
45+
// catch any error that may occurs on api call.
46+
}
47+
```
48+
49+
## ChatCompletions
50+
51+
The chatCompletions api generates a list of chat completions for the given input message. It uses machine learning algorithms to generate responses that match the context or pattern provided in the input message.
52+
53+
### Swift
54+
55+
```swift
56+
var yChat: YChat {
57+
YChatCompanion.shared.create(apiKey: "your-api-key")
58+
}
59+
60+
do {
61+
let result = try await chatGpt.chatCompletions()
62+
.setMaxTokens(tokens: 1024)
63+
.addMessage(
64+
role: "assistant",
65+
content: "You are a helpful assistant that only answers questions related to fitness"
66+
)
67+
.set... // you can set more parameters
68+
.execute(content: "What is the best exercise for building muscle?")
69+
} catch {
70+
// catch any error that may occurs on api call.
71+
}
72+
```
73+
74+
### Kotlin
75+
76+
```kotlin
77+
val yChat by lazy {
78+
YChat.create("your-api-key")
79+
}
80+
81+
try {
82+
val result = yChat.chatCompletions()
83+
.setMaxTokens(1024)
84+
.addMessage(
85+
role = "assistant",
86+
content = "You are a helpful assistant that only answers questions related to fitness"
87+
)
88+
.set... // you can set more parameters
89+
.execute("What is the best exercise for building muscle?")
90+
91+
} catch (e: exception) {
92+
// catch any error that may occurs on api call.
93+
}
94+
```
95+
96+
## ImageGenerations
97+
98+
The image generations api is used to generate images based on a prompt. You input some text as a prompt, and the model will generate one or more images.
99+
100+
### Swift
101+
102+
```swift
103+
var yChat: YChat {
104+
YChatCompanion.shared.create(apiKey: "your-api-key")
105+
}
106+
107+
do {
108+
let result = try await chatGpt.imageGenerations()
109+
.setResults(results: 2)
110+
.setSize(size: "1024x1024")
111+
.set... // you can set more parameters
112+
.execute(prompt: "ocean")
113+
} catch {
114+
// catch any error that may occurs on api call.
115+
}
116+
```
117+
118+
### Kotlin
119+
120+
```kotlin
121+
val yChat by lazy {
122+
YChat.create("your-api-key")
123+
}
124+
125+
try {
126+
val result = yChat.imageGenerations()
127+
.setResults(2)
128+
.setSize("1024x1024")
129+
.set... // you can set more parameters
130+
.execute("ocean")
131+
132+
} catch (e: exception) {
133+
// catch any error that may occurs on api call.
134+
}
135+
```
136+
137+
## Edits
138+
139+
The edits api is used to edit prompts and re-generate. Given a prompt and an instruction, the model will return an edited version of the prompt.
140+
141+
### Swift
142+
143+
```swift
144+
var yChat: YChat {
145+
YChatCompanion.shared.create(apiKey: "your-api-key")
146+
}
147+
148+
do {
149+
let result = try await chatGpt.edits()
150+
.setInput(input: "What day of the wek is it?")
151+
.setResults(result: 1)
152+
.set... // you can set more parameters
153+
.execute(instruction: "Fix the spelling mistakes")
154+
} catch {
155+
// catch any error that may occurs on api call.
156+
}
157+
```
158+
159+
### Kotlin
160+
161+
```kotlin
162+
val yChat by lazy {
163+
YChat.create("your-api-key")
164+
}
165+
166+
try {
167+
val result = yChat.edits()
168+
.setInput("What day of the wek is it?")
169+
.setResults(1)
170+
.set... // you can set more parameters
171+
.execute("Fix the spelling mistakes")
172+
173+
} catch (e: exception) {
174+
// catch any error that may occurs on api call.
175+
}
176+
```

ychat/src/commonMain/kotlin/co/yml/ychat/YChat.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ interface YChat {
8787
* ```
8888
* val result = YChat.create(apiKey).imageGenerations()
8989
* .setResults(2)
90-
* .setSize(1024x1024)
90+
* .setSize("1024x1024")
9191
* .set...
92-
* .execute("/image ocean")
92+
* .execute("ocean")
9393
* ```
9494
*/
9595
fun imageGenerations(): ImageGenerations

0 commit comments

Comments
 (0)