Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions core/src/main/java/com/google/adk/models/OllamaBaseLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ public Flowable<LlmResponse> generateContent(LlmRequest llmRequest, boolean stre

// Skip this tool if there is no function declaration
if (!declarationOptional.isPresent()) {
// Log a warning or handle appropriately
System.err.println(
"Skipping tool '" + baseTool.name() + "' with missing declaration.");
// continue; // If inside a loop
logger.warn("Skipping tool '{}' with missing declaration.", baseTool.name());
return; // If processing a single tool outside a loop
}

Expand Down Expand Up @@ -388,8 +385,7 @@ public Flowable<LlmResponse> generateContentStream(LlmRequest llmRequest) {
BaseTool baseTool = tooldetail.getValue();
Optional<FunctionDeclaration> declarationOptional = baseTool.declaration();
if (!declarationOptional.isPresent()) {
System.err.println(
"Skipping tool '" + baseTool.name() + "' with missing declaration.");
logger.warn("Skipping tool '{}' with missing declaration.", baseTool.name());
return;
}
FunctionDeclaration functionDeclaration = declarationOptional.get();
Expand Down Expand Up @@ -697,7 +693,7 @@ public BufferedReader callLLMChatStream(String model, JSONArray messages, JSONAr
}

int responseCode = connection.getResponseCode();
System.out.println("Response Code from Ollama for model " + model + ": " + responseCode);
logger.debug("Response Code from Ollama for model {}: {}", model, responseCode);

if (responseCode >= 200 && responseCode < 300) {
return new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
Expand All @@ -710,7 +706,7 @@ public BufferedReader callLLMChatStream(String model, JSONArray messages, JSONAr
while ((errorLine = errorReader.readLine()) != null) {
errorResponse.append(errorLine);
}
System.err.println("Error Response Body: " + errorResponse.toString());
logger.error("Error Response Body: {}", errorResponse.toString());
} catch (IOException errorEx) {
logger.error("Error reading error stream", errorEx);
}
Expand Down Expand Up @@ -890,7 +886,7 @@ public JSONObject callLLMChat(

// Read response
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
logger.debug("Response Code: {}", responseCode);

// Read response body using UTF-8
try (InputStream inputStream = connection.getInputStream();
Expand All @@ -901,7 +897,7 @@ public JSONObject callLLMChat(
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println("Response Body: " + response.toString());
logger.debug("Response Body: {}", response.toString());

responseJ = new JSONObject(response.toString());

Expand All @@ -917,7 +913,7 @@ public JSONObject callLLMChat(
while ((errorLine = errorReader.readLine()) != null) {
errorResponse.append(errorLine);
}
System.err.println("Error Response Body: " + errorResponse.toString());
logger.error("Error Response Body: {}", errorResponse.toString());
// You might want to parse the errorResponse as a JSON object too if the API returns
// JSON errors
} catch (IOException errorEx) {
Expand Down Expand Up @@ -988,7 +984,7 @@ public static JSONObject callLLMChat(

// Open connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.print("HTTP Connection to Ollama API: " + apiUrl.toString());
logger.debug("HTTP Connection to Ollama API: {}", apiUrl);
// Set request method
connection.setRequestMethod("POST");

Expand All @@ -1007,7 +1003,7 @@ public static JSONObject callLLMChat(

// Read response
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
logger.debug("Response Code: {}", responseCode);

// Read response body
try (BufferedReader reader =
Expand All @@ -1032,10 +1028,7 @@ public static JSONObject callLLMChat(
streamOutput.append(responseText);

// Display the parsed data
System.out.println("Model: " + model);
System.out.println("Response Text: " + responseText);
System.out.println("Done: " + done);
System.out.println("----------");
logger.debug("Model: {}, Response Text: {}, Done: {}", model, responseText, done);

// Break if response is marked as done
if (done) {
Expand All @@ -1056,7 +1049,7 @@ public static JSONObject callLLMChat(
response.append(line);
}
String responseBody = response.toString();
System.out.println("Response Body: " + responseBody);
logger.debug("Response Body: {}", responseBody);

responseJ = new JSONObject(responseBody);
}
Expand Down
Loading