This repository contains an empty Scala/Cats project for use in Spacecat training courses.
Licensed Apache 2.0.
-
To use this repo you'll need to install a Java 11+ compatible JDK. We recommend using Sdkman to do this:
sdk list java sdk install java <VERSION_TAKEN_FROM_THE_LIST>
-
Clone this repository to a directory on your hard drive:
git clone https://github.com/spacecatio/cats-sandbox.git cd cats-sandbox
-
Run the
sbt.sh
script (or use your own locally installed SBT):./sbt.sh # Lots of output here. The first run will take a while. # You'll see an SBT prompt as follows: sbt:sandbox> run
-
Type
run
at the SBT prompt to run the sample app:sbt:sandbox> run # Lots of output here. The first run will take a while. # You should finally see the following output: Hello world!
-
Type
exit
to quit the SBT prompt when you're done:sbt:sandbox> exit
If you don't have a particular preference for a Scala editor or IDE, we recommend you use Visual Studio Code and a Linux or macOS terminal.
Ideally you should have the code
command set up in your terminal, in which case:
cd cats-sandbox
code .
If you don't have the command installed, you can open the code from the file menu:
- Choose File Menu > New Window
- Choose File Menu > Open Folder... and select the repo root folder
We recommend using your terminal to compile and run your code.
You can optionally install the Metals plugin to add IDE-like features for editing Scala in VSCode. However, please take the time to get this working correctly before your course.
If you prefer to edit Scala code using IntelliJ IDEA:
- Make sure you have the Scala plugin installed
- Choose File Menu > Open... and select the
build.sbt
file from the repo root folder - Choose "Open as Project"
To use the Chat GPT client library you'll need to create an OpenAI API key:
-
Sign up for an account
-
Click your profile icon inthe top right and select "View API keys"
-
Click "Create new secret key", name the key, and copy the key value
-
Initialise the Chat GPT client in your code as follows:
import openai.GptService GptService.resource("secret key goes here")
-
If you're condiering making your code public, don't commit your secret key to git! Instead, set up an environment variable in your bash/zsh profile and use the following code:
import openai.GptService GptService.resource(System.getenv("name of environment variable"))