-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: add CometAPI integration with chat and text completion actions #18259
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
Open
TensorNull
wants to merge
6
commits into
PipedreamHQ:master
Choose a base branch
from
TensorNull:feat/cometapi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7fc589d
feat: add CometAPI integration with chat and text completion actions
TensorNull 8bedfa4
fix: improve CometAPI integration with Pipedream guidelines compliance
TensorNull 94e0a6a
feat(cometapi): implement CodeRabbitAI review suggestions
TensorNull f4c4059
Merge branch 'PipedreamHQ:master' into feat/cometapi
TensorNull 8682985
Merge branch 'master' into feat/cometapi
TensorNull ce0a603
Merge branch 'master' into feat/cometapi
TensorNull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# CometAPI Integration for Pipedream | ||
|
||
This integration provides access to CometAPI's powerful AI models through Pipedream workflows. CometAPI offers access to various LLM models including GPT, Claude, Gemini, Grok, DeepSeek, and Qwen series. | ||
|
||
## Features | ||
|
||
- **Retrieve Available Models**: Get a list of all available models from CometAPI | ||
- **Chat Completion**: Send conversational messages to AI models | ||
- **Text Completion**: Generate text completions from prompts | ||
|
||
## Authentication | ||
|
||
To use this integration, you'll need a CometAPI API key: | ||
|
||
1. Visit [CometAPI Console](https://api.cometapi.com/console/token) | ||
2. Generate your API key | ||
3. Add it to your Pipedream account in the CometAPI app configuration | ||
|
||
## Supported Models | ||
|
||
CometAPI provides access to state-of-the-art models including: | ||
|
||
### GPT Series | ||
- `gpt-5-chat-latest` | ||
- `chatgpt-4o-latest` | ||
- `gpt-5-mini` | ||
- `gpt-4o-mini` | ||
|
||
### Claude Series | ||
- `claude-opus-4-1-20250805` | ||
- `claude-sonnet-4-20250514` | ||
- `claude-3-5-haiku-latest` | ||
|
||
### Gemini Series | ||
- `gemini-2.5-pro` | ||
- `gemini-2.5-flash` | ||
- `gemini-2.0-flash` | ||
|
||
### Other Models | ||
- Grok series (`grok-4-0709`, `grok-3`) | ||
- DeepSeek series (`deepseek-v3.1`, `deepseek-chat`) | ||
- Qwen series (`qwen3-30b-a3b`) | ||
|
||
## Usage Examples | ||
|
||
### Chat Completion | ||
```javascript | ||
// Example messages array for chat completion | ||
[ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What is the capital of France?" | ||
} | ||
] | ||
``` | ||
|
||
### Text Completion | ||
```javascript | ||
// Simple prompt for text completion | ||
"Once upon a time in a land far away" | ||
``` | ||
|
||
## Configuration Options | ||
|
||
### Common Parameters | ||
- **Model**: Choose from available CometAPI models | ||
- **Max Tokens**: Maximum number of tokens to generate (default: varies by model) | ||
- **Temperature**: Controls randomness (0.0 = deterministic, 2.0 = very random) | ||
- **Top P**: Nucleus sampling parameter (0.0 to 1.0) | ||
- **Top K**: Limits vocabulary to top K tokens | ||
- **Frequency Penalty**: Reduces repetition of frequent tokens | ||
- **Presence Penalty**: Encourages discussing new topics | ||
- **Seed**: For deterministic outputs | ||
|
||
### Advanced Parameters | ||
- **Stop**: Array of stop sequences | ||
- **Stream**: Enable streaming responses (default: false) | ||
- **Repetition Penalty**: Additional repetition control | ||
|
||
## Error Handling | ||
|
||
The integration includes comprehensive error handling: | ||
- Authentication errors with clear messages | ||
- API rate limit handling | ||
- Invalid parameter validation | ||
- Network timeout protection (5-minute default) | ||
|
||
## Rate Limits | ||
|
||
Please refer to [CometAPI Pricing](https://api.cometapi.com/pricing) for current rate limits and usage policies. | ||
|
||
## Support | ||
|
||
For CometAPI-specific issues: | ||
- [CometAPI Documentation](https://api.cometapi.com/doc) | ||
- [CometAPI Website](https://www.cometapi.com/) | ||
|
||
For Pipedream integration issues: | ||
- [Pipedream Community](https://pipedream.com/community) | ||
- [Pipedream Documentation](https://pipedream.com/docs) | ||
|
||
## License | ||
|
||
This integration follows Pipedream's component licensing terms. |
20 changes: 20 additions & 0 deletions
20
components/cometapi/actions/retrieve-available-models/retrieve-available-models.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import cometapi from "../../cometapi.app.mjs"; | ||
|
||
export default { | ||
key: "cometapi-retrieve-available-models", | ||
name: "Retrieve Available Models", | ||
version: "0.0.1", | ||
description: "Returns a list of all models available through the CometAPI including GPT, Claude, Gemini, Grok, DeepSeek, and Qwen series. Use this to discover available models before making completion requests. [See the documentation](https://api.cometapi.com/doc)", | ||
type: "action", | ||
props: { | ||
cometapi, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.cometapi.listModels({ | ||
$, | ||
}); | ||
|
||
$.export("$summary", `Successfully retrieved ${response.data?.length || 0} available model(s)!`); | ||
return response; | ||
}, | ||
}; |
207 changes: 207 additions & 0 deletions
207
components/cometapi/actions/send-chat-completion-request/send-chat-completion-request.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import cometapi from "../../cometapi.app.mjs"; | ||
|
||
export default { | ||
key: "cometapi-send-chat-completion-request", | ||
name: "Send Chat Completion Request", | ||
version: "0.0.1", | ||
description: "Send a chat completion request to any available CometAPI model. " + | ||
"Perfect for conversational AI, Q&A systems, and interactive applications. " + | ||
"Supports system messages, conversation history, and advanced parameters. " + | ||
"[See the documentation](https://api.cometapi.com/doc)", | ||
type: "action", | ||
props: { | ||
cometapi, | ||
model: { | ||
propDefinition: [ | ||
cometapi, | ||
"model", | ||
], | ||
}, | ||
messages: { | ||
type: "object[]", | ||
label: "Messages", | ||
description: "A list of message objects with 'role' and 'content' properties. " + | ||
"Roles can be 'system', 'user', 'assistant', or 'function'. " + | ||
"Example: {\"role\":\"user\",\"content\":\"Hello, how are you?\"}. " + | ||
"[See docs](https://api.cometapi.com/doc).", | ||
}, | ||
maxTokens: { | ||
propDefinition: [ | ||
cometapi, | ||
"maxTokens", | ||
], | ||
}, | ||
temperature: { | ||
propDefinition: [ | ||
cometapi, | ||
"temperature", | ||
], | ||
}, | ||
topP: { | ||
propDefinition: [ | ||
cometapi, | ||
"topP", | ||
], | ||
}, | ||
topK: { | ||
propDefinition: [ | ||
cometapi, | ||
"topK", | ||
], | ||
}, | ||
frequencyPenalty: { | ||
propDefinition: [ | ||
cometapi, | ||
"frequencyPenalty", | ||
], | ||
}, | ||
presencePenalty: { | ||
propDefinition: [ | ||
cometapi, | ||
"presencePenalty", | ||
], | ||
}, | ||
repetitionPenalty: { | ||
propDefinition: [ | ||
cometapi, | ||
"repetitionPenalty", | ||
], | ||
}, | ||
seed: { | ||
propDefinition: [ | ||
cometapi, | ||
"seed", | ||
], | ||
}, | ||
stop: { | ||
propDefinition: [ | ||
cometapi, | ||
"stop", | ||
], | ||
}, | ||
stream: { | ||
propDefinition: [ | ||
cometapi, | ||
"stream", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
// Validate model is provided | ||
if (!this.model) { | ||
throw new ConfigurationError("Model is required"); | ||
} | ||
|
||
// Validate and parse messages | ||
const messages = parseObject(this.messages); | ||
|
||
if (!Array.isArray(messages) || messages.length === 0) { | ||
throw new ConfigurationError("Messages must be a non-empty array"); | ||
} | ||
|
||
// Validate message format | ||
for (const [ | ||
index, | ||
message, | ||
] of messages.entries()) { | ||
if (!message.role || !message.content) { | ||
throw new ConfigurationError( | ||
`Message at index ${index} must have both 'role' and 'content' properties`, | ||
); | ||
} | ||
|
||
if (![ | ||
"system", | ||
"user", | ||
"assistant", | ||
"function", | ||
].includes(message.role)) { | ||
throw new ConfigurationError( | ||
`Message at index ${index} has invalid role '${message.role}'. ` + | ||
"Must be 'system', 'user', 'assistant', or 'function'", | ||
); | ||
} | ||
|
||
if (typeof message.content !== "string" || message.content.trim() === "") { | ||
throw new ConfigurationError( | ||
`Message at index ${index} must have non-empty string content`, | ||
); | ||
} | ||
} | ||
|
||
// Normalize and validate numeric parameters | ||
const toNum = (v) => (v === undefined || v === null || v === "" | ||
? undefined | ||
: Number(v)); | ||
const temperature = toNum(this.temperature); | ||
const topP = toNum(this.topP); | ||
const topK = toNum(this.topK); | ||
const frequencyPenalty = toNum(this.frequencyPenalty); | ||
const presencePenalty = toNum(this.presencePenalty); | ||
const repetitionPenalty = toNum(this.repetitionPenalty); | ||
const maxTokens = toNum(this.maxTokens); | ||
const seed = toNum(this.seed); | ||
|
||
// Validate numeric parameters | ||
if (temperature !== undefined && | ||
(!Number.isFinite(temperature) || temperature < 0 || temperature > 2)) { | ||
throw new ConfigurationError("Temperature must be a number between 0.0 and 2.0"); | ||
} | ||
if (topP !== undefined && | ||
(!Number.isFinite(topP) || topP < 0 || topP > 1)) { | ||
throw new ConfigurationError("Top P must be a number between 0.0 and 1.0"); | ||
} | ||
if (frequencyPenalty !== undefined && | ||
(!Number.isFinite(frequencyPenalty) || frequencyPenalty < -2 || frequencyPenalty > 2)) { | ||
throw new ConfigurationError( | ||
"Frequency Penalty must be a number between -2.0 and 2.0", | ||
); | ||
} | ||
if (presencePenalty !== undefined && | ||
(!Number.isFinite(presencePenalty) || presencePenalty < -2 || presencePenalty > 2)) { | ||
throw new ConfigurationError( | ||
"Presence Penalty must be a number between -2.0 and 2.0", | ||
); | ||
} | ||
if (topK !== undefined && | ||
(!Number.isFinite(topK) || topK < 0)) { | ||
throw new ConfigurationError("Top K must be a non-negative number"); | ||
} | ||
if (maxTokens !== undefined && | ||
(!Number.isFinite(maxTokens) || maxTokens <= 0)) { | ||
throw new ConfigurationError("Max Tokens must be a positive number"); | ||
} | ||
TensorNull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const data = { | ||
model: this.model, | ||
messages, | ||
stream: this.stream || false, | ||
max_tokens: maxTokens, | ||
temperature, | ||
top_p: topP, | ||
top_k: topK, | ||
frequency_penalty: frequencyPenalty, | ||
presence_penalty: presencePenalty, | ||
repetition_penalty: repetitionPenalty, | ||
seed, | ||
stop: this.stop, | ||
}; | ||
|
||
// Remove undefined values | ||
Object.keys(data).forEach((key) => { | ||
if (data[key] === undefined) { | ||
delete data[key]; | ||
} | ||
}); | ||
|
||
const response = await this.cometapi.sendChatCompletionRequest({ | ||
$, | ||
data, | ||
}); | ||
|
||
$.export("$summary", `Successfully sent chat completion request using model ${this.model}`); | ||
return response; | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.