-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split provider and register (#743)
# Description 1. splitting the original `LLMProvider` into two interfaces, one for storing registered funcs and another for LLM requesting. ```go // The storage interface type Register interface { ListToolCalls(md metadata.M) (map[uint32]ai.ToolCall, error) RegisterFunction(tag uint32, functionDefinition *ai.FunctionDefinition, connID uint64, md metadata.M) error UnregisterFunction(name string, connID uint64) } ``` Additionally, provide the `register.SetRegister()` method to allow modification of the default Register. ```go // The request interface type LLMProvider interface { // Name returns the name of the llm provider Name() string GetChatCompletions(prompt string, md metaddata.M) (*ai.InvokeResponse, error) } ``` 2. Add the `md` attribute to the `service` and inject the `md` using the `ExchangeMetadataFunc` method. The signature of the `ExchangeMetadataFunc` function is as follows: ```go // ExchangeMetadataFunc is used to exchange metadata type ExchangeMetadataFunc func(credential string) (metadata.M, error) // DefaultExchangeMetadataFunc is the default ExchangeMetadataFunc, It returns an empty metadata. func DefaultExchangeMetadataFunc(credential string) (metadata.M, error) { return metadata.M{}, nil } ``` 3. Declare the `HandleOverview` and `HandleInvoke` methods and mount the service to `req.Context()`. 4. fix `ConnMiddleware` function bug in the `ai.go` file.
- Loading branch information
Showing
17 changed files
with
459 additions
and
1,171 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
Oops, something went wrong.