Skip to content

Pass JSON Schema directly to 'function' parameter #786

Closed Answered by benzourry
benzourry asked this question in Q&A
Discussion options

You must be logged in to vote

Update: I achieved it using model.generate() which accepts ToolSpecification

    public JsonNode extractToJson(String jsonSchemaString, String text) {
        ToolParameters params = ToolParameters.builder()
                .properties(objectMapper.readValue(jsonSchemaString, Map.class))
                .build();

        ToolSpecification spec = ToolSpecification.builder()
                .name("extract")
                .description("Extract to json")
                .parameters(params)
                .build();

        List<ChatMessage> messages = Collections.singletonList(
                new UserMessage("Extract json from text " + text)
        );

        return mapper.readTree(
  …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@langchain4j
Comment options

Answer selected by langchain4j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants