Skip to content

Commit be486f4

Browse files
committed
feat: add poe AI (Sage, GPT4, ClaudePlus, Claude, ChatGPT, Dragonfly)
1 parent f89e9c9 commit be486f4

40 files changed

+691
-7
lines changed

build.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
184184
test: /\.(jpg|png|svg)$/,
185185
type: 'asset/inline',
186186
},
187+
{
188+
test: /\.(graphql|gql)$/,
189+
loader: 'graphql-tag/loader',
190+
},
187191
isWithoutTiktoken
188192
? {
189193
test: /crop-text\.mjs$/,

package-lock.json

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
"@picocss/pico": "^1.5.7",
2424
"@primer/octicons-react": "^18.2.0",
2525
"countries-list": "^2.6.1",
26+
"diff": "^5.1.0",
2627
"eventsource-parser": "^0.1.0",
2728
"file-saver": "^2.0.5",
2829
"github-markdown-css": "^5.2.0",
2930
"gpt-3-encoder": "^1.1.4",
3031
"i18next": "^22.4.13",
3132
"katex": "^0.16.4",
3233
"lodash-es": "^4.17.21",
34+
"md5": "^2.3.0",
3335
"parse5": "^6.0.1",
3436
"preact": "^10.13.1",
3537
"prop-types": "^15.8.1",
@@ -64,6 +66,7 @@
6466
"eslint": "^8.36.0",
6567
"eslint-plugin-react": "^7.32.2",
6668
"fs-extra": "^11.1.0",
69+
"graphql-tag": "^2.12.6",
6770
"jsdom": "^21.1.1",
6871
"less-loader": "^11.1.0",
6972
"mini-css-extract-plugin": "^2.7.5",

src/background/apis/bing-web.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BingAIClient from '../clients/BingAIClient'
1+
import BingAIClient from '../clients/bing'
22
import { getUserConfig } from '../../config/index.mjs'
33
import { pushRecord, setAbortController } from './shared.mjs'
44

src/background/apis/poe-web.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { pushRecord, setAbortController } from './shared.mjs'
2+
import PoeAiClient from '../clients/poe'
3+
4+
/**
5+
* @param {Runtime.Port} port
6+
* @param {string} question
7+
* @param {Session} session
8+
* @param {string} modelName
9+
*/
10+
export async function generateAnswersWithPoeWebApi(port, question, session, modelName) {
11+
const bot = new PoeAiClient(session.poe_chatId)
12+
const { messageListener } = setAbortController(port, () => {
13+
bot.breakMsg()
14+
bot.close()
15+
})
16+
17+
let answer = ''
18+
await bot
19+
.ask(
20+
question,
21+
modelName,
22+
(msg) => {
23+
answer += msg
24+
port.postMessage({ answer: answer, done: false, session: null })
25+
},
26+
() => {
27+
if (bot.chatId) session.poe_chatId = bot.chatId
28+
29+
pushRecord(session, question, answer)
30+
console.debug('conversation history', { content: session.conversationRecords })
31+
port.onMessage.removeListener(messageListener)
32+
port.postMessage({ answer: answer, done: true, session: session })
33+
bot.close()
34+
},
35+
)
36+
.catch((err) => {
37+
port.onMessage.removeListener(messageListener)
38+
bot.close()
39+
throw err
40+
})
41+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
mutation AddHumanMessageMutation(
2+
$chatId: BigInt!
3+
$bot: String!
4+
$query: String!
5+
$source: MessageSource
6+
$withChatBreak: Boolean! = false
7+
) {
8+
messageCreateWithStatus(
9+
chatId: $chatId
10+
bot: $bot
11+
query: $query
12+
source: $source
13+
withChatBreak: $withChatBreak
14+
) {
15+
message {
16+
id
17+
__typename
18+
messageId
19+
text
20+
linkifiedText
21+
authorNickname
22+
state
23+
vote
24+
voteReason
25+
creationTime
26+
suggestedReplies
27+
chat {
28+
id
29+
shouldShowDisclaimer
30+
}
31+
}
32+
messageLimit{
33+
canSend
34+
numMessagesRemaining
35+
resetTime
36+
shouldShowReminder
37+
}
38+
chatBreak {
39+
id
40+
__typename
41+
messageId
42+
text
43+
linkifiedText
44+
authorNickname
45+
state
46+
vote
47+
voteReason
48+
creationTime
49+
suggestedReplies
50+
}
51+
}
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
mutation AddMessageBreakMutation($chatId: BigInt!) {
2+
messageBreakCreate(chatId: $chatId) {
3+
message {
4+
id
5+
__typename
6+
messageId
7+
text
8+
linkifiedText
9+
authorNickname
10+
state
11+
vote
12+
voteReason
13+
creationTime
14+
suggestedReplies
15+
}
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mutation AutoSubscriptionMutation($subscriptions: [AutoSubscriptionQuery!]!) {
2+
autoSubscribe(subscriptions: $subscriptions) {
3+
viewer {
4+
id
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fragment BioFragment on Viewer {
2+
id
3+
poeUser {
4+
id
5+
uid
6+
bio
7+
}
8+
}

0 commit comments

Comments
 (0)