GithubHelp home page GithubHelp logo

slash-copilot / poe_unoffical_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from isxuelinme/poe_unoffical_api

0.0 0.0 0.0 48 KB

the POE of Quora golang implement

License: Apache License 2.0

Go 95.84% HTML 4.16%

poe_unoffical_api's Introduction

if you are chinese, scaning the QR image

118

Using POE Unofficial API

sse.mp4

demo CLI

demo.mp4

Import

import "github.com/isxuelinme/poe_unofficial_api/core"
go mod tidy 

Run the following code on your Chrome console

function getChatId(botName) {
    let channel = localStorage.getItem("poe-tchannel-channel")
    let paramsForGetChatId = window.__NEXT_DATA__.buildId
    let fetchUrl = "https://poe.com/_next/data/" + paramsForGetChatId + "/"+botName+".json?handle="+botName
    fetch(fetchUrl)
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not okay');
            }
            return response.text();
        })
        .then(data => {
            jsonData = JSON.parse(data)
            let output = "POE_BOT_NAME = " + botName + "\n"+ "POE_BOT_MODEL = " + jsonData.pageProps.payload.chatOfBotDisplayName.defaultBotObject.model + "\n"+ "POE_CHANNEL = " + channel + "\n" + "POE_CHAT_ID = " + jsonData.pageProps.payload.chatOfBotDisplayName.chatId
            console.log(output)
        })
        .catch(error => {
            console.error('Error fetching data:', error);
        });
}(getChatId("Sage"))

Copy the value of POE_CHANNEL and POE_CHAT_ID after running the above code. The output will look like this:

POE_BOT_NAME = Sage
POE_BOT_MODEL = capybara
POE_CHANNEL = poe-chan51-8888-hqqqqzuksgonnzdwnitj
POE_CHAT_ID = 530922

Change .env.example name to .env and change the value of your cookie

POE_COOKIE = <your cookie>
POE_BOT_NAME = <bot name>
POE_BOT_MODEL = <bot model>
POE_CHANNEL = <bot channel>
POE_CHAT_ID = <bot chat id >

if you wanna use SSE (default is CLI), ADD the following configuration to .env

RUN_MODE = SSE
BACKEND_PORT = <backend port if not set default is 8090>

if you wanna use proxy, change the value of HTTP_PROXY in .env

HTTP_PROXY = http://<host>:<port>

More details in core and example

package main
import "github.com/isxuelinme/poe_unofficial_api/core"

func main() {
    core.SetLogMode(core.LOG_ERROR)
    MutLtiUser := core.NewMutLtiUserGpt(core.GptTypePoeUnofficial)
    ask := &core.AskRequest{
        UserId:           1, //your local user id
        Question:         "hi~ bro",
        CallbackFuncName: "", //useless. Like JSONP or event name
       // when message Coming from GPT, it will call this function
        AskResponseCallBack: func(askRequest *core.AskRequest, response *core.CallbackMessageResponse) {
			fmt.Printf("\r answer: %s", message.Data.Text)
        },
    }
    //ask question
    MutLtiUser.Talk(ask)
    
    select {}
}

It's easy to use,However, you can use AskResponseCallBack to implement websocket or more protocol by yourself. learn more READ SSE IMPLEMENT

 ask := &core.AskRequest{
        UserId:           1,
        Question:         "hi~ bro",
        CallbackFuncName: "",
        AskResponseCallBack: func (askRequest *core.AskRequest, response *core.CallbackMessageResponse) {
			<your business logiical code>
        },
 }

It has implemented multi-user, but it is not friendly to business and especially noobs, just for dev/test. So you have to read the code by yourself.

If you really have difficulty deploying or are not in the discord group, you can contact WeChat wangjian19830605

I am also implementing webUI by React, if you want try it plz wait a few hours or days

SCR-20230406-bfks-2 (1)

poe_unoffical_api's People

Contributors

acceptyour avatar isxuelinme avatar xyc0123456789 avatar

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.