-
Notifications
You must be signed in to change notification settings - Fork 35
Feature/natural language template selection #894
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: ai-app-init
Are you sure you want to change the base?
Changes from 5 commits
7f8c907
4e6f23a
527cae9
c0c1a4d
0db8372
d79fef3
d60d345
92fe742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| Copyright 2025 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:template-recommendation', { provider: 'debug' }) | ||
| const { defaultTemplateRecommendationApiUrl } = require('./defaults') | ||
|
|
||
| /** | ||
| * Calls the template recommendation API to get AI-based template suggestions | ||
| * | ||
| * @param {string} prompt - User's natural language description of what they want to build | ||
| * @param {string} [apiUrl] - Optional API URL (defaults to env var TEMPLATE_RECOMMENDATION_API or default URL from defaults.js) | ||
| * @returns {Promise<object>} Template recommendation from the API | ||
| * @throws {Error} If API call fails | ||
| */ | ||
| async function getAIRecommendation (prompt, apiUrl) { | ||
| const url = apiUrl || process.env.TEMPLATE_RECOMMENDATION_API || defaultTemplateRecommendationApiUrl | ||
|
|
||
| aioLogger.debug(`Calling template recommendation API: ${url}`) | ||
| aioLogger.debug(`Prompt: ${prompt}`) | ||
|
|
||
| const response = await fetch(url, { | ||
| method: 'POST', | ||
| headers: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any auth enabled for recommendation API? If not it can lead to DOS attacks very easily.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We initially wanted everyone to access the AI prompt. We will look into how to achieve the auth part.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sandeep-paliwal This would be good to discuss - I was thinking maybe we could pass the CLI token and do IMS auth on the backend. That of course would make it so we only allow the recommend flow for the logged in use cases and not noLogin. But maybe that's okay since noLogin is usually non-interactive? |
||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify({ prompt }) | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text() | ||
| aioLogger.error(`API returned status ${response.status}: ${errorText}`) | ||
| throw new Error(`API returned status ${response.status}`) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
| aioLogger.debug(`API response: ${JSON.stringify(data)}`) | ||
|
|
||
| return data.body || data | ||
| } | ||
|
|
||
| module.exports = { | ||
| getAIRecommendation | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.