mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
31 lines
738 B
Go
31 lines
738 B
Go
package oneapi
|
|
|
|
import (
|
|
"chat/globals"
|
|
"chat/utils"
|
|
)
|
|
|
|
type AdapterProps struct {
|
|
Model string
|
|
Plan bool
|
|
Infinity bool
|
|
Message []globals.Message
|
|
Token int
|
|
}
|
|
|
|
func HandleRequest(props *AdapterProps, hook globals.Hook) error {
|
|
instance := NewChatInstanceFromConfig()
|
|
return instance.CreateStreamChatRequest(&ChatProps{
|
|
Model: instance.FormatModel(props.Model),
|
|
Message: instance.FormatMessage(props.Message),
|
|
Token: utils.Multi(props.Token == 0, instance.GetToken(props.Model), props.Token),
|
|
}, func(data string) error {
|
|
return hook(instance.Process(data))
|
|
})
|
|
}
|
|
|
|
func Handle(props interface{}, hook globals.Hook) error {
|
|
conv := utils.MapToStruct[AdapterProps](props)
|
|
return HandleRequest(conv, hook)
|
|
}
|