Skip to content

Commit

Permalink
feat: 🎸 now you can choose the number of emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Apr 21, 2023
1 parent 32dd88f commit cd9c542
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
23 changes: 12 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import axios from "axios";
import type { Option } from "extension";
import type {
ChatCompletionRequestMessage,
CreateChatCompletionRequest,
CreateChatCompletionResponse,
} from "openai";
import type { Input } from "popclip";

async function prompt(input: Input, { apikey, model }: Option) {
async function prompt(input: Input, { apikey, model, count }: Option) {
const content = input.text.trim();
const messages: Array<ChatCompletionRequestMessage> = [
{
role: "system",
content:
"Perform emotion analysis and select just one suitable emoji for the message without explanations, without translation.",
},
{ role: "user", content },
];
const { data } = await axios.post<CreateChatCompletionResponse>(
"https://api.openai.com/v1/chat/completions",
{ model, messages },
{
model,
messages: [
{
role: "system",
content: `Perform emotion analysis and select just ${count} suitable emoji for the message without explanations, without translation.`,
},
{ role: "user", content },
],
} satisfies CreateChatCompletionRequest,
{ headers: { Authorization: `Bearer ${apikey}` } }
);
const emoji = data.choices[0]?.message?.content.trim() ?? "";
Expand Down
7 changes: 6 additions & 1 deletion manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ options:
- identifier: model
label: Model
type: string
description: 'Model to use for completion. Defaults to gpt-3.5-turbo'
description: Model to use for completion. Defaults to gpt-3.5-turbo
default value: gpt-3.5-turbo
- identifier: count
label: Emoji Count
type: string
description: Number of emoji to autocomplete
default value: one
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=16.9"
},
"publishConfig": {
"access": "public"
}
}
27 changes: 17 additions & 10 deletions popclip-chatgpt-emoji-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@
// - identifier: model
// label: Model
// type: string
// description: 'Model to use for completion. Defaults to gpt-3.5-turbo'
// description: Model to use for completion. Defaults to gpt-3.5-turbo
// default value: gpt-3.5-turbo
// - identifier: count
// label: Emoji Count
// type: string
// description: Number of emoji to autocomplete
// default value: one
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
async function prompt(input, { apikey, model }) {
async function prompt(input, { apikey, model, count }) {
const content = input.text.trim();
const messages = [
{
role: "system",
content: "Perform emotion analysis and select just one suitable emoji for the message without explanations, without translation.",
},
{ role: "user", content },
];
const { data } = await axios_1.default.post("https://api.openai.com/v1/chat/completions", { model, messages }, { headers: { Authorization: `Bearer ${apikey}` } });
const { data } = await axios_1.default.post("https://api.openai.com/v1/chat/completions", {
model,
messages: [
{
role: "system",
content: `Perform emotion analysis and select just ${count} suitable emoji for the message without explanations, without translation.`,
},
{ role: "user", content },
],
}, { headers: { Authorization: `Bearer ${apikey}` } });
const emoji = data.choices[0]?.message?.content.trim() ?? "";
return content + emoji;
}
Expand Down
1 change: 1 addition & 0 deletions types/extension.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module "extension" {
declare interface Option {
apikey: string;
model: string;
count: string;
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ __metadata:
version: 6
cacheKey: 8

"@suin/popclip-chatgpt-emoji@workspace:.":
"@suin/popclip-chatgpt-emoji-extension@workspace:.":
version: 0.0.0-use.local
resolution: "@suin/popclip-chatgpt-emoji@workspace:."
resolution: "@suin/popclip-chatgpt-emoji-extension@workspace:."
dependencies:
"@suin/tsconfig": ^0.0.0
"@types/node": ^18.15.13
Expand Down

0 comments on commit cd9c542

Please sign in to comment.