Skip to content

Commit

Permalink
Revert function calling
Browse files Browse the repository at this point in the history
Revert function calling and include support for message properties `msg.API_KEY` and `msg.ORGANIZATION`
  • Loading branch information
HaroldPetersInskipp authored Jan 17, 2024
1 parent ccbcf96 commit fc12bac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# Change Log

## [1.2.16] - 2024-01-17

### Changed

- Reverted function calling with GPT-4 model due to issues
- Included support for message properties `msg.API_KEY` and `msg.ORGANIZATION`

## [1.2.15] - 2024-01-12

### Changed
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ For detailed information on the usage of these modes, please refer to the [OpenA

- [Optional] `msg.history` should be an array of objects containing the conversation history. [Default:`[]`]

- [Optional] `msg.functions` should be an array of objects defining function behaviors for the model. Each object must contain a `name` and `behavior` property. [Default:`[]`]

- [Optional] `msg.function_call` should be a string or object that controls how the model responds to function calls. "none" means the model does not call a function and responds to the end-user. "auto" allows the model to decide. Specifying a particular function via `{"name":"my_function"}` forces the model to call that function. [Default:`none` if no functions, `auto` if functions are present]

### Additional optional properties

The following optional inputs are supported - `msg.max_tokens`, `msg.suffix`, `msg.n`, `msg.temperature`, `msg.top_p`, `msg.presence_penalty`, `msg.frequency_penalty`, and `msg.echo`. See the nodes built-in help tab for more information on how they are used.
The following optional inputs are supported - `msg.max_tokens`, `msg.suffix`, `msg.n`, `msg.temperature`, `msg.top_p`, `msg.presence_penalty`, `msg.frequency_penalty`, `msg.echo`, `msg.API_KEY` and `msg.ORGANIZATION`. See the nodes built-in help tab for more information on how they are used.

## Examples

Expand Down
26 changes: 12 additions & 14 deletions chatgpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,7 @@ <h3>Inputs</h3>
<span class="property-type">string</span>
</dt>
<dd> The topic and node behavior to select.</dd>

<dt class="optional">msg.function
<span class="property-type">string</span>
</dt>
<dd> (GPT-4 only) The function to be used if specified.</dd>

<dt class="optional">msg.function_call
<span class="property-type">string</span>
</dt>
<dd> (GPT-4 only) Whether to call the function automatically or not. Set to 'auto' if functions are present, 'none' if no functions are specified. [Default:`none` if no functions, `auto` if functions are present]</dd>


<dt class="optional">msg.size
<span class="property-type">string</span>
</dt>
Expand Down Expand Up @@ -160,6 +150,16 @@ <h3>Inputs</h3>
<span class="property-type">boolean</span>
</dt>
<dd> Echo back the prompt in addition to the completion when set to <code>true</code>.</dd>

<dt class="optional">msg.API_KEY
<span class="property-type">string</span>
</dt>
<dd> The API key to be used if not specified in the node.</dd>

<dt class="optional">msg.ORGANIZATION
<span class="property-type">string</span>
</dt>
<dd> The ORGANIZATION to be used if not specified in the node.</dd>
</dl>

<h3>Outputs</h3>
Expand Down Expand Up @@ -200,9 +200,7 @@ <h3>Details</h3>
<p>5. When <code>msg.topic</code> is set to <code>gpt4</code>:</p>
<p>Required <code>msg.payload</code> should be a well-written prompt.</p>
<p>Optional <code>msg.history</code> should be an array of objects containing the conversation history. [Default:<code>[]</code>]</p>
<p>Optional <code>msg.function</code> should contain the function to be used if specified. This parameter is only applicable when using GPT-4.</p>
<p>Optional <code>msg.function_call</code> should indicate whether to call the function automatically or not. It should be set to 'auto' if functions are present, and 'none' if no functions are specified. The default value is 'none' if no functions are specified, and 'auto' if functions are present. This parameter is only applicable when using GPT-4.</p>


<h3>Links</h3>
<ul>
<li><a href="https://github.com/HaroldPetersInskipp/node-red-contrib-chatgpt">GitHub</a> - this node's GitHub repository.</li>
Expand Down
17 changes: 3 additions & 14 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = (RED) => {
RED.nodes.createNode(node, config);

// Extract API key and organization information from credentials
const API_KEY = this.credentials.API_KEY;
const ORGANIZATION = this.credentials.Organization;
const API_KEY = this.credentials.API_KEY || msg.API_KEY;
const ORGANIZATION = this.credentials.Organization || msg.ORGANIZATION;

// Create OpenAI configuration with the provided API key and organization
const configuration = new Configuration({
Expand Down Expand Up @@ -239,16 +239,7 @@ module.exports = (RED) => {
content: msg.payload,
};
msg.history.push(input);
let function_call;
if (msg.function_call) {
function_call = msg.function_call;
} else {
if (msg.functions && msg.functions.length > 0) {
function_call = "auto";
} else {
function_call = "none";
}
}

// Request completion from GPT-4 model
const response = await openai.createChatCompletion({
model: "gpt-4",
Expand All @@ -261,8 +252,6 @@ module.exports = (RED) => {
max_tokens: parseInt(msg.max_tokens) || 4000,
presence_penalty: parseInt(msg.presence_penalty) || 0,
frequency_penalty: parseInt(msg.frequency_penalty) || 0,
functions: msg.functions || null,
function_call,
});
const trimmedContent =
response.data.choices[0].message.content.trim();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-custom-chatgpt",
"version": "1.2.15",
"version": "1.2.16",
"description": "A Node-RED node that interacts with OpenAI machine learning models to generate text and image outputs like 'ChatGPT' and 'DALL·E 2'.",
"main": "chatgpt.js",
"scripts": {
Expand Down

0 comments on commit fc12bac

Please sign in to comment.