Skip to content

Commit

Permalink
feat(chat.cr): deal with common AI mistake defining function name
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach authored Nov 2, 2023
1 parent 94e2361 commit b6c669a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/openai/api/chat.cr
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ module OpenAI
end

def execute(call : ChatFunctionCall)
raise OpenAIError.new "Function '#{call.name}' not defined." unless func = @map[call.name]?
# sometime the chat defines the name: "functions.function_name" so we should check for that case
raise OpenAIError.new "Function '#{call.name}' not defined." unless func = @map[call.name]? || @map[call.name.split('.', 2)[-1]]?
params = call.arguments.as_s? || call.arguments.to_s
arg = func.first.from_json(params)
result = func.last.call(arg)
Expand Down

0 comments on commit b6c669a

Please sign in to comment.