mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-23 06:58:12 +02:00
Add ability to configure and select AI models for text generation
Implement OpenRouter API integration for AI-powered text generation, allowing users to configure API keys, select models, and define system prompts for customized content creation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/HPCBgsr
This commit is contained in:
1 parent
d63f776af0
commit
68ed90b0c9
6 files changed
+219
-39
No files matched your search
+49
-2
@@ -4,7 +4,7 @@ import { storage } from "./storage";
|
||||
import multer from "multer";
|
||||
import { openRouterService } from "./services/openrouter";
|
||||
import { cloudinaryService } from "./services/cloudinary";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema } from "@shared/schema";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema, insertOpenrouterConfigSchema } from "@shared/schema";
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
const productInfo = req.body;
|
||||
const userId = "demo-user"; // In real app, get from session/auth
|
||||
|
||||
const generatedTexts = await openRouterService.generatePostText(productInfo);
|
||||
const generatedTexts = await openRouterService.generatePostText(productInfo, userId);
|
||||
|
||||
// Save to database
|
||||
await storage.createAiGeneration({
|
||||
@@ -283,6 +283,53 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// OpenRouter configuration
|
||||
app.get("/api/openrouter/config", async (req, res) => {
|
||||
try {
|
||||
const userId = "demo-user"; // In real app, get from session/auth
|
||||
const config = await storage.getOpenrouterConfig(userId);
|
||||
|
||||
if (!config) {
|
||||
return res.json(null);
|
||||
}
|
||||
|
||||
// Don't send the API key to the client
|
||||
const { apiKey, ...safeConfig } = config;
|
||||
res.json(safeConfig);
|
||||
} catch (error) {
|
||||
console.error("Error fetching OpenRouter config:", error);
|
||||
res.status(500).json({ error: "Failed to fetch OpenRouter config" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/openrouter/config", async (req, res) => {
|
||||
try {
|
||||
const userId = "demo-user"; // In real app, get from session/auth
|
||||
|
||||
const configData = insertOpenrouterConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Check if config already exists
|
||||
const existingConfig = await storage.getOpenrouterConfig(userId);
|
||||
|
||||
let config;
|
||||
if (existingConfig) {
|
||||
config = await storage.updateOpenrouterConfig(userId, configData);
|
||||
} else {
|
||||
config = await storage.createOpenrouterConfig(configData);
|
||||
}
|
||||
|
||||
// Don't send the API key back
|
||||
const { apiKey, ...safeConfig } = config;
|
||||
res.json(safeConfig);
|
||||
} catch (error) {
|
||||
console.error("Error saving OpenRouter config:", error);
|
||||
res.status(500).json({ error: "Failed to save OpenRouter config" });
|
||||
}
|
||||
});
|
||||
|
||||
const httpServer = createServer(app);
|
||||
|
||||
return httpServer;
|
||||
|
||||
Reference in new issue
Block a user