-
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
Changes from 1 commit
4895ca1
bc5a45b
770453c
282bf5f
df26551
0fd3d2f
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 | ||||
---|---|---|---|---|---|---|
@@ -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,7 +37,7 @@ export const Config: Schema<Config> = Schema.intersect([ | |||||
}), | ||||||
]) | ||||||
|
||||||
const conversations = new Map<string, { messageId: string; conversationId: string }>() | ||||||
const conversations = new Map<string, Conversation>() | ||||||
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. Not really good to use type 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. What is your specific idea? My idea is to use the 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. I think just to revert this type would be good to me. export interface Conversation {
messageId: string
conversationId: string
}
export interface ConversationMessage extends Conversation {
message: string
} That would be much much redundant. 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. So how do I save the chat context, which is necessary in the implementation of 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. Or
Suggested change
while |
||||||
|
||||||
export function apply(ctx: Context, config: Config) { | ||||||
ctx.i18n.define('zh', require('./locales/zh-CN')) | ||||||
|
@@ -92,9 +92,21 @@ 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 }) | ||||||
const conversation: Conversation = conversations.get(key) ?? { message: '', conversationId: undefined, messageId: undefined } | ||||||
Seidko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
let action = 'next' | ||||||
switch (input) { | ||||||
case '重新说': | ||||||
action = 'variant' | ||||||
break | ||||||
case '继续说': | ||||||
action = 'continue' | ||||||
break | ||||||
default: | ||||||
conversation.message = input | ||||||
} | ||||||
|
||||||
Seidko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const response = await api.sendMessage(conversation, action) | ||||||
conversations.set(key, { message: input, conversationId: response.conversationId, messageId: response.messageId }) | ||||||
return response.message | ||||||
} catch (error) { | ||||||
logger.warn(error) | ||||||
|
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.
Would be better for the typing
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.
And you can consider to put action into
Conversation
type as well.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 don't think it's necessary. Because I think
conversation
represents the context of the chat, and I don't thinkaction
is part of the chat context, so I put it in the parameters ofsendMessage
.