-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feat: chat regenerate and proceed #26
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4895ca1
Feat: chat regenerate and proceed
Seidko bc5a45b
chore: suggested change by @MaikoTan
Seidko 770453c
fix: some code was overrided by the previous commit
Seidko 282bf5f
fix: read properties of undefined (request)
Seidko df26551
fix: extra endpoint arguments cause ENOTFOUND
Seidko 0fd3d2f
Merge branch 'fix-extra-endpoint' into feat-chat-variant-continue
Seidko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import ChatGPT from './api' | ||
import ChatGPT, { Conversation } from './api' | ||
import { Context, Logger, Schema, Session, SessionError } from 'koishi' | ||
|
||
const logger = new Logger('chatgpt') | ||
|
@@ -37,13 +37,18 @@ export const Config: Schema<Config> = Schema.intersect([ | |
}), | ||
]) | ||
|
||
const conversations = new Map<string, { messageId: string; conversationId: string }>() | ||
const conversations = new Map<string, Conversation>() | ||
|
||
export function apply(ctx: Context, config: Config) { | ||
ctx.i18n.define('zh', require('./locales/zh-CN')) | ||
|
||
const api = new ChatGPT(ctx, config) | ||
|
||
const actions: ChatGPT.Actions = { | ||
...Object.fromEntries(config.keywordContinue.map((value) => [value, 'continue'])), | ||
...Object.fromEntries(config.keywordVariant.map((value) => [value, 'variant'])) | ||
} | ||
|
||
const getContextKey = (session: Session, config: Config) => { | ||
switch (config.interaction) { | ||
case 'user': | ||
|
@@ -93,9 +98,11 @@ export function apply(ctx: Context, config: Config) { | |
|
||
try { | ||
// send a message and wait for the response | ||
const { conversationId, messageId } = conversations.get(key) ?? {} | ||
const response = await api.sendMessage({ message: input, conversationId, messageId }) | ||
conversations.set(key, { conversationId: response.conversationId, messageId: response.messageId }) | ||
let request: Conversation = conversations.get(key) | ||
let action: ChatGPT.Action = input in actions ? actions[input] : 'next' | ||
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also always use |
||
|
||
const response = await api.sendMessage({ message: input, ...request}, action) | ||
conversations.set(key, { message: request?.message, conversationId: response.conversationId, messageId: response.messageId }) | ||
return response.message | ||
} catch (error) { | ||
logger.warn(error) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not really good to use type
Conversation
here, as we don't save messages in the map.If you stick with a type, you can split them into two types, but I argue with that.
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.
What is your specific idea? My idea is to use the
Conversation
type here and save it in aMap
. I can't think of any other idea at the moment.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.
I think just to revert this type would be good to me.
Otherwise you should write something like:
That would be much much redundant.
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.
So how do I save the chat context, which is necessary in the implementation of
variant
?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.
Or
while
Omit
is a built-in type of typescript.