Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ernesttan1976 committed Jul 3, 2023
1 parent e231617 commit 9ea1320
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
27 changes: 27 additions & 0 deletions models/Log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import mongoose from "mongoose";
const { Schema } = mongoose;

if (!mongoose.models.Log) {
const logsSchema = new Schema(
{
bot: String,
history: [String],
question: String,
toolsSelect: [String],
},
{
timestamps: {
createdAt: "created_at",
updatedAt: "updated_at",
},
}
);

mongoose.model("Log", logsSchema);
}

export default mongoose.models.Log;




21 changes: 21 additions & 0 deletions pages/api/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use server"
import {connect} from "../../config/database";
import Log from "../../models/Log"

export default async function handler(req, res) {

if (req.method !== 'POST') {
res.status(405).json({ message: 'Method Not Allowed' });
return;
}

connect();

const obj = req.body;

console.info("req.body", req.body)

const log = await Log.create(obj)

res.status(200).json({message: "ok"})
}
25 changes: 25 additions & 0 deletions pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ export default function Home() {

setLoading(true);

await fetch('/api/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
bot: bot,
question: userInput,
history: history,
}),
});


const response = await ApiChat(bot, userInput, history, setMessages);

// Reset user input
Expand Down Expand Up @@ -331,6 +344,18 @@ export default function Home() {

const controller = new AbortController();

await fetch('/api/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
bot: bot,
question: userInput,
toolsSelect: toolsSelect
}),
});

try {
const response = await fetch('/api/agentchat', {
method: 'POST',
Expand Down

1 comment on commit 9ea1320

@vercel
Copy link

@vercel vercel bot commented on 9ea1320 Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mylangchain – ./

mylangchain.vercel.app
mylangchain-git-main-ernesttan.vercel.app
mylangchain-ernesttan.vercel.app

Please sign in to comment.