@pipedream/openai 0.9.4 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/actions/chat/chat.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { ConfigurationError } from "@pipedream/platform";
|
|
|
6
6
|
export default {
|
|
7
7
|
...common,
|
|
8
8
|
name: "Chat",
|
|
9
|
-
version: "0.2.
|
|
9
|
+
version: "0.2.9",
|
|
10
10
|
key: "openai-chat",
|
|
11
11
|
description: "The Chat API, using the `gpt-3.5-turbo` or `gpt-4` model. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
|
|
12
12
|
type: "action",
|
|
@@ -159,6 +159,16 @@ export default {
|
|
|
159
159
|
},
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
+
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
163
|
+
for (const choice of response.choices) {
|
|
164
|
+
try {
|
|
165
|
+
choice.message.content = JSON.parse(choice.message.content);
|
|
166
|
+
} catch {
|
|
167
|
+
console.log(`Unable to parse JSON: ${choice.message.content}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
162
172
|
if (response) {
|
|
163
173
|
$.export("$summary", `Successfully sent chat with id ${response.id}`);
|
|
164
174
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import openai from "../../openai.app.mjs";
|
|
2
|
+
import FormData from "form-data";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
key: "openai-create-transcription",
|
|
7
|
+
name: "Create Transcription",
|
|
8
|
+
description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createTranscription)",
|
|
9
|
+
version: "0.2.0",
|
|
10
|
+
type: "action",
|
|
11
|
+
props: {
|
|
12
|
+
openai,
|
|
13
|
+
file: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
openai,
|
|
16
|
+
"file",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
model: {
|
|
20
|
+
type: "string",
|
|
21
|
+
label: "Model",
|
|
22
|
+
description: "ID of the model to use",
|
|
23
|
+
options: [
|
|
24
|
+
"gpt-4o-transcribe",
|
|
25
|
+
"gpt-4o-mini-transcribe",
|
|
26
|
+
"whisper-1",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
include: {
|
|
30
|
+
type: "string[]",
|
|
31
|
+
label: "Include",
|
|
32
|
+
description: "Additional information to include in the transcription response. `logprobs` will return the log probabilities of the tokens in the response to understand the model's confidence in the transcription. `logprobs` only works with response_format set to `json` and only with the models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`.",
|
|
33
|
+
optional: true,
|
|
34
|
+
},
|
|
35
|
+
language: {
|
|
36
|
+
type: "string",
|
|
37
|
+
label: "Language",
|
|
38
|
+
description: "The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. en) format will improve accuracy and latency.",
|
|
39
|
+
default: "en",
|
|
40
|
+
optional: true,
|
|
41
|
+
},
|
|
42
|
+
prompt: {
|
|
43
|
+
type: "string",
|
|
44
|
+
label: "Prompt",
|
|
45
|
+
description: "An optional text to guide the model's style or continue a previous audio segment. The [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match the audio language.",
|
|
46
|
+
optional: true,
|
|
47
|
+
},
|
|
48
|
+
response_format: {
|
|
49
|
+
type: "string",
|
|
50
|
+
label: "Response Format",
|
|
51
|
+
description: "The format of the output. For `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`, the only supported format is `json`.",
|
|
52
|
+
options: [
|
|
53
|
+
"json",
|
|
54
|
+
"text",
|
|
55
|
+
"srt",
|
|
56
|
+
"verbose_json",
|
|
57
|
+
"vtt",
|
|
58
|
+
],
|
|
59
|
+
optional: true,
|
|
60
|
+
},
|
|
61
|
+
temperature: {
|
|
62
|
+
type: "string",
|
|
63
|
+
label: "Temperature",
|
|
64
|
+
description: "The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.",
|
|
65
|
+
optional: true,
|
|
66
|
+
},
|
|
67
|
+
timestamp_granularities: {
|
|
68
|
+
type: "string[]",
|
|
69
|
+
label: "Timestamp Granularities",
|
|
70
|
+
description: "The timestamp granularities to populate for this transcription. `response_format` must be set `verbose_json` to use timestamp granularities. Either or both of these options are supported: `word`, or `segment`. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.",
|
|
71
|
+
optional: true,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
methods: {
|
|
75
|
+
createTranscription(opts = {}) {
|
|
76
|
+
return this.openai._makeRequest({
|
|
77
|
+
method: "POST",
|
|
78
|
+
path: "/audio/transcriptions",
|
|
79
|
+
...opts,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
async run({ $ }) {
|
|
84
|
+
const {
|
|
85
|
+
/* eslint-disable no-unused-vars */
|
|
86
|
+
openai,
|
|
87
|
+
file,
|
|
88
|
+
createTranscription,
|
|
89
|
+
...fields
|
|
90
|
+
} = this;
|
|
91
|
+
|
|
92
|
+
const data = new FormData();
|
|
93
|
+
const content = fs.createReadStream(file.includes("tmp/")
|
|
94
|
+
? file
|
|
95
|
+
: `/tmp/${file}`);
|
|
96
|
+
|
|
97
|
+
data.append("file", content);
|
|
98
|
+
|
|
99
|
+
for (const [
|
|
100
|
+
key,
|
|
101
|
+
value,
|
|
102
|
+
] of Object.entries(fields)) {
|
|
103
|
+
const v = Array.isArray(value)
|
|
104
|
+
? value.join(",")
|
|
105
|
+
: value;
|
|
106
|
+
data.append(key, v);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const response = await createTranscription({
|
|
110
|
+
$,
|
|
111
|
+
data,
|
|
112
|
+
headers: data.getHeaders(),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
$.export("$summary", "Successfully converted speech to text");
|
|
116
|
+
return response;
|
|
117
|
+
},
|
|
118
|
+
};
|