1234567891011121314151617181920212223242526272829303132333435 |
- const { r2rClient } = require("r2r-js");
- const client = new r2rClient("http://localhost:8000");
- module.exports = async function handler(req, res) {
- console.log("Received a request at /api/login");
- if (req.method === "POST") {
- const { query } = req.body;
- try {
- // Login with each request. In a production app, you'd want to manage sessions.
- await client.login("admin@example.com", "change_me_immediately");
- const response = await client.rag({
- query: query,
- rag_generation_config: {
- model: "gpt-4o",
- temperature: 0.0,
- stream: false,
- },
- });
- res.status(200).json({
- result: response.results.completion.choices[0].message.content,
- });
- } catch (error) {
- res.status(500).json({
- error: error instanceof Error ? error.message : "An error occurred",
- });
- }
- } else {
- res.setHeader("Allow", ["POST"]);
- res.status(405).end(`Method ${req.method} Not Allowed`);
- }
- };
|