diff --git a/README.md b/README.md index b5272538221..c5dd42d8f49 100644 --- a/README.md +++ b/README.md @@ -113,10 +113,6 @@ To learn about the Prompt class, refer to the [Prompt API guide](https://docs.sp Delve into PromptTemplates in our [concept guide](https://docs.spring.io/spring-ai/reference/concepts.html#_prompt_templates). For a hands-on guide to PromptTemplate, see the [PromptTemplate API guide](https://docs.spring.io/spring-ai/reference/api/prompt-template.html). -**Output Parsers:** AI model outputs often come as raw `java.lang.String` values. Output Parsers restructure these raw strings into more programmer-friendly formats, such as CSV or JSON. - -Get insights on Output Parsers in our [concept guide](https://docs.spring.io/spring-ai/reference/concepts.html#_output_parsing).. -For implementation details, visit the [StructuredOutputConverter API guide](https://docs.spring.io/spring-ai/reference/api/output-parser.html). ### Incorporating your data diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java index 14c58fc3bc8..aaad145b5d6 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java @@ -187,9 +187,9 @@ void beanOutputConverterRecords() { @Test void beanStreamOutputConverterRecords() { - BeanOutputConverter outputParser = new BeanOutputConverter<>(ActorsFilmsRecord.class); + BeanOutputConverter converter = new BeanOutputConverter<>(ActorsFilmsRecord.class); - String format = outputParser.getFormat(); + String format = converter.getFormat(); String template = """ Generate the filmography of 5 movies for Tom Hanks. {format} @@ -208,7 +208,7 @@ void beanStreamOutputConverterRecords() { .filter(Objects::nonNull) .collect(Collectors.joining()); - ActorsFilmsRecord actorsFilms = outputParser.convert(generationTextFromStream); + ActorsFilmsRecord actorsFilms = converter.convert(generationTextFromStream); logger.info("" + actorsFilms); assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks"); assertThat(actorsFilms.movies()).hasSize(5); diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java index 530101a83d9..e0893036b3f 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java @@ -111,9 +111,9 @@ void roleTest() { @Test void listOutputConverter() { DefaultConversionService conversionService = new DefaultConversionService(); - ListOutputConverter outputParser = new ListOutputConverter(conversionService); + ListOutputConverter converter = new ListOutputConverter(conversionService); - String format = outputParser.getFormat(); + String format = converter.getFormat(); String template = """ List five {subject} {format} @@ -123,7 +123,7 @@ void listOutputConverter() { Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); - List list = outputParser.convert(generation.getOutput().getContent()); + List list = converter.convert(generation.getOutput().getContent()); assertThat(list).hasSize(5); } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatModelIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatModelIT.java index 97085c2c2b9..45bc6fed1bb 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatModelIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatModelIT.java @@ -103,7 +103,6 @@ void roleTest() { assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); } - // @Disabled("TODO: Fix the parser instructions to return the correct format") @Test void listOutputConverter() { DefaultConversionService conversionService = new DefaultConversionService(); @@ -123,7 +122,6 @@ void listOutputConverter() { assertThat(list).hasSize(5); } - // @Disabled("TODO: Fix the parser instructions to return the correct format") @Test void mapOutputConverter() { MapOutputConverter outputConverter = new MapOutputConverter(); @@ -148,7 +146,7 @@ void mapOutputConverter() { record ActorsFilmsRecord(String actor, List movies) { } - @Disabled("TODO: Fix the parser instructions to return the correct format") + @Disabled("TODO: Fix the converter instructions to return the correct format") @Test void beanOutputConverterRecords() { @@ -169,7 +167,7 @@ void beanOutputConverterRecords() { assertThat(actorsFilms.movies()).hasSize(5); } - @Disabled("TODO: Fix the parser instructions to return the correct format") + @Disabled("TODO: Fix the converter instructions to return the correct format") @Test void beanStreamOutputConverterRecords() { diff --git a/models/spring-ai-moonshot/src/test/java/org/springframework/ai/moonshot/chat/MoonshotChatModelIT.java b/models/spring-ai-moonshot/src/test/java/org/springframework/ai/moonshot/chat/MoonshotChatModelIT.java index d38eaf3f9e7..f0b4b794451 100644 --- a/models/spring-ai-moonshot/src/test/java/org/springframework/ai/moonshot/chat/MoonshotChatModelIT.java +++ b/models/spring-ai-moonshot/src/test/java/org/springframework/ai/moonshot/chat/MoonshotChatModelIT.java @@ -122,7 +122,7 @@ void mapOutputConverter() { } @Test - void beanOutputParser() { + void beanOutputConverter() { BeanOutputConverter outputConverter = new BeanOutputConverter<>(ActorsFilms.class); @@ -143,7 +143,7 @@ record ActorsFilmsRecord(String actor, List movies) { } @Test - void beanOutputParserRecords() { + void beanOutputConverterRecords() { BeanOutputConverter outputConverter = new BeanOutputConverter<>(ActorsFilmsRecord.class); @@ -170,7 +170,7 @@ void beanOutputParserRecords() { } @Test - void beanStreamOutputParserRecords() { + void beanStreamOutputConverterRecords() { BeanOutputConverter outputConverter = new BeanOutputConverter<>(ActorsFilmsRecord.class); diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java index 764609a8404..b11c8f1ec9c 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java @@ -105,9 +105,9 @@ private Prompt createPrompt(VertexAiGeminiChatOptions chatOptions) { @Test void listOutputConverter() { DefaultConversionService conversionService = new DefaultConversionService(); - ListOutputConverter outputParser = new ListOutputConverter(conversionService); + ListOutputConverter converter = new ListOutputConverter(conversionService); - String format = outputParser.getFormat(); + String format = converter.getFormat(); String template = """ List five {subject} {format} @@ -117,7 +117,7 @@ void listOutputConverter() { Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); - List list = outputParser.convert(generation.getOutput().getContent()); + List list = converter.convert(generation.getOutput().getContent()); assertThat(list).hasSize(5); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java b/spring-ai-core/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java index 224a96fc3ad..424d291de7c 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java @@ -46,7 +46,7 @@ /** * An implementation of {@link StructuredOutputConverter} that transforms the LLM output - * to a specific object type using JSON schema. This parser works by generating a JSON + * to a specific object type using JSON schema. This converter works by generating a JSON * schema based on a given Java class or parameterized type reference, which is then used * to validate and transform the LLM output into the desired type. * diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractConversionServiceOutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractConversionServiceOutputParser.java deleted file mode 100644 index 4e5224863cb..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractConversionServiceOutputParser.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ai.parser; - -import org.springframework.core.convert.support.DefaultConversionService; - -/** - * @deprecated Use the - * {@link org.springframework.ai.converter.AbstractConversionServiceOutputConverter} - * instead. - * - * Abstract {@link OutputParser} implementation that uses a pre-configured - * {@link DefaultConversionService} to convert the LLM output into the desired type - * format. - * @param Specifies the desired response type. - * @author Mark Pollack - * @author Christian Tzolov - */ -public abstract class AbstractConversionServiceOutputParser implements OutputParser { - - private final DefaultConversionService conversionService; - - public AbstractConversionServiceOutputParser(DefaultConversionService conversionService) { - this.conversionService = conversionService; - } - - public DefaultConversionService getConversionService() { - return conversionService; - } - -} \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractMessageConverterOutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractMessageConverterOutputParser.java deleted file mode 100644 index cc1e71504ee..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/AbstractMessageConverterOutputParser.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ai.parser; - -import org.springframework.messaging.converter.MessageConverter; - -/** - * @deprecated Use the - * {@link org.springframework.ai.converter.AbstractMessageOutputConverter} instead. - * - * Abstract {@link OutputParser} implementation that uses a pre-configured - * {@link MessageConverter} to convert the LLM output into the desired type format. - * @param Specifies the desired response type. - * @author Mark Pollack - * @author Christian Tzolov - */ -public abstract class AbstractMessageConverterOutputParser implements OutputParser { - - private MessageConverter messageConverter; - - public AbstractMessageConverterOutputParser(MessageConverter messageConverter) { - this.messageConverter = messageConverter; - } - - public MessageConverter getMessageConverter() { - return this.messageConverter; - } - -} \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/BeanOutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/BeanOutputParser.java deleted file mode 100644 index 625dee21549..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/BeanOutputParser.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.util.DefaultIndenter; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.github.victools.jsonschema.generator.SchemaGenerator; -import com.github.victools.jsonschema.generator.SchemaGeneratorConfig; -import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder; -import com.github.victools.jsonschema.module.jackson.JacksonModule; - -import java.util.Map; -import java.util.Objects; - -import org.springframework.ai.util.JacksonUtils; - -import static com.github.victools.jsonschema.generator.OptionPreset.PLAIN_JSON; -import static com.github.victools.jsonschema.generator.SchemaVersion.DRAFT_2020_12; - -/** - * @deprecated Use the {@link org.springframework.ai.converter.BeanOutputConverter} - * instead. - * - * An implementation of {@link OutputParser} that transforms the LLM output to a specific - * object type using JSON schema. This parser works by generating a JSON schema based on a - * given Java class, which is then used to validate and transform the LLM output into the - * desired type. - * @param The target type to which the output will be converted. - * @author Mark Pollack - * @author Christian Tzolov - * @author Sebastian Ullrich - * @author Kirk Lund - */ -public class BeanOutputParser implements OutputParser { - - /** Holds the generated JSON schema for the target type. */ - private String jsonSchema; - - /** The Java class representing the target type. */ - @SuppressWarnings({ "FieldMayBeFinal", "rawtypes" }) - private Class clazz; - - /** The object mapper used for deserialization and other JSON operations. */ - @SuppressWarnings("FieldMayBeFinal") - private ObjectMapper objectMapper; - - /** - * Constructor to initialize with the target type's class. - * @param clazz The target type's class. - */ - public BeanOutputParser(Class clazz) { - this(clazz, null); - } - - /** - * Constructor to initialize with the target type's class, a custom object mapper, and - * a line endings normalizer to ensure consistent line endings on any platform. - * @param clazz The target type's class. - * @param objectMapper Custom object mapper for JSON operations. endings. - */ - public BeanOutputParser(Class clazz, ObjectMapper objectMapper) { - Objects.requireNonNull(clazz, "Java Class cannot be null;"); - this.clazz = clazz; - this.objectMapper = objectMapper != null ? objectMapper : getObjectMapper(); - generateSchema(); - } - - /** - * Generates the JSON schema for the target type. - */ - private void generateSchema() { - JacksonModule jacksonModule = new JacksonModule(); - SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(DRAFT_2020_12, PLAIN_JSON) - .with(jacksonModule); - SchemaGeneratorConfig config = configBuilder.build(); - SchemaGenerator generator = new SchemaGenerator(config); - JsonNode jsonNode = generator.generateSchema(this.clazz); - ObjectWriter objectWriter = this.objectMapper.writer(new DefaultPrettyPrinter() - .withObjectIndenter(new DefaultIndenter().withLinefeed(System.lineSeparator()))); - try { - this.jsonSchema = objectWriter.writeValueAsString(jsonNode); - } - catch (JsonProcessingException e) { - throw new RuntimeException("Could not pretty print json schema for " + this.clazz, e); - } - } - - @Override - /** - * Parses the given text to transform it to the desired target type. - * @param text The LLM output in string format. - * @return The parsed output in the desired target type. - */ - public T parse(String text) { - try { - // If the response is a JSON Schema, extract the properties and use them as - // the response. - text = this.jsonSchemaToInstance(text); - return (T) this.objectMapper.readValue(text, this.clazz); - } - catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - /** - * Converts a JSON Schema to an instance based on a given text. - * @param text The JSON Schema in string format. - * @return The JSON instance generated from the JSON Schema, or the original text if - * the input is not a JSON Schema. - */ - private String jsonSchemaToInstance(String text) { - try { - Map map = this.objectMapper.readValue(text, Map.class); - if (map.containsKey("$schema")) { - return this.objectMapper.writeValueAsString(map.get("properties")); - } - } - catch (Exception e) { - } - return text; - } - - /** - * Configures and returns an object mapper for JSON operations. - * @return Configured object mapper. - */ - protected ObjectMapper getObjectMapper() { - return JsonMapper.builder() - .addModules(JacksonUtils.instantiateAvailableModules()) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .build(); - } - - /** - * Provides the expected format of the response, instructing that it should adhere to - * the generated JSON schema. - * @return The instruction format string. - */ - @Override - public String getFormat() { - String template = """ - Your response should be in JSON format. - Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation. - Do not include markdown code blocks in your response. - Here is the JSON Schema instance your output must adhere to: - ```%s``` - """; - return String.format(template, this.jsonSchema); - } - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/FormatProvider.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/FormatProvider.java deleted file mode 100644 index 087c15fe5cc..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/FormatProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -/** - * Implementations of this interface provides instructions for how the output of a - * language generative should be formatted. - * - * @author Mark Pollack - * @deprecated Use the {@link org.springframework.ai.converter.FormatProvider} instead. - */ -public interface FormatProvider { - - /** - * @return Returns a string containing instructions for how the output of a language - * generative should be formatted. - */ - String getFormat(); - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/ListOutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/ListOutputParser.java deleted file mode 100644 index d4f243835d9..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/ListOutputParser.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -import java.util.List; - -import org.springframework.core.convert.support.DefaultConversionService; - -/** - * @deprecated Use the {@link org.springframework.ai.converter.ListOutputConverter} - * instead. - * - * {@link OutputParser} implementation that uses a {@link DefaultConversionService} to - * convert the LLM output into a {@link java.util.List} instance. - * @author Mark Pollack - * @author Christian Tzolov - */ -public class ListOutputParser extends AbstractConversionServiceOutputParser> { - - public ListOutputParser(DefaultConversionService defaultConversionService) { - super(defaultConversionService); - } - - @Override - public String getFormat() { - return """ - Your response should be a list of comma separated values - eg: `foo, bar, baz` - """; - } - - @Override - public List parse(String text) { - return getConversionService().convert(text, List.class); - } - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/MapOutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/MapOutputParser.java deleted file mode 100644 index a222d7940ba..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/MapOutputParser.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.messaging.Message; -import org.springframework.messaging.converter.MappingJackson2MessageConverter; -import org.springframework.messaging.support.MessageBuilder; - -/** - * @deprecated Use the {@link org.springframework.ai.converter.MapOutputConverter} - * instead. - * - * {@link OutputParser} implementation that uses a pre-configured - * {@link MappingJackson2MessageConverter} to convert the LLM output into a - * java.util.Map<String, Object> instance. - * @author Mark Pollack - * @author Christian Tzolov - */ -public class MapOutputParser extends AbstractMessageConverterOutputParser> { - - public MapOutputParser() { - super(new MappingJackson2MessageConverter()); - } - - @Override - public Map parse(String text) { - Message message = MessageBuilder.withPayload(text.getBytes(StandardCharsets.UTF_8)).build(); - return (Map) getMessageConverter().fromMessage(message, HashMap.class); - } - - @Override - public String getFormat() { - String raw = """ - Your response should be in JSON format. - The data structure for the JSON should match this Java class: %s - Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation. - """; - return String.format(raw, "java.util.HashMap"); - } - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/OutputParser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/OutputParser.java deleted file mode 100644 index 57ad9c274cd..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/OutputParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -/** - * Converts the (raw) LLM output into a structured responses of type. The - * {@link FormatProvider#getFormat()} method should provide the LLM prompt description of - * the desired format. - * - * @param Specifies the desired response type. - * @author Mark Pollack - * @author Christian Tzolov - * @deprecated Use the {@link org.springframework.ai.converter.StructuredOutputConverter} - * instead. - */ -public interface OutputParser extends Parser, FormatProvider { - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/Parser.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/Parser.java deleted file mode 100644 index 03f9cc0d9b4..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/Parser.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2023 - 2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ai.parser; - -@FunctionalInterface -public interface Parser { - - T parse(String text); - -} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/README.md b/spring-ai-core/src/main/java/org/springframework/ai/parser/README.md deleted file mode 100644 index 49fcedaefe5..00000000000 --- a/spring-ai-core/src/main/java/org/springframework/ai/parser/README.md +++ /dev/null @@ -1,13 +0,0 @@ -Deprecated! uset the Structured output instead. - -# Output Parsing - -* [Documentation](https://docs.spring.io/spring-ai/reference/concepts.html#_output_parsing) - -The output of AI models traditionally arrives as a java.util.String, even if you ask for the reply to be in JSON. It may be a correct JSON, but it isn’t a JSON data structure. It is just a string. Also, asking "for JSON" as part of the prompt isn’t 100% accurate. - -This intricacy has led to the emergence of a specialized field involving the creation of prompts to yield the intended output, followed by parsing the resulting simple string into a usable data structure for application integration. - -Output parsing employs meticulously crafted prompts, often necessitating multiple interactions with the model to achieve the desired formatting. - -This challenge has prompted OpenAI to introduce 'OpenAI Functions' as a means to specify the desired output format from the model precisely.