forked from langchain4j/langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added output parsers for numeric types (langchain4j#27)
Added output parsers for numeric types: byte, short, int, long, BigInteger, float, double and BigDecimal
- Loading branch information
1 parent
907c1eb
commit ce598df
Showing
9 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
langchain4j/src/main/java/dev/langchain4j/model/output/BigDecimalOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class BigDecimalOutputParser implements OutputParser<BigDecimal> { | ||
|
||
@Override | ||
public BigDecimal parse(String string) { | ||
return new BigDecimal(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "floating point number"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
langchain4j/src/main/java/dev/langchain4j/model/output/BigIntegerOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class BigIntegerOutputParser implements OutputParser<BigInteger> { | ||
|
||
@Override | ||
public BigInteger parse(String string) { | ||
return new BigInteger(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "integer number"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/ByteOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class ByteOutputParser implements OutputParser<Byte> { | ||
|
||
@Override | ||
public Byte parse(String string) { | ||
return Byte.parseByte(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "integer number in range [-128, 127]"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/DoubleOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class DoubleOutputParser implements OutputParser<Double> { | ||
|
||
@Override | ||
public Double parse(String string) { | ||
return Double.parseDouble(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "floating point number"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/FloatOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class FloatOutputParser implements OutputParser<Float> { | ||
|
||
@Override | ||
public Float parse(String string) { | ||
return Float.parseFloat(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "floating point number"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/IntOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class IntOutputParser implements OutputParser<Integer> { | ||
|
||
@Override | ||
public Integer parse(String string) { | ||
return Integer.parseInt(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "integer number"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/LongOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class LongOutputParser implements OutputParser<Long> { | ||
|
||
@Override | ||
public Long parse(String string) { | ||
return Long.parseLong(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "integer number"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
langchain4j/src/main/java/dev/langchain4j/model/output/ShortOutputParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
public class ShortOutputParser implements OutputParser<Short> { | ||
|
||
@Override | ||
public Short parse(String string) { | ||
return Short.parseShort(string); | ||
} | ||
|
||
@Override | ||
public String formatInstructions() { | ||
return "integer number in range [-32768, 32767]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters