-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
* Fix sonar lint * Adding more linter fix * Adding more fix * Adding sonar lint fix to gitignore * Update .gitignore * Adding example utils for example * Remove e.printStackTrace from example
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ai.knowly.langtorch.capability.local.v1; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalCapabilityReadException extends RuntimeException { | ||
public LocalCapabilityReadException(IOException e) { | ||
super(e); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ai.knowly.langtorch.capability.module.openai; | ||
|
||
public class PromptTemplateNotSetException extends RuntimeException { | ||
public PromptTemplateNotSetException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ai.knowly.langtorch.example; | ||
|
||
import ai.knowly.langtorch.capability.Capability; | ||
import com.google.common.flogger.FluentLogger; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class ExampleUtils { | ||
private ExampleUtils() {} | ||
|
||
static void readInputUntilEXIT(FluentLogger logger, Capability<String, String> capability) | ||
throws IOException { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
String input; | ||
final String sentinel = "EXIT"; // Define a sentinel value to exit the loop | ||
logger.atInfo().log("Type '%s' and press Enter to exit the application.%n", sentinel); | ||
|
||
while (true) { | ||
input = reader.readLine(); | ||
|
||
if (input == null || sentinel.equalsIgnoreCase(input)) { | ||
break; // Exit the loop if the user types the sentinel value | ||
} | ||
|
||
logger.atInfo().log("User: " + input); | ||
String assistantMsg = capability.run(input); | ||
logger.atInfo().log("Assistant: " + assistantMsg); | ||
} | ||
|
||
logger.atInfo().log("Exiting the application."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,18 @@ | ||
package ai.knowly.langtorch.example; | ||
|
||
import static ai.knowly.langtorch.example.ExampleUtils.readInputUntilEXIT; | ||
|
||
import ai.knowly.langtorch.capability.module.openai.SimpleChatCapability; | ||
import java.io.BufferedReader; | ||
import com.google.common.flogger.FluentLogger; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class SimpleChatBotWithoutExplicitKey { | ||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
// Reading the key from the environment variable under Resource folder(.env file, OPENAI_API_KEY | ||
// field) | ||
SimpleChatCapability chatBot = SimpleChatCapability.create(); | ||
readInputUntilEXIT(chatBot); | ||
} | ||
|
||
private static void readInputUntilEXIT(SimpleChatCapability chatBot) | ||
throws ExecutionException, InterruptedException { | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
String input; | ||
final String sentinel = "EXIT"; // Define a sentinel value to exit the loop | ||
System.out.printf("Type '%s' and press Enter to exit the application.\n", sentinel); | ||
|
||
while (true) { | ||
input = reader.readLine(); | ||
|
||
if (input == null || sentinel.equalsIgnoreCase(input)) { | ||
break; // Exit the loop if the user types the sentinel value | ||
} | ||
|
||
System.out.println("User: " + input); | ||
String assistantMsg = chatBot.run(input); | ||
System.out.println("Assistant: " + assistantMsg); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
System.out.println("Exiting the application."); | ||
readInputUntilEXIT(logger, chatBot); | ||
} | ||
} |