-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: llm bridge server communicates with zipper in memory way (#996)
# Description 1. Implement `frame.Listener` using a golang channel. 2. Zipper supports managing multiple `frame.Listener` instances. 3. The LLM bridge server communicates with Zipper using the golang channel implementation of `frame.Listener`.
- Loading branch information
Showing
12 changed files
with
502 additions
and
66 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/yomorun/yomo" | ||
"github.com/yomorun/yomo/core" | ||
"github.com/yomorun/yomo/core/auth" | ||
"github.com/yomorun/yomo/core/frame" | ||
"github.com/yomorun/yomo/core/metadata" | ||
"github.com/yomorun/yomo/core/serverless" | ||
"github.com/yomorun/yomo/pkg/id" | ||
"github.com/yomorun/yomo/pkg/listener/mem" | ||
) | ||
|
||
var _ yomo.Source = &memSource{} | ||
|
||
type memSource struct { | ||
cred *auth.Credential | ||
conn *mem.FrameConn | ||
} | ||
|
||
func NewSource(conn *mem.FrameConn, cred *auth.Credential) yomo.Source { | ||
return &memSource{ | ||
conn: conn, | ||
cred: cred, | ||
} | ||
} | ||
|
||
func (m *memSource) Connect() error { | ||
hf := &frame.HandshakeFrame{ | ||
Name: "fc-source", | ||
ID: id.New(), | ||
ClientType: byte(core.ClientTypeSource), | ||
AuthName: m.cred.Name(), | ||
AuthPayload: m.cred.Payload(), | ||
Version: core.Version, | ||
} | ||
|
||
return m.conn.Handshake(hf) | ||
} | ||
|
||
func (m *memSource) Write(tag uint32, data []byte) error { | ||
df := &frame.DataFrame{ | ||
Tag: tag, | ||
Payload: data, | ||
} | ||
return m.conn.WriteFrame(df) | ||
} | ||
|
||
func (m *memSource) Close() error { return nil } | ||
func (m *memSource) SetErrorHandler(_ func(_ error)) {} | ||
func (m *memSource) WriteWithTarget(_ uint32, _ []byte, _ string) error { return nil } | ||
|
||
type memStreamFunction struct { | ||
observedTags []uint32 | ||
handler core.AsyncHandler | ||
cred *auth.Credential | ||
conn *mem.FrameConn | ||
} | ||
|
||
// NewReducer creates a new instance of memory StreamFunction. | ||
func NewReducer(conn *mem.FrameConn, cred *auth.Credential) yomo.StreamFunction { | ||
return &memStreamFunction{ | ||
conn: conn, | ||
cred: cred, | ||
} | ||
} | ||
|
||
func (m *memStreamFunction) Close() error { | ||
return nil | ||
} | ||
|
||
func (m *memStreamFunction) Connect() error { | ||
hf := &frame.HandshakeFrame{ | ||
Name: "fc-reducer", | ||
ID: id.New(), | ||
ClientType: byte(core.ClientTypeStreamFunction), | ||
AuthName: m.cred.Name(), | ||
AuthPayload: m.cred.Payload(), | ||
ObserveDataTags: m.observedTags, | ||
Version: core.Version, | ||
} | ||
|
||
if err := m.conn.Handshake(hf); err != nil { | ||
return nil | ||
} | ||
|
||
go func() { | ||
for { | ||
f, err := m.conn.ReadFrame() | ||
if err != nil { | ||
return | ||
} | ||
|
||
switch ff := f.(type) { | ||
case *frame.DataFrame: | ||
go m.onDataFrame(ff) | ||
default: | ||
return | ||
} | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func (m *memStreamFunction) onDataFrame(dataFrame *frame.DataFrame) { | ||
md, err := metadata.Decode(dataFrame.Metadata) | ||
if err != nil { | ||
return | ||
} | ||
|
||
serverlessCtx := serverless.NewContext(m.conn, dataFrame.Tag, md, dataFrame.Payload) | ||
m.handler(serverlessCtx) | ||
} | ||
|
||
func (m *memStreamFunction) SetHandler(fn core.AsyncHandler) error { | ||
m.handler = fn | ||
return nil | ||
} | ||
|
||
func (m *memStreamFunction) Init(_ func() error) error { return nil } | ||
func (m *memStreamFunction) SetCronHandler(_ string, _ core.CronHandler) error { return nil } | ||
func (m *memStreamFunction) SetErrorHandler(_ func(err error)) {} | ||
func (m *memStreamFunction) SetObserveDataTags(tags ...uint32) { m.observedTags = tags } | ||
func (m *memStreamFunction) SetPipeHandler(fn core.PipeHandler) error { return nil } | ||
func (m *memStreamFunction) SetWantedTarget(string) {} | ||
func (m *memStreamFunction) Wait() {} | ||
|
||
var _ yomo.StreamFunction = &memStreamFunction{} |
Oops, something went wrong.