-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying the organizationId in the configuration #197
Conversation
Just an implementation note. In |
Thanks for this. I'll have to think about this, I'm not really a fan of the filter for this case. This might be an opportunity actually to improve the REST Client... |
Yeah I'd much prefer to have just the annotation as well, but I thought having to add an extra method parameter to every method, when a lot of the time the value is |
91ef38e
to
c418ab4
Compare
The thing is that I don't want to have two different approaches for the parameters if it can be avoided. I'm thinking about some improvements to the |
I thought about making the filter more generic as well, something like a Some of the other edits (like transforming annonymous class instances to lambdas) we done by IntelliJ automatically. I can turn that off and revert those changes if you'd prefer. |
Yeah, no lambdas please 🙂. But in any case, I need to look into what I mentioned above before moving this ahead |
Ok I'll revert that. Can I ask why? I feel like return builder::build; is way cleaner than return new Supplier<>() {
@Override
public Object get() {
return builder.build();
}
}; and public void cleanUp(ShutdownContext shutdown) {
shutdown.addShutdownTask(QuarkusOpenAiClient::clearCache);
} is way cleaner than public void cleanUp(ShutdownContext shutdown) {
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
QuarkusOpenAiClient.clearCache();
}
});
} |
805be07
to
3ed437d
Compare
Certainly! There is no doubt that the lambdas and method references look cleaner in this case, it's just a case of us trying to eliminate lambdas in runtime code as much as possible. |
Assuming works fine (it works just fine in whatever test I ran), this should be rebased onto it and it will become simpler |
I'll take a look at that and rebase onto this. Had somewhat of a pet medical emergency today so I might not get to it until tomorrow. |
Hopefully your pet will be fine! |
3ed437d
to
4e751eb
Compare
openai/openai-common/runtime/src/main/java/io/quarkiverse/langchain4j/openai/OpenAiRestApi.java
Outdated
Show resolved
Hide resolved
Thanks! So I started rebasing this and saw what you did with the If I add another |
A header (or whatever) will not be sent if the value is null |
Thats what I needed to know. I'll work on this new integration now. Just a thought - instead of adding a new method parameter to |
Yeah, we can certainly have a builder, but we need to be careful of how the key translates to the two headers |
I'll put something together and you can review. |
👌 |
3466d49
to
4fae868
Compare
Just pushed changes. Let me know what you think. |
1029f5a
to
73e477a
Compare
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.
I added a minor comment.
Also, it would be nice to have the commits squashed
import static org.acme.example.openai.MessageUtil.createChatCompletionRequest; | ||
import static org.acme.example.openai.MessageUtil.createCompletionRequest; | ||
import static org.acme.example.openai.MessageUtil.createEmbeddingRequest; | ||
import static org.acme.example.openai.MessageUtil.*; |
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.
I'd prefer we don't use star imports
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.
I ran mvn impsort:sort
from the project root and thats what it produced. If I commit without running that then the build fails saying I need to run it...
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.
Interesting
Fixes quarkiverse#131 # Conflicts: # openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java
eb58e52
to
2d5e148
Compare
They are. Maybe you were looking at it just as I was squashing. |
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.
Thanks a lot!
You're welcome! I like the builder approach coupled with the metadata I'll still agree to disagree that if (someOptional.isPresent()) {
someOptional.get();
} is an anti-pattern. Optional<String> apiKeyOpt = runtimeConfig.apiKey();
if (apiKeyOpt.isEmpty()) {
throw new ConfigValidationException(createApiKeyConfigProblems());
}
ChatModelConfig chatModelConfig = runtimeConfig.chatModel();
var builder = OpenAiChatModel.builder()
.apiKey(apiKeyOpt.get()); would be much better as var apiKey = runtimeConfig.apiKey()
.orElseThrow(() -> new ConfigValidationException(createApiKeyConfigProblems()));
ChatModelConfig chatModelConfig = runtimeConfig.chatModel();
var builder = OpenAiChatModel.builder()
.apiKey(apiKey); |
I don't think I said it's an antipattern. |
No, I don't think you did. I'm saying it is :) |
Not sure why the native java 21 build is failing. Its timing out when creating the binary. I've seen that happen in other apps for java 21. Takes longer to build the image. |
That's a bug in GraalVM that we need to address. Not related to this PR |
See https://platform.openai.com/docs/api-reference/organization-optional - allow the organizationId to be specified in the configuration.
Fixes #131