bramses / chatgpt-md

A (nearly) seamless integration of ChatGPT into Obsidian.
MIT License
854 stars 64 forks source link

There is limit of response texts when querying the code generation #9

Closed tkt028 closed 1 year ago

tkt028 commented 1 year ago

ISSUE: Below response text is uncompleted. There is limit of response text.

role::user
I want to write 3 websocket routes with authorization based on Redis as data store and passportJS with cookie.

<hr class="__chatgpt_plugin">

role::assistant

Sure, here's an example of how you can write 3 WebSocket routes with authorization based on Redis as data store and Passport.js with cookie:

const WebSocket = require('ws');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const redis = require("redis");
const client = redis.createClient();
const { Server } = require('@overnightjs/websocket');

// Define an object to store authorized users and their allowed topics
// Each key represents a topic, and the value is an array of authorized user IDs for that topic
const authorizedUsersByTopic = {
  'topic1': ['user1', 'user2'],
  'topic2': ['user2', 'user3'],
  'topic3': ['user1']
};

class TopicController {

  static async onConnect(socket) {
    // When a user connects, prompt them to enter their username
    socket.send(JSON.stringify({ type: 'prompt_username' }));
  }

  static async onMessage(socket, message) {
    const { type, payload } = JSON.parse(message);

    if (type === 'authenticate') {
      const { username, password } = payload;

      // Use Passport.js to authenticate the user's credentials
      passport.authenticate('local', function(err, user) {
        if (err || !user) return socket.send(JSON.stringify({ type: 'authentication_failed' }));

        // Once authenticated, add the user's information to the

<hr class="__chatgpt_plugin">

role::user
bramses commented 1 year ago

Hi @tkt028,

Just addressed this type of question in the FAQ: https://github.com/bramses/chatgpt-md#q-the-chat-seems-to-be-getting-cut-off-halfway-through. Try it out and let me know how it goes (keep in mind the tax will get cut off by the OpenAI API at 4096 tokens (~ 16000 characters: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)