-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4608 from wix/feat/migrate-to-new-serverless
chore(migration): migrate to a new Copilot prompt-handler service.
- Loading branch information
Showing
14 changed files
with
396 additions
and
377 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,58 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs').promises; | ||
|
||
class PromptHandler { | ||
async uploadImage(imagePath) { | ||
const image = await fs.readFile(imagePath); | ||
|
||
try { | ||
const response = await axios.post('https://bo.wix.com/mobile-infra-ai-services/v1/image-upload', { | ||
image, | ||
}); | ||
|
||
const imageUrl = response.data.url; | ||
if (!imageUrl) { | ||
throw new Error('Cannot find uploaded URL, got response:', response.data); | ||
} | ||
|
||
return imageUrl; | ||
} catch (error) { | ||
console.error('Error while uploading image:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async runPrompt(prompt, image) { | ||
if (!image) { | ||
throw new Error('Image is required'); | ||
} | ||
|
||
const imageUrl = await this.uploadImage(image); | ||
|
||
try { | ||
const response = await axios.post('https://bo.wix.com/mobile-infra-ai-services/v1/prompt', { | ||
prompt, | ||
model: 'SONNET_3_5', | ||
ownershipTag: 'Detox OSS', | ||
project: 'Detox OSS', | ||
images: [imageUrl] | ||
}); | ||
|
||
const generatedText = response.data.generatedTexts[0]; | ||
if (!generatedText) { | ||
throw new Error('Failed to generate text, got response:', response.data); | ||
} | ||
|
||
return generatedText; | ||
} catch (error) { | ||
console.error('Error running prompt:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
isSnapshotImageSupported() { | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = PromptHandler; |
This file contains 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
This file contains 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
This file contains 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