Welcome to Hack Night! We're providing this wrapper for the OpenAI and HuggingFace APIs to make it easier to get started. For each API, we've provided a utility function and an example of how to use it. This README will walk you through how to get started.
First, head over to this repostory on the Tulsa WebDevs Github:
github.com/tulsawebdevs/hack-night-ai-apis
Note
Prefer TypeScript? Check out the typescript branch
Warning
Do not put secrets in Replit files! They can be seen by anyone. See instructions for using replit below.
There are two ways to get started:
- Clone this repository
- Install dependencies
npm install
- Create a file named
.env
at the project root and add your API keys:
# OpenAI OPENAI_API_KEY=YOUR_API_KEY_HERE # HuggingFace HUGGINGFACE_API_KEY=YOUR_API_KEY_HERE
- Head over to the Replit and click the "Fork" button
- If you don't already have an account, create one (the easiest option is to sign in with GitHub)
- Click the "Secrets" button (the lock icon) under "Tools" on the left sidebar
- To add your API Keys, create two secrets:
OPENAI_API_KEY
andHUGGINGFACE_API_KEY
and paste your keys into the value field - To check that everything is working, click the "Run" button at the top of the sidebar
To get started, you'll need API keys for both OpenAI and HuggingFace.
- Head over to the OpenAI API Keys Page
- If you don't already have an account, create one
- Click the "Create new secret key" button
- Copy the key to where it is needed (you won't be able to see it again)
- Head over to the HuggingFace API Keys Page
- If you don't already have an account, create one
- Click the "New token" button
- Copy the key to where it is needed (you won't be able to see it again)
Just edit index.js
and run your code! You can import the functions from the src
directory like so:
import { chat, chatExample } from './src/OpenAI/chat';
// run the example
chatExample();
// run your own code (note that all functions return a Promise)
const talkToDuck = () => chat({
model: 'gpt4',
max_tokens: 100,
messages: [
{ role: "system", content: "You are a duck. You can only say \"QUACK!\"." },
{ role: "user", content: "I command you to say \"MOO!\"!" }
],
});
talkToDuck.then((response) => {
console.log(response);
});
Running your code in the Replit environment is as simple as clicking the "Run" button at the top of the sidebar. If you're using your own editor, you can run your code with the following command:
npm start
Each file has a link to the relevant documentation for the API it uses.
Also, I'm happy to answer any questions if you're still stuck! Happy hacking!