Skip to content

Commit e16fb35

Browse files
author
Zach Ebner
committed
adding LLM parsing and FlexRequests
1 parent aa22d2b commit e16fb35

File tree

10 files changed

+174
-6
lines changed

10 files changed

+174
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The official Java SDK for the Textkernel Tx v10 API for resume/CV and job parsin
1313
### Gradle Users
1414
Add this dependency to your project's build file:
1515
```
16-
implementation "com.textkernel:tx-java:2.0.0"
16+
implementation "com.textkernel:tx-java:2.1.0"
1717
```
1818

1919
### Maven Users
@@ -22,13 +22,13 @@ Add this dependency to your project's POM:
2222
<dependency>
2323
<groupId>com.textkernel</groupId>
2424
<artifactId>tx-java</artifactId>
25-
<version>2.0.0</version>
25+
<version>2.1.0</version>
2626
</dependency>
2727
```
2828

2929
### Others
3030
You'll need to manually install the following JARs:
31-
- The Textkernel Tx JAR from https://repo1.maven.org/maven2/com/textkernel/tx-java/2.0.0/tx-java-2.0.0.jar
31+
- The Textkernel Tx JAR from https://repo1.maven.org/maven2/com/textkernel/tx-java/2.1.0/tx-java-2.1.0.jar
3232
- [Google Gson][gson_url] from https://repo1.maven.org/maven2/com/google/code/gson/gson/2.9.0/gson-2.9.0.jar
3333
- [Square OkHttp][okhttp_url] from https://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/4.9.3/okhttp-4.9.3.jar
3434

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.textkernel</groupId>
55
<artifactId>tx-java</artifactId>
66

7-
<version>2.0.0</version>
7+
<version>2.1.0</version>
88

99
<packaging>jar</packaging>
1010
<name>Textkernel Tx Java SDK</name>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
7+
package com.textkernel.tx.models.api.parsing;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Custom requests to ask during parsing.
13+
* See the <a href="https://developer.textkernel.com/tx-platform/v10/resume-parser/overview/llm-parser/#flex-requests">overview documentation</a> for more details.
14+
* <a href="https://developer.textkernel.com/tx-platform/v10/overview/#transaction-cost">Additional charges</a> will apply.
15+
*/
16+
public class FlexRequest {
17+
/**
18+
* The prompt to be sent to the LLM Parsing Engine
19+
*/
20+
public String Prompt;
21+
22+
/**
23+
* Unique field name to be returned alongside the reply in the response
24+
*/
25+
public String Identifier;
26+
27+
/**
28+
* The data type for the reply
29+
*/
30+
public FlexRequestDataType DataType;
31+
32+
/**
33+
* If DataType is {@link FlexRequestDataType#Enumeration}, this is the list of possible replies. This is limited to a maximum of 50 values.
34+
*/
35+
public List<String> EnumerationValues;
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.textkernel.tx.models.api.parsing;
2+
3+
/**
4+
* Possible data types for FlexRequests
5+
*/
6+
public enum FlexRequestDataType {
7+
Text,
8+
Numeric,
9+
Bool,
10+
List,
11+
Enumeration
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
7+
package com.textkernel.tx.models.api.parsing;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Information about the FlexRequests transaction, if any were provided.
13+
*/
14+
public class FlexResponse {
15+
16+
/** See https://developer.textkernel.com/tx-platform/v10/overview/#http-status-codes*/
17+
public String Code;
18+
19+
/** A short human-readable description explaining the {@link #Code} value*/
20+
public String Message;
21+
22+
/**
23+
* Responses to FlexRequests
24+
*/
25+
public List<FlexResponseItem> Responses;
26+
27+
public boolean isSuccess() {
28+
switch (Code) {
29+
case "Success":
30+
return true;
31+
}
32+
33+
return false;
34+
}
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
7+
package com.textkernel.tx.models.api.parsing;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Responses to FlexRequests
13+
*/
14+
public class FlexResponseItem {
15+
16+
/**
17+
* Unique field name assigned to the respective FlexRequest
18+
*/
19+
public String Identifier;
20+
21+
/**
22+
* Reply to the FlexRequest Prompt
23+
*/
24+
public String Reply;
25+
26+
/**
27+
* List of replies to the FlexRequest Prompt if the FlexRequest had a {@link FlexRequestDataType#Enumeration} DataType
28+
*/
29+
public List<String> ReplyList;
30+
31+
}

src/main/java/com/textkernel/tx/models/api/parsing/ParseOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package com.textkernel.tx.models.api.parsing;
77

8+
import java.util.List;
9+
810
import com.textkernel.tx.models.api.geocoding.GeocodeOptions;
911
import com.textkernel.tx.models.api.indexes.IndexSingleDocumentInfo;
1012

@@ -41,6 +43,20 @@ public class ParseOptions extends BasicParseOptions {
4143
*/
4244
public IndexSingleDocumentInfo IndexingOptions;
4345

46+
/**
47+
* Only used for resumes. When {@code true}, and the document is English, the LLM Parser will be used.
48+
* See the <a href="https://developer.textkernel.com/tx-platform/v10/resume-parser/overview/llm-parser/#overview">overview documentation</a> for more information.
49+
* <a href="https://developer.textkernel.com/tx-platform/v10/overview/#transaction-cost">Additional charges</a> will apply.
50+
*/
51+
public boolean UseLLMParser;
52+
53+
/**
54+
* Only used for resumes. Custom requests to ask during parsing.
55+
* See the <a href="https://developer.textkernel.com/tx-platform/v10/resume-parser/overview/llm-parser/#flex-requests">overview documentation</a> for more information.
56+
* <a href="https://developer.textkernel.com/tx-platform/v10/overview/#transaction-cost">Additional charges</a> will apply.
57+
*/
58+
public List<FlexRequest> FlexRequests;
59+
4460
//********************************
4561
//IF YOU ADD ANY PARAMS HERE BE SURE TO ADD THEM IN THE DEEP COPY INSIDE ParseRequest.ctor() !!
4662
//********************************

src/main/java/com/textkernel/tx/models/api/parsing/ParseRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public ParseRequest(Document doc, ParseOptions optionsToUse) {
5757
this.SkillsData = optionsToUse.SkillsData;
5858
this.SkillsSettings = optionsToUse.SkillsSettings;
5959
this.ProfessionsSettings = optionsToUse.ProfessionsSettings;
60+
this.UseLLMParser = optionsToUse.UseLLMParser;
61+
this.FlexRequests = optionsToUse.FlexRequests;
6062
}
6163
}
6264
}

src/main/java/com/textkernel/tx/models/api/parsing/ParseResumeResponseValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ public class ParseResumeResponseValue extends BaseParseResponseValue {
2222
* this property will contain no {@link ParsedResume#ContactInformation}.
2323
*/
2424
public ParsedResume RedactedResumeData;
25+
26+
/**
27+
* Information about the FlexRequests transaction, if any were provided.
28+
*/
29+
public FlexResponse FlexResponse;
2530
}

src/test/java/com/textkernel/tx/integration/ParsingTests.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import com.textkernel.tx.models.api.geocoding.GeocodeProvider;
1717
import com.textkernel.tx.models.api.indexes.IndexSingleDocumentInfo;
1818
import com.textkernel.tx.models.api.parsing.*;
19-
import com.textkernel.tx.models.api.parsing.SkillsSettings;
20-
import com.textkernel.tx.models.api.parsing.ParseJobResponseValue;
2119

2220
import static org.junit.jupiter.api.Assertions.*;
2321

@@ -35,6 +33,7 @@
3533
import java.nio.file.Files;
3634
import java.nio.file.Paths;
3735
import java.time.LocalDate;
36+
import java.util.ArrayList;
3837
import java.util.UUID;
3938
import java.util.concurrent.atomic.AtomicReference;
4039
import java.util.stream.Stream;
@@ -719,4 +718,36 @@ public void TestJobOrderProfessionNormalization() throws Exception {
719718
assertNotNull(response.Value.JobData.JobTitles.NormalizedProfession.ONET);
720719
assertNotEquals(0, response.Value.JobData.JobTitles.NormalizedProfession.Confidence);
721720
}
721+
722+
@Test
723+
public void TestLLMParse() throws Exception {
724+
Document document = getTestFileAsDocument("resume.docx");
725+
ParseOptions options = new ParseOptions();
726+
options.UseLLMParser = true;
727+
ParseResumeResponse response = Client.parseResume(new ParseRequest(document, options));
728+
729+
assertTrue(response.Info.isSuccess());
730+
assertNotNull(response.Value.ResumeData.ContactInformation.CandidateName.GivenName);
731+
assertNull(response.Value.ResumeData.Patents); // Patents is not parsed during LLM Parsing
732+
}
733+
734+
@Test
735+
public void TestFlexRequests() throws Exception {
736+
Document document = getTestFileAsDocument("resume.docx");
737+
ParseOptions options = new ParseOptions();
738+
options.FlexRequests = new ArrayList<FlexRequest>();
739+
FlexRequest prompt = new FlexRequest();
740+
prompt.Prompt = "How many years has this person spent in a leadership position?";
741+
prompt.DataType = FlexRequestDataType.Text;
742+
prompt.Identifier = "YearsLeadership";
743+
options.FlexRequests.add(prompt);
744+
ParseResumeResponse response = Client.parseResume(new ParseRequest(document, options));
745+
746+
assertTrue(response.Info.isSuccess());
747+
assertNotNull(response.Value.FlexResponse);
748+
assertTrue(response.Value.FlexResponse.isSuccess());
749+
assertNotNull(response.Value.FlexResponse.Responses);
750+
assertEquals("YearsLeadership", response.Value.FlexResponse.Responses.get(0).Identifier);
751+
assertNotNull(response.Value.FlexResponse.Responses.get(0).Reply);
752+
}
722753
}

0 commit comments

Comments
 (0)