-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Done some Refactoring, like extract method, extract class, decomposing conditional etc. #489
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with some nits.
Thanks.
// Constants for token counts per message and name | ||
final int TOKENS_PER_MESSAGE_GPT_3_5_TURBO = 4; | ||
final int TOKENS_PER_MESSAGE_GPT_4 = 3; | ||
final int TOKENS_PER_NAME = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final members for utils class, should be static.
Reason: It provides better performance, values are inlined at compile time instead of a runtime value lookup.
@@ -82,7 +82,7 @@ void createRetrieveRun() throws JsonProcessingException { | |||
|
|||
|
|||
AssistantRequest assistantRequest = AssistantRequest.builder() | |||
.model(TikTokensUtil.ModelEnum.GPT_4_1106_preview.getName()) | |||
.model(TikTokensUtil.ModelEnum.GPT_3_5_TURBO.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any good reason, why the model type changed?
Thanks.
Map<JsonToken, JsonNodeHandler> handlers = new HashMap<>(); | ||
handlers.put(JsonToken.VALUE_NULL, new MissingNodeHandler()); | ||
// Add more handlers for different token types if needed | ||
return handlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Returning collections such as Map - from functions, should preserve their immutability.
Thing about collections.unmodifiableMap
https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#unmodifiableMap-java.util.Map-
); | ||
throw new OpenAiHttpException(error, e, e.code()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It can be optimized
try {
ResponseBody errorBody = response.errorBody();
if (errorBody != null) {
OpenAiError error = mapper.readValue(errorBody.string(), OpenAiError.class);
throw new OpenAiHttpException(error, new HttpException(response), response.code());
}
} catch (IOException ex) {
throw new HttpException(response);
}
Thanks for submitting a pull request! Please check CONTRIBUTING.md for style guidelines.
Changes
Describe your changes here
New API Checklist
See CONTRIBUTING.md for more info.