-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-22661: Add a native OpenAI component #19820
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
base: main
Are you sure you want to change the base?
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🤖 CI automation will test this PR automatically. 🐫 Apache Camel Committers, please review the following items:
|
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.
That looks pretty nice!!!
...ts/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
Show resolved
Hide resolved
...ts/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
Outdated
Show resolved
Hide resolved
|
|
||
| protected String resolveApiKey() { | ||
| // Priority: URI parameter > component config > environment variable > application.properties | ||
| if (configuration.getApiKey() != null && !configuration.getApiKey().isEmpty()) { |
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.
You can use org.apache.camel.util.ObjectHelper.isNotEmpty() here for consistency
|
|
||
| Currently, only the `chat-completion` operation is supported. | ||
|
|
||
| == Component Options |
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.
These should be generated, like the partials in https://github.com/apache/camel/blob/main/components/camel-ai/camel-langchain4j-agent/src/main/docs/langchain4j-agent-component.adoc#uri-format
a7d1403 to
ddee3aa
Compare
components/camel-ai/camel-openai/src/main/docs/openai-component.adoc
Outdated
Show resolved
Hide resolved
ddee3aa to
9f9ca24
Compare
9f9ca24 to
4cb1bfd
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.
Looks really promising. The model uriParam cannot be an enum, because we're going to have it exploded soon, but I think we should have some mechanism determing what models is better to use for the context.
16b9bb5 to
caf2a74
Compare
|
It's now possible to set the openai component like this: - route:
id: route-1145
from:
id: from-1972
uri: timer
parameters:
repeatCount: 1
timerName: timer
steps:
- to:
id: to-1908
uri: openai:chat-completion
parameters:
userMessage: What's the weather in Brno?
tools: resource:classpath:assets/tools.json
- log: "Response: ${body}"
tools.json is standard representation of tools in openai api: The response in this case (requiring a tool call) is list of ChatCompletionMessageToolCall objects from OpenAI SDK |
514e587 to
54d30dc
Compare
54d30dc to
0cfcd81
Compare
|
This PR is a little bit big, so maybe tidy up last comments and get this merged. Then more work can be done in new PRs that are easier to review. Also a SB -starter is needed which should be fairly easy to do with the script file to create A quarkus extension then create a ticket in their system as this needs to be done manually |
0cfcd81 to
6116406
Compare
Description
The OpenAI component provides integration with OpenAI and OpenAI-compatible APIs for chat completion using the official openai-java SDK. The component also supports streaming, structured outputs (POJO/JSON schema), per-Exchange conversation memory, and image/text file + user prompts.
Openai-java sdk https://github.com/openai/openai-java
The camel-openai component is meant for simple LLM invocations and unlike Langchain4j it doesn't require any custom java code or additional dependencies (providers, chatmodels, ..).
Here are few examples how the component can be used:
Target
mainbranch)Tracking
https://issues.apache.org/jira/browse/CAMEL-22661
Apache Camel coding standards and style
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.