Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why not place the tool calling logic in the ChatClient implementation, rather than delegating it to the ChatModel when interacting with the model provider? #4105

lambochen started this conversation in General
Discussion options

It's hypothesized that during design, function calls were thought to be a capability only some models possess, so placing them in the model provider layer (i.e., ChatModel) would be more appropriate. However, as model provider products evolve, they all end up supporting function call capabilities (which is indeed the case, as most models in the market now support function calls). This would lead to ChatModel layer implementations being remarkably similar, resulting in code duplication and redundancy.

Perhaps we can discuss a new implementation approach? For example, abstracting a dedicated tool calling component to handle the current tool calling and model recursive calling logic in ChatModel? Welcome to contribute your ideas, thank you.

Context:ChatModel tool call
org.springframework.ai.openai.OpenAiChatModel#internalCall

public ChatResponse internalCall(Prompt prompt, ChatResponse previousChatResponse) {
		ChatCompletionRequest request = createRequest(prompt, false);
		ChatResponse response = ...
		if (this.toolExecutionEligibilityPredicate.isToolExecutionRequired(prompt.getOptions(), response)) {
			var toolExecutionResult = this.toolCallingManager.executeToolCalls(prompt, response);
			if (toolExecutionResult.returnDirect()) {
				// Return tool execution result directly to the client.
				return ChatResponse.builder()
					.from(response)
					.generations(ToolExecutionResult.buildGenerations(toolExecutionResult))
					.build();
			}
			else {
				// Send the tool execution result back to the model.
				return this.internalCall(new Prompt(toolExecutionResult.conversationHistory(), prompt.getOptions()),
						response);
			}
		}
		return response;
	}
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /