Create openai.yaml
Browse files- openai.yaml +86 -0
openai.yaml
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
_id: openai
|
| 2 |
+
description: Includes Chat GPT
|
| 3 |
+
readme: The first base version
|
| 4 |
+
title: Open AI
|
| 5 |
+
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/openai.yaml
|
| 6 |
+
version: 1
|
| 7 |
+
nodes:
|
| 8 |
+
ask_chat_gpt:
|
| 9 |
+
_id: ask_chat_gpt
|
| 10 |
+
arrange:
|
| 11 |
+
x: 220
|
| 12 |
+
y: 140
|
| 13 |
+
category:
|
| 14 |
+
id: llm_agents
|
| 15 |
+
title: en=Language Agents;ru=Языковые агенты
|
| 16 |
+
environment:
|
| 17 |
+
OPEN_API_KEY:
|
| 18 |
+
title: Open API key
|
| 19 |
+
type: string
|
| 20 |
+
scope: global
|
| 21 |
+
inputs:
|
| 22 |
+
question:
|
| 23 |
+
order: 2
|
| 24 |
+
title: en=Question;ru=Вопрос
|
| 25 |
+
type: string
|
| 26 |
+
required: true
|
| 27 |
+
multiline: true
|
| 28 |
+
model:
|
| 29 |
+
order: 2
|
| 30 |
+
title: en=Model;ru=Модель
|
| 31 |
+
type: string
|
| 32 |
+
required: true
|
| 33 |
+
default: gpt-4o-mini
|
| 34 |
+
enum:
|
| 35 |
+
- gpt-4o-mini|4o mini
|
| 36 |
+
- gpt-4o|4o
|
| 37 |
+
outputs:
|
| 38 |
+
answer:
|
| 39 |
+
title: en=Answer;ru=Ответ
|
| 40 |
+
type: string
|
| 41 |
+
json:
|
| 42 |
+
title: JSON
|
| 43 |
+
type: json
|
| 44 |
+
package: openai
|
| 45 |
+
script: |
|
| 46 |
+
const OpenAI = require('openai');
|
| 47 |
+
|
| 48 |
+
const OPEN_API_KEY = env?.variables?.get('OPEN_API_KEY');
|
| 49 |
+
if(!OPEN_API_KEY) {
|
| 50 |
+
error.fatal('Please, set your API key for Open AI');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
(async () => {
|
| 54 |
+
const { model, question } = inputs;
|
| 55 |
+
|
| 56 |
+
const openai = new OpenAI({
|
| 57 |
+
apiKey: OPEN_API_KEY,
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
const result = await openai.chat.completions.create({
|
| 61 |
+
model: model,
|
| 62 |
+
store: true,
|
| 63 |
+
messages: [
|
| 64 |
+
{"role": "user", "content": question},
|
| 65 |
+
],
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
const { content: answer } = result.choices[0].message;
|
| 69 |
+
|
| 70 |
+
try {
|
| 71 |
+
const json = answer.replace(/^\`\`\`json\s*/ig, '').replace(/\`\`\`\s*$/ig, '');
|
| 72 |
+
return next({outputs: { json: JSON.parse(json) }});
|
| 73 |
+
} catch(e) {
|
| 74 |
+
log(e);
|
| 75 |
+
// plain text
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
return next({outputs: { answer }});
|
| 79 |
+
})();
|
| 80 |
+
source: catalog
|
| 81 |
+
title: en=Ask Chat GPT;ru=Спросить Chat GPT
|
| 82 |
+
version: 1
|
| 83 |
+
costs: |-
|
| 84 |
+
(() => {
|
| 85 |
+
return 0.001;
|
| 86 |
+
})();
|