-
Notifications
You must be signed in to change notification settings - Fork 852
Integrates You.com chatbot in web-mode using session cookie. Supports conversation history + "create" chatMode (image generation). #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6497f76
837499f
25317c5
5e460e4
cfaba62
2a5c650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||||||||
| // path/to/services/apis/you-web.mjs | ||||||||||||
|
|
||||||||||||
| import { pushRecord, setAbortController } from '../../services/apis/shared.mjs' | ||||||||||||
| import { fetchSSE } from '../../utils/fetch-sse.mjs' | ||||||||||||
| import { getUserConfig, youWebModelKeys } from '../../config/index.mjs' | ||||||||||||
| import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs' | ||||||||||||
| import { getModelValue, isUsingModelName } from '../../utils/model-name-convert.mjs' | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @param {Runtime.Port} port | ||||||||||||
| * @param {string} question | ||||||||||||
| * @param {Session} session | ||||||||||||
| * @param {string} sessionCookie | ||||||||||||
| */ | ||||||||||||
| export async function generateAnswersWithYouWebApi(port, question, session, sessionCookie) { | ||||||||||||
| const { controller, cleanController } = setAbortController(port) | ||||||||||||
| const config = await getUserConfig() | ||||||||||||
| const model = getModelValue(session) | ||||||||||||
|
|
||||||||||||
| const apiUrl = 'https://you.com/api/streamingSearch' | ||||||||||||
|
|
||||||||||||
| // Use the existing chatId from the session or generate a new one | ||||||||||||
| if (!session.chatId) { | ||||||||||||
| session.chatId = generateUUID() // You need a function to generate UUIDs | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Always include the conversation history | ||||||||||||
| const conversationContext = getConversationPairs(session.conversationRecords, false) | ||||||||||||
|
|
||||||||||||
| const traceId = `${session.chatId}|${session.messageId}|${new Date().toISOString()}` | ||||||||||||
|
|
||||||||||||
| const params = new URLSearchParams() | ||||||||||||
| params.append('page', '1') | ||||||||||||
| params.append('count', '10') | ||||||||||||
| params.append('safeSearch', 'Off') | ||||||||||||
| params.append('q', question) | ||||||||||||
| params.append('chatId', session.chatId) // Use the existing or new chatId | ||||||||||||
| params.append('traceId', traceId) | ||||||||||||
| params.append('conversationTurnId', session.messageId) | ||||||||||||
| params.append('selectedAiModel', model) | ||||||||||||
|
|
||||||||||||
| // Conditional chatMode based on modelName | ||||||||||||
| let chatMode = 'custom' | ||||||||||||
| if (isUsingModelName('create', session)) { | ||||||||||||
| chatMode = 'create' | ||||||||||||
| } | ||||||||||||
| params.append('selectedChatMode', chatMode) | ||||||||||||
|
|
||||||||||||
| params.append('pastChatLength', session.conversationRecords.length.toString()) | ||||||||||||
| params.append('queryTraceId', traceId) | ||||||||||||
| params.append('use_personalization_extraction', 'false') | ||||||||||||
| params.append('domain', 'youchat') | ||||||||||||
| params.append('mkt', 'en-US') | ||||||||||||
| params.append('chat', JSON.stringify(conversationContext)) | ||||||||||||
|
|
||||||||||||
| const url = `${apiUrl}?${params.toString()}` | ||||||||||||
|
|
||||||||||||
| let answer = '' | ||||||||||||
|
|
||||||||||||
| await fetchSSE(url, { | ||||||||||||
| method: 'GET', | ||||||||||||
| signal: controller.signal, | ||||||||||||
| headers: { | ||||||||||||
| 'Content-Type': 'text/event-stream;charset=utf-8', | ||||||||||||
|
||||||||||||
| 'Content-Type': 'text/event-stream;charset=utf-8', | |
| 'Accept': 'text/event-stream', |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling finishMessage() here will push the record and post a completed message, but the onEnd callback also calls finishMessage(), leading to duplicate pushes and messages. Consider invoking it in only one place.
| finishMessage() | |
| if (!isFinished) { | |
| finishMessage() | |
| isFinished = true | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate
createkey in theModelsobject (also defined at line 251). Please remove or consolidate one of the definitions to avoid key collisions.