yomorun / yomo

🦖 Stateful Serverless Framework for Geo-distributed Edge AI Infra. with function calling support, write once, run on any model.
https://yomo.run
Apache License 2.0
1.65k stars 128 forks source link

refactor: split provider and register #743

Closed woorui closed 5 months ago

woorui commented 6 months ago

Description

  1. splitting the original LLMProvider into two interfaces, one for storing registered funcs and another for LLM requesting.
// 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.

// 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)
}
  1. Add the md attribute to the service and inject the md using the ExchangeMetadataFunc method. The signature of the ExchangeMetadataFunc function is as follows:
    
    // 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.
vercel[bot] commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **yomo** | ⬜️ Ignored ([Inspect](https://vercel.com/yomorun/yomo/7m4kEizdknFNhKA8RB4Fo3PhixRo)) | [Visit Preview](https://yomo-git-refactor-register-yomorun.vercel.app) | | Mar 10, 2024 7:10pm |
codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 45.00000% with 55 lines in your changes are missing coverage. Please review.

Project coverage is 58.21%. Comparing base (b5317dc) to head (93714e5). Report is 1 commits behind head on master.

Files Patch % Lines
pkg/bridge/ai/provider/gemini/provider.go 32.35% 23 Missing :warning:
pkg/bridge/ai/provider/azopenai/provider.go 0.00% 16 Missing :warning:
pkg/bridge/ai/provider/openai/provider.go 0.00% 16 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #743 +/- ## ========================================== - Coverage 59.20% 58.21% -1.00% ========================================== Files 42 45 +3 Lines 3226 3379 +153 ========================================== + Hits 1910 1967 +57 - Misses 1202 1298 +96 Partials 114 114 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.