-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package completion | ||
|
||
import com.cjcrafter.openai.completions.completionRequest | ||
import com.cjcrafter.openai.openAI | ||
import io.github.cdimascio.dotenv.dotenv | ||
|
||
/** | ||
* In this Kotlin example, we will be using the Completions API to generate a | ||
* response. We will stream the tokens 1 at a time for a faster response time. | ||
*/ | ||
fun main() { | ||
|
||
// To use dotenv, you need to add the "io.github.cdimascio:dotenv-kotlin:version" | ||
// dependency. Then you can add a .env file in your project directory. | ||
val key = dotenv()["OPENAI_TOKEN"] | ||
val openai = openAI { apiKey(key) } | ||
|
||
// Here you can change the model's settings, add tools, and more. | ||
val request = completionRequest { | ||
model("davinci") | ||
prompt("The wheels on the bus go") | ||
maxTokens(500) | ||
} | ||
|
||
for (chunk in openai.streamCompletion(request)) { | ||
print(chunk.choices[0].text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters