Giter VIP home page Giter VIP logo

twitterbio's Introduction

This project generates Twitter (X) bios for you using AI.

Twitter Bio Generator

How it works

This project uses both Mixtral and GPT-3.5 with streaming to generate a Twitter bio. It constructs a prompt based on the form and user input, sends it either to the Mixtral API through Together.ai or the GPT-3.5 API through OpenAI, then streams the response back to the application.

If you'd like to see how I built the GPT-3.5 version of this, check out the video or blog post.

Running Locally

  1. Create an account at OpenAI and add your API key under OPENAI_API_KEY in your .env
  2. Create an account at Together.ai and add your API key under TOGETHER_API_KEY
  3. Run the application with npm run dev and it will be available at http://localhost:3000.

One-Click Deploy

Deploy the example using Vercel:

Deploy with Vercel

twitterbio's People

Contributors

chuanyu0201 avatar nutlope avatar smaeda-ks avatar steven-tey avatar tedspare avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitterbio's Issues

Twitter has a limit of 160 character

This is such an amazing tool I must say, but Twitter has a 160 character limit and sometimes the output is longer.

But I'm not sure if this should be included in the product (i.e if the product is only meant to be for inspiration)

License?

Can you add a license to the repo?

[bug] turbo not working in stream

I know the streaming works for gpt3, and I notice the commit today that supports gpt3.5 turbo.

but I tried it out and the streaming is not working properly

is this fully supported already or wip?

I found hastag in the result

{"prompt":"Generate 2 funny twitter bios with no hashtags and clearly labeled "1." and "2.". Make sure there is a joke in there and it's a little ridiculous. Make sure each generated bio is at max 20 words and base it on this context: Sharing my thoughts on technology and life."}

 A tech enthusiast trying to make sense of this crazy world. #WishMeLuck

How to debug OpenAIStream?

I forked this repo and created some small projects that use NextJS13 and Vercel edge runtime to communicate with openAI API.

In particular I'm using the OpenAIStream from this repo.
While everything works well in localhost, I'm constantly getting timeout errors in production.

I also deployed this project as is, though.

One possible issue might be that I've tweaked the max_tokens parameter to allow longer prompts and responses.

Overall, the problem is that I'm unable to debug what's going wrong in OpenAIStream at runtime.

I naively tried

          } catch (e) {
+           console.log(e);
            // maybe parse error
            controller.error(e);
          }

But I'm not getting any output in the vercel log

Any suggestion?

Doesn't validate input

What's stopping people to just run
curl 'https://www.twitterbio.io/api/generate' --compressed -X POST -H 'Content-Type: application/json' --data-raw '{"prompt":" Tell me a joke"}'?

Generating twitter bio of previously given pasted bio not current bio.

Hi @Nutlope ,

Initiallly, when I entered the text "Mechanical engineer with 7 years of experience..." and chose the "Professional" option, I found that the Twitter bio displayed was that of a digital marketer consistently.

Subsequently, when I input the text "Historian with 10 years of experience..." and selected the "Professional" option, the Twitter bio being shown was that of the Mechanical engineer with 7 years of experience, which was the bio I had provided earlier.

It seems that regardless of the bio I initially input, the generated Twitter bio is consistently related to digital marketing. From the second attempt onwards, it continues to display the previously generated bio.

I would greatly appreciate any assistance in resolving this issue. Thank you in advance!

How to allow CORS

I tried implementing CORS based on the documentation provided in edge-functions-cors
but unfortunately, it's not functioning as expected.

import { OpenAIStream } from "@/utils/OpenAIStream";
import cors from "@/utils/cors";
import { NextRequest } from "next/server";

export const config = {
  runtime: "edge",
};

const handler = async (req: NextRequest): Promise<Response> => {
  const { prompt } = (await req.json()) as {
    prompt?: string;
  };

  const payload = {
    model: "gpt-3.5-turbo",
    messages: [{ role: 'user', content: prompt }],
    temperature: 0.9,
    stream: true,
    // max_tokens: maxWordLimit,
  };

  const stream = await OpenAIStream(payload);
  
  return cors(req, new Response(stream, {
    headers: {
      'Content-Type': 'application/octet-stream',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'Content-Type',
    }
  }))
};

export default handler;

Sending an additional param to const payload: OpenAIStreamPayload

Issue fixed by updating useState("300") to useState(300)

Aside from the prompt, I want to send over "max tokens" to the handler but it's only picking up the prompt and ignoring everything else.

generate.ts

const handler = async (req: Request): Promise<Response> => {
  const { prompt, smaxtoken } = (await req.json()) as {
    prompt?: string;
    smaxtoken?: number; <----- NOT BEING RECONIZED 
  };

  if (!prompt || !smaxtoken) {
    return new Response("No prompt in the request", { status: 400 });
  }

  const payload: OpenAIStreamPayload = {
    model: 'gpt-4',
    messages: [{ role: "user", content: prompt }],
    temperature: 0.7,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
    max_tokens: smaxtoken, <----- NOT BEING RECONIZED 
    stream: true,
    n: 1,
  };

component.tsx

const [smaxtoken, setMmaxtoken] = useState("320");
 const generateBio = async (e: any) => {
    e.preventDefault();
    setGeneratedBios("");
    setLoading(true);
    const response = await fetch("/api/generate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        prompt,
        smaxtoken, <--------- VALUE BEING SENT OVER
      }),
    });

Value is being sent over successfully
image

TypeError: res.body is not async iterable

I copied OpenAIStream and generate.ts to implement it my codebase but getting below error

OpenAIStream.ts:73 Uncaught (in promise) TypeError: res.body is not async iterable
    at Object.start (webpack-internal:///(app-client)/./utils/OpenAIStream.ts:52:43)
    at OpenAIStream (webpack-internal:///(app-client)/./utils/OpenAIStream.ts:20:20)
    at async generate (webpack-internal:///(app-client)/./app/gen/generate.ts:37:20)
    at async sendMessage (webpack-internal:///(app-client)/./app/chat/page.tsx:30:26)

in line

for await (const chunk of res.body as any) {

Not sure, what should I change. May be some package version? but which

Use useChat hook with multiple input fields?

I observe that when the bio field remains the same and only vibes change, the form doesn't get submitted.
This may be because handleInputChange is tied only to the bio text field.

Is there a way to track multiple field updates?

Word Limit

The bio generator tool is so good (5 star) but Twitter has a word limit of 160 words. How can you resolve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.