Skip to content

Commit

Permalink
Use the openai winglib
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaiBer committed Mar 19, 2024
1 parent 66e3f6f commit 4f908b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
14 changes: 11 additions & 3 deletions examples/openai-joker/main.w
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
bring cloud;
bring openai;

// TODO: Set the secret value in the "secrets.json" file (create it if needed) in the ".wing" folder inside your user's folder.
// You need to add an OAIAPIKey like this:
//{
// "OAIAPIKey": "<your key here>"
//}
let apiKeySecret = new cloud.Secret(name: "OAIAPIKey") as "OpenAI Secret";

class Assistant {
personality: str;
openai: openai.OpenAI;

new(personality: str) {
this.openai = new openai.OpenAI(apiKeySecret: apiKeySecret);
this.personality = personality;
}

pub inflight ask(question: str): str {
let prompt = "you are an assistant with the following personality: {this.personality}. {question}";
let response = Assistant.createCompletion(prompt);
let response = this.openai.createCompletion(prompt);

return response.trim();
}

pub extern "./openai.js" static inflight createCompletion(prompt: str): str;
}

class Comedian {
Expand Down
31 changes: 0 additions & 31 deletions examples/openai-joker/openai.js

This file was deleted.

12 changes: 12 additions & 0 deletions examples/openai-joker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/openai-joker/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@winglibs/openai": "^0.0.1",
"openai": "^4.28.4"
}
}

0 comments on commit 4f908b3

Please sign in to comment.