Context
Leverage ChatGPT capabilities to draft content for you. It could be for an email or an actual contract, as the format is quite open with the ability to add the prompt you like when connecting this custom action in your application. This example runs with ChatGPT API.
Metadata
{
"key": "ask-GPT",
"name": "Get Completion from GPT4",
"description": "Gets a completion from GPT4",
"developerEmail": "email@bryter.io",
"parameters": [
{
"name": "prompt",
"type": "text",
"description": "The prompt"
}
],
"connections": [{
"id": "<Connection ID>",
"alias": "ChatGptKey"
}],
"result": {
"type": "text",
"description": "The completion"
}
}
Action
Caution: This action requires an API key for the OpenAI API. The API then needs to be added securely as a connection in BRYTER platform.
async function main(prompt: string, connections): Promise<string> {
try {
const url = "https://api.openai.com/v1/chat/completions"
const config = {
model: "gpt-4",
messages: [{role:"user", content:"prompt"}],
max_tokens: 100,
temperature: 0.6,
};
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${connections['ChatGptKey'].token}`,
},
body: JSON.stringify(config),
});
if (response.status === 200) {
const data = await response.json();
const completion = data["choices"][0]["message"]["content"];
return completion;
}
else {
console.log('Error', response.status)
throw new Error(`Error: ${response.status}`);
}
} catch (e) {
throw new Error('Error contacting API', e.message)
}
}