Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
import java.util.Map;
import java.util.Set;

import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.util.Assert;

import com.azure.ai.openai.models.AzureChatEnhancementConfiguration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
* The configuration information for a chat completions request. Completions support a
* wide variety of tasks and generate text that continues from or "completes" provided
Expand Down Expand Up @@ -145,7 +144,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
* default. Use the enableFunctions to set the functions from the registry to be used
* by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure if this should work even if we kept the annotation as how does boot know what class that implements FunctionCallback to create?

I tried the following in application.yaml

spring:
  ai:
    azure:
      openai:
        chat:
          options:
            function-callbacks:
              - name: "functionName1"
                description: "Description of what function1 does"
                input-type-schema: |
                  {
                    "type": "object",
                    "properties": {
                      "param1": {
                        "type": "string"
                      }
                    }
                  }
              - name: "functionName2"
                description: "Description of what function2 does"
                input-type-schema: |
                  {
                    "type": "object",
                    "properties": {
                      "param2": {
                        "type": "integer"
                      }
                    }
                  }

and got the following error

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-10-30T11:41:55.878-04:00 ERROR 11409 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target [Bindable@7b6141f0 type = java.util.List<org.springframework.ai.model.function.FunctionCallback>, value = 'provided', annotations = array<Annotation>[@com.fasterxml.jackson.annotation.JsonIgnore(true)], bindMethod = [null]] failed:

    Property: spring.ai.azure.openai.chat.options.function-callbacks[0].description
    Value: "Description of what function1 does"
    Origin: class path resource [application.yaml] - 9:30
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.
    Property: spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema
    Value: "{
  "type": "object",
  "properties": {
    "param1": {
      "type": "string"
    }
  }
}
"
    Origin: class path resource [application.yaml] - 10:36
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.
    Property: spring.ai.azure.openai.chat.options.function-callbacks[0].name
    Value: "functionName1"
    Origin: class path resource [application.yaml] - 8:23
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.
    Property: spring.ai.azure.openai.chat.options.function-callbacks[1].description
    Value: "Description of what function2 does"
    Origin: class path resource [application.yaml] - 20:30
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.
    Property: spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema
    Value: "{
  "type": "object",
  "properties": {
    "param2": {
      "type": "integer"
    }
  }
}"
    Origin: class path resource [application.yaml] - 21:36
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.
    Property: spring.ai.azure.openai.chat.options.function-callbacks[1].name
    Value: "functionName2"
    Origin: class path resource [application.yaml] - 19:23
    Reason: The elements [spring.ai.azure.openai.chat.options.function-callbacks[0].description,spring.ai.azure.openai.chat.options.function-callbacks[0].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[0].name,spring.ai.azure.openai.chat.options.function-callbacks[1].description,spring.ai.azure.openai.chat.options.function-callbacks[1].input-type-schema,spring.ai.azure.openai.chat.options.function-callbacks[1].name] were left unbound.

Action:

Update your application's configuration

This can be researched in a separate issue as it is more important to remove the boot dependency in core than wait for solution to these sort of infrequently used options.

@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();

Expand All @@ -160,7 +158,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
* functions is set in a prompt options, then the enabled functions are only active
* for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

Expand Down Expand Up @@ -194,11 +191,9 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
* If provided, the configuration options for available Azure OpenAI chat
* enhancements.
*/
@NestedConfigurationProperty
@JsonIgnore
private AzureChatEnhancementConfiguration enhancements;

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.ai.minimax.api.MiniMaxApi;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -88,7 +87,6 @@ public class MiniMaxChatOptions implements FunctionCallingOptions, ChatOptions {
/**
* Up to 4 sequences where the API will stop generating further tokens.
*/
@NestedConfigurationProperty
private @JsonProperty("stop") List<String> stop;
/**
* What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output
Expand All @@ -112,7 +110,6 @@ public class MiniMaxChatOptions implements FunctionCallingOptions, ChatOptions {
* A list of tools the model may call. Currently, only functions are supported as a tool. Use this to
* provide a list of functions the model may generate JSON inputs for.
*/
@NestedConfigurationProperty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to above with FunctionCallback in Azure options.

private @JsonProperty("tools") List<MiniMaxApi.FunctionTool> tools;
/**
* Controls which (if any) function is called by the model. none means the model will not call a
Expand All @@ -129,7 +126,6 @@ public class MiniMaxChatOptions implements FunctionCallingOptions, ChatOptions {
* For Default Options the functionCallbacks are registered but disabled by default. Use the enableFunctions to set the functions
* from the registry to be used by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();

Expand All @@ -142,14 +138,12 @@ public class MiniMaxChatOptions implements FunctionCallingOptions, ChatOptions {
* Note that function enabled with the default options are enabled for all chat completion requests. This could impact the token count and the billing.
* If the functions is set in a prompt options, then the enabled functions are only active for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

@JsonIgnore
private Boolean proxyToolCalls;

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.ai.model.ChatModelDescription;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -339,7 +338,6 @@ public record FunctionTool(
* Create a tool of type 'function' and the given function definition.
* @param function function definition.
*/
@ConstructorBinding
public FunctionTool(Function function) {
this(Type.FUNCTION, function);
}
Expand Down Expand Up @@ -381,7 +379,6 @@ public record Function(
* @param name tool function name.
* @param parameters tool function schema.
*/
@ConstructorBinding
public Function(String description, String name, Map<String, Object> parameters) {
this(description, name, ModelOptionsUtils.toJsonString(parameters));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -94,23 +93,20 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
* Stop generation if this token is detected. Or if one of these tokens is detected
* when providing an array.
*/
@NestedConfigurationProperty
private @JsonProperty("stop") List<String> stop;

/**
* A list of tools the model may call. Currently, only functions are supported as a
* tool. Use this to provide a list of functions the model may generate JSON inputs
* for.
*/
@NestedConfigurationProperty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an entry for this in the metadata.json file.

private @JsonProperty("tools") List<FunctionTool> tools;

/**
* Controls which (if any) function is called by the model. none means the model will
* not call a function and instead generates a message. auto means the model can pick
* between generating a message or calling a function.
*/
@NestedConfigurationProperty
private @JsonProperty("tool_choice") ToolChoice toolChoice;

/**
Expand All @@ -120,7 +116,6 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
* disabled by default. Use the enableFunctions to set the functions from the registry
* to be used by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();

Expand All @@ -135,14 +130,12 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
* functions is set in a prompt options, then the enabled functions are only active
* for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

@JsonIgnore
private Boolean proxyToolCalls;

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.observation.conventions.AiProvider;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -324,7 +323,6 @@ public record FunctionTool(@JsonProperty("type") Type type, @JsonProperty("funct
* Create a tool of type 'function' and the given function definition.
* @param function function definition.
*/
@ConstructorBinding
public FunctionTool(Function function) {
this(Type.FUNCTION, function);
}
Expand Down Expand Up @@ -362,7 +360,6 @@ public record Function(@JsonProperty("description") String description, @JsonPro
* @param name tool function name.
* @param jsonSchema tool function schema as json.
*/
@ConstructorBinding
public Function(String description, String name, String jsonSchema) {
this(description, name, ModelOptionsUtils.jsonToMap(jsonSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.moonshot.api.MoonshotApi;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -90,10 +89,8 @@ public class MoonshotChatOptions implements FunctionCallingOptions, ChatOptions
/**
* Up to 5 sequences where the API will stop generating further tokens.
*/
@NestedConfigurationProperty
private @JsonProperty("stop") List<String> stop;

@NestedConfigurationProperty
private @JsonProperty("tools") List<MoonshotApi.FunctionTool> tools;

/**
Expand All @@ -115,7 +112,6 @@ public class MoonshotChatOptions implements FunctionCallingOptions, ChatOptions
* default. Use the enableFunctions to set the functions from the registry to be used
* by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar situation to other List< Rich Data Type> comments.


Expand All @@ -130,7 +126,6 @@ public class MoonshotChatOptions implements FunctionCallingOptions, ChatOptions
* functions is set in a prompt options, then the enabled functions are only active
* for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

Expand All @@ -143,7 +138,6 @@ public class MoonshotChatOptions implements FunctionCallingOptions, ChatOptions
@JsonIgnore
private Boolean proxyToolCalls;

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.ai.model.ChatModelDescription;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -600,7 +599,6 @@ public record FunctionTool(@JsonProperty("type") Type type, @JsonProperty("funct
* Create a tool of type 'function' and the given function definition.
* @param function function definition.
*/
@ConstructorBinding
public FunctionTool(Function function) {
this(Type.FUNCTION, function);
}
Expand Down Expand Up @@ -638,7 +636,6 @@ public record Function(@JsonProperty("description") String description, @JsonPro
* @param name tool function name.
* @param jsonSchema tool function schema as json.
*/
@ConstructorBinding
public Function(String description, String name, String jsonSchema) {
this(description, name, ModelOptionsUtils.jsonToMap(jsonSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.observation.conventions.AiProvider;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -654,7 +653,6 @@ public record Tool(
* Create a tool of type 'function' and the given function definition.
* @param function function definition.
*/
@ConstructorBinding
public Tool(Function function) {
this(Type.FUNCTION, function);
}
Expand Down Expand Up @@ -690,7 +688,6 @@ public record Function(
* @param name tool function name.
* @param jsonSchema tool function schema as json.
*/
@ConstructorBinding
public Function(String description, String name, String jsonSchema) {
this(description, name, ModelOptionsUtils.jsonToMap(jsonSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -280,7 +279,6 @@ public class OllamaOptions implements FunctionCallingOptions, ChatOptions, Embed
* For Default Options the functionCallbacks are registered but disabled by default. Use the enableFunctions to set the functions
* from the registry to be used by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before

@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();

Expand All @@ -292,14 +290,12 @@ public class OllamaOptions implements FunctionCallingOptions, ChatOptions, Embed
* Note that function enabled with the default options are enabled for all chat completion requests. This could impact the token count and the billing.
* If the functions is set in a prompt options, then the enabled functions are only active for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

@JsonIgnore
private Boolean proxyToolCalls;

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
6 changes: 0 additions & 6 deletions models/spring-ai-openai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
<version>${project.parent.version}</version>
</dependency>

<!-- NOTE: Required only by the @ConstructorBinding. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.StreamOptions;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.ToolChoiceBuilder;
import org.springframework.ai.openai.api.OpenAiApi.FunctionTool;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -117,7 +116,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
/**
* Up to 4 sequences where the API will stop generating further tokens.
*/
@NestedConfigurationProperty
private @JsonProperty("stop") List<String> stop;
/**
* What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output
Expand All @@ -135,7 +133,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
* A list of tools the model may call. Currently, only functions are supported as a tool. Use this to
* provide a list of functions the model may generate JSON inputs for.
*/
@NestedConfigurationProperty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before

private @JsonProperty("tools") List<FunctionTool> tools;
/**
* Controls which (if any) function is called by the model. none means the model will not call a
Expand All @@ -161,7 +158,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
* For Default Options the functionCallbacks are registered but disabled by default. Use the enableFunctions to set the functions
* from the registry to be used by the ChatModel chat completion requests.
*/
@NestedConfigurationProperty
@JsonIgnore
private List<FunctionCallback> functionCallbacks = new ArrayList<>();

Expand All @@ -174,7 +170,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
* Note that function enabled with the default options are enabled for all chat completion requests. This could impact the token count and the billing.
* If the functions is set in a prompt options, then the enabled functions are only active for the duration of this prompt execution.
*/
@NestedConfigurationProperty
@JsonIgnore
private Set<String> functions = new HashSet<>();

Expand All @@ -189,11 +184,9 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
/**
* Optional HTTP headers to be added to the chat completion request.
*/
@NestedConfigurationProperty
@JsonIgnore
private Map<String, String> httpHeaders = new HashMap<>();

@NestedConfigurationProperty
@JsonIgnore
private Map<String, Object> toolContext;

Expand Down
Loading