Skip to content

Commit

Permalink
Make function call port optional, strip other properties, and strip w…
Browse files Browse the repository at this point in the history
…hen no name or arguments properties
  • Loading branch information
abrenneke committed Oct 30, 2023
1 parent f22e5e4 commit 1d43211
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/core/src/model/nodes/PromptNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { nanoid } from 'nanoid/non-secure';
import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
import { nodeDefinition } from '../NodeDefinition.js';
import {
coerceTypeOptional,
type ChatMessage,
type EditorDefinition,
type Inputs,
Expand Down Expand Up @@ -214,10 +215,15 @@ export class PromptNodeImpl extends NodeImpl<PromptNode> {

const name = getInputOrData(this.data, inputs, 'name', 'string');

const functionCall = this.data.enableFunctionCall
? coerceType(inputs['function-call' as PortId], 'object')
let functionCall = this.data.enableFunctionCall
? coerceTypeOptional(inputs['function-call' as PortId], 'object')
: undefined;

// If no name is specified, ignore the function call
if (!functionCall?.name || !functionCall?.arguments) {
functionCall = undefined;
}

// GPT is weird - the arguments should be a stringified JSON object https://platform.openai.com/docs/api-reference/chat/create
if (functionCall?.arguments && typeof functionCall.arguments !== 'string') {
functionCall.arguments = JSON.stringify(functionCall.arguments);
Expand All @@ -227,7 +233,14 @@ export class PromptNodeImpl extends NodeImpl<PromptNode> {
type: type as 'assistant' | 'system' | 'user' | 'function',
message: outputValue,
name,
function_call: functionCall,

// Standardize to only have name and arguments (discard other props)
function_call: functionCall
? {
name: functionCall.name,
arguments: functionCall.arguments,
}
: undefined,
};

const outputs: Outputs = {
Expand Down

0 comments on commit 1d43211

Please sign in to comment.