kopia lustrzana https://github.com/learn-awesome/learndb
Porównaj commity
8 Commity
4af057d61d
...
55e084f11b
Autor | SHA1 | Data |
---|---|---|
Skultrix | 55e084f11b | |
Skultrix | f9d89ec9e8 | |
Skultrix | 03f806eb0a | |
Skultrix | 201cfd6b99 | |
Skultrix | 01624b8745 | |
Skultrix | 3de7afb69b | |
Skultrix | b1d577101f | |
Skultrix | 7e3d8242d7 |
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"projects": {
|
||||
"default": "learbdb-cmuq"
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
# This file was auto-generated by the Firebase CLI
|
||||
# https://github.com/firebase/firebase-tools
|
||||
|
||||
name: Deploy to Firebase Hosting on merge
|
||||
'on':
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
build_and_deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: npm ci && npm run build
|
||||
- uses: FirebaseExtended/action-hosting-deploy@v0
|
||||
with:
|
||||
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
||||
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LEARBDB_CMUQ }}'
|
||||
channelId: live
|
||||
projectId: learbdb-cmuq
|
|
@ -1,17 +0,0 @@
|
|||
# This file was auto-generated by the Firebase CLI
|
||||
# https://github.com/firebase/firebase-tools
|
||||
|
||||
name: Deploy to Firebase Hosting on PR
|
||||
'on': pull_request
|
||||
jobs:
|
||||
build_and_preview:
|
||||
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: npm ci && npm run build
|
||||
- uses: FirebaseExtended/action-hosting-deploy@v0
|
||||
with:
|
||||
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
||||
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LEARBDB_CMUQ }}'
|
||||
projectId: learbdb-cmuq
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"functions": [
|
||||
{
|
||||
"source": "functions",
|
||||
"codebase": "default",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git",
|
||||
"firebase-debug.log",
|
||||
"firebase-debug.*.log"
|
||||
]
|
||||
}
|
||||
],
|
||||
"hosting": {
|
||||
"public": "public",
|
||||
"ignore": [
|
||||
"firebase.json",
|
||||
"**/.*",
|
||||
"**/node_modules/**"
|
||||
],
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "**",
|
||||
"destination": "/index.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"emulators": {
|
||||
"functions": {
|
||||
"port": 5001
|
||||
},
|
||||
"ui": {
|
||||
"enabled": true
|
||||
},
|
||||
"singleProjectMode": true
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
node_modules/
|
|
@ -1,146 +0,0 @@
|
|||
const fetch = require('node-fetch'); // Import for webscraping in fetchContentFromURL()
|
||||
import { OpenAIApi, Configuration } from 'openai';
|
||||
// const { Configuration, OpenAIApi } = require('openai');
|
||||
|
||||
// Function to fetch content from URL using a web scraping service
|
||||
async function fetchContentFromURL(url) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return await response.text();
|
||||
} catch (error) {
|
||||
console.error(`Could not fetch content from URL: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function simplifyContent(content) {
|
||||
// Denote headings with a marker (like '###') and add a line break
|
||||
content = content.replace(/<h[1-6].*?>(.*?)<\/h[1-6]>/g, '\n### $1\n');
|
||||
// Remove script and style elements and their content
|
||||
let simplifiedContent = content.replace(/<script.*?>.*?<\/script>/gms, '');
|
||||
simplifiedContent = simplifiedContent.replace(/<style.*?>.*?<\/style>/gms, '');
|
||||
// Remove all remaining HTML tags, leaving the inner text
|
||||
simplifiedContent = simplifiedContent.replace(/<[^>]+>/g, '');
|
||||
// Manually replace common HTML entities
|
||||
simplifiedContent = simplifiedContent
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'");
|
||||
// Remove inline CSS and JavaScript event handlers
|
||||
simplifiedContent = simplifiedContent.replace(/style\s*=\s*'.*?'/gi, '');
|
||||
simplifiedContent = simplifiedContent.replace(/on\w+\s*=\s*".*?"/gi, '');
|
||||
// Normalize whitespace without removing sentence punctuation
|
||||
simplifiedContent = simplifiedContent.replace(/\s+/g, ' ').trim();
|
||||
// Condense multiple line breaks into a single one
|
||||
simplifiedContent = simplifiedContent.replace(/(\r\n|\r|\n){2,}/g, '\n');
|
||||
return simplifiedContent;
|
||||
}
|
||||
|
||||
|
||||
// Placeholder function to perform GPT analysis for media type and topics using Mistral-7b via OpenRouter
|
||||
async function performGPTAnalysis(simplifiedContent, apiKey) {
|
||||
// Implement logic to send content to Mistral-7b via OpenRouter for GPT analysis
|
||||
// Send content and receive GPT analysis response
|
||||
|
||||
// this is the code that we tried to use for the GPT Analysis
|
||||
// try {
|
||||
// const configuration = new Configuration({
|
||||
// apiKey: apiKey, // Use the provided API key
|
||||
// baseURL: "https://openrouter.ai/api/v1" // Your custom API endpoint
|
||||
// });
|
||||
|
||||
// const openai = new OpenAIApi(configuration);
|
||||
|
||||
// // Using the specified prompt
|
||||
// const prompt = `Analyze the following text and provide the media type and key topics: ${simplifiedContent}`;
|
||||
|
||||
// const completion = await openai.createCompletion({
|
||||
// model: "mistralai/mistral-7b-instruct",
|
||||
// prompt: prompt,
|
||||
// max_tokens: 150 // Adjust as needed
|
||||
// });
|
||||
|
||||
// //return completion.data.choices[0].text.trim();
|
||||
// return inferredMediaType;
|
||||
// } catch (error) {
|
||||
// console.error('Error with OpenAI completion:', error);
|
||||
// throw error;
|
||||
// }
|
||||
// however, it gives the error below:
|
||||
// { "error": "Something went wrong", "details": "Configuration is not a constructor" }
|
||||
|
||||
// Placeholder code
|
||||
const inferredMediaType = ["article"];
|
||||
const extractedTopics = ["topic1", "topic2"];
|
||||
return { inferredMediaType, extractedTopics };
|
||||
}
|
||||
|
||||
// Placeholder function to map inferred values to predefined formats and topics
|
||||
function mapInferredValues(mediaType, topics) {
|
||||
// Implement logic to map inferred media type and topics to predefined formats and topics
|
||||
// Match inferred values with predefined taxonomy
|
||||
// Placeholder code
|
||||
const predefinedMediaType = "Article";
|
||||
const predefinedTopics = ["Topic 1", "Topic 2"];
|
||||
return { predefinedMediaType, predefinedTopics };
|
||||
}
|
||||
|
||||
// Placeholder function to format the response
|
||||
function formatResponse(predefinedMediaType, predefinedTopics) {
|
||||
// Implement logic to format the extracted metadata into the desired response structure
|
||||
// Construct the response object
|
||||
// Placeholder code
|
||||
const response = {
|
||||
format: predefinedMediaType,
|
||||
topics: predefinedTopics,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function handler(event) {
|
||||
try {
|
||||
// Extract URL and API Key from the request body
|
||||
const { url, apiKey } = JSON.parse(event.body);
|
||||
|
||||
// Validate if URL and API Key are present
|
||||
if (!url || !apiKey) {
|
||||
return {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify({ error: 'URL and API Key are required' }),
|
||||
};
|
||||
}
|
||||
|
||||
// Step 1: Fetch content from the URL using a web scraping service
|
||||
const fetchedContent = await fetchContentFromURL(url);
|
||||
|
||||
// Step 2: Simplify the fetched content for GPT analysis
|
||||
const simplifiedContent = simplifyContent(fetchedContent);
|
||||
|
||||
// Step 3: Perform GPT analysis for media type and topics
|
||||
const { inferredMediaType, extractedTopics } = await performGPTAnalysis(simplifiedContent, apiKey);
|
||||
|
||||
// Step 4: Map inferred values to predefined formats and topics
|
||||
const { predefinedMediaType, predefinedTopics } = mapInferredValues(inferredMediaType, extractedTopics);
|
||||
|
||||
// Step 5: Format the response
|
||||
const formattedResponse = formatResponse(predefinedMediaType, predefinedTopics);
|
||||
|
||||
// Return the formatted response
|
||||
return {
|
||||
statusCode: 200,
|
||||
// returning the output of the simplifyContent function, to test the function
|
||||
body: JSON.stringify(simplifiedContent),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error occurred:', error.message);
|
||||
return {
|
||||
statusCode: 500,
|
||||
body: JSON.stringify({ error: 'Something went wrong', details: error.message }),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"name": "functions",
|
||||
"description": "Cloud Functions for Firebase",
|
||||
"scripts": {
|
||||
"serve": "firebase emulators:start --only functions",
|
||||
"shell": "firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18"
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"firebase-admin": "^11.8.0",
|
||||
"firebase-functions": "^4.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"firebase-functions-test": "^3.1.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Invoke Netlify Function</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
form {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
text-align: left; /* Left-align form elements */
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.button-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
background-color: #3fbfff;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
margin: 0 auto; /* Center the button horizontally */
|
||||
}
|
||||
|
||||
input[type="submit"]:hover {
|
||||
background-color: #1177e4;
|
||||
}
|
||||
|
||||
#result {
|
||||
margin-top: 20px;
|
||||
padding: 10px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
white-space: nowrap; /* Prevent wrapping to the next line */
|
||||
/* overflow: hidden; Hide the overflow */
|
||||
text-align: center; /* Center-align text in result div */
|
||||
margin-left: auto; /* Move to the center horizontally */
|
||||
margin-right: auto; /* Move to the center horizontally */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Invoke Netlify Function</h1>
|
||||
<form id="invokeForm" action="https://us-central-learbdb-cmuq.cloudfunctions.net/handle" method="POST" onsubmit="invokeFunction(event)">
|
||||
<label for="url">URL:</label>
|
||||
<input type="text" id="url" name="url" value="https://example.com">
|
||||
|
||||
<label for="apiKey">API Key:</label>
|
||||
<input type="text" id="apiKey" name="apiKey" value="your-api-key">
|
||||
|
||||
<div class="button-container">
|
||||
<input type="submit" value="Invoke Function">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
async function invokeFunction(event) {
|
||||
event.preventDefault(); // Prevent the default form submission behavior
|
||||
|
||||
const url = document.getElementById("url").value;
|
||||
const apiKey = document.getElementById("apiKey").value;
|
||||
|
||||
const formData = { url, apiKey };
|
||||
|
||||
try {
|
||||
const response = await fetch("https://us-central-learbdb-cmuq.cloudfunctions.net/handle", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(formData)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Display the result in the "result" div
|
||||
document.getElementById("result").innerHTML = JSON.stringify(data, null, 2);
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Ładowanie…
Reference in New Issue