-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ai to theme plugin which allow users to generate theme by AI.
- Loading branch information
1 parent
9e0b9a9
commit efd1b9d
Showing
20 changed files
with
416 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package llm | ||
|
||
var provider Provider | ||
var model Model | ||
|
||
func GetInstance() (Provider, Model) { | ||
return provider, model | ||
} | ||
|
||
func SetInstance(p Provider, m Model) { | ||
provider = p | ||
model = m | ||
} | ||
|
||
func IsInstanceReady() bool { | ||
return provider != nil && model.Name != "" | ||
} |
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,69 @@ | ||
package llm | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
type ConversationRole string | ||
|
||
var ( | ||
ConversationRoleUser ConversationRole = "user" | ||
ConversationRoleSystem ConversationRole = "system" | ||
) | ||
|
||
type Conversation struct { | ||
Role ConversationRole | ||
Text string | ||
Timestamp int64 | ||
} | ||
|
||
type ModelProviderName string | ||
|
||
var ( | ||
ModelProviderNameOpenAI ModelProviderName = "openai" | ||
ModelProviderNameGoogle ModelProviderName = "google" | ||
ModelProviderNameOllama ModelProviderName = "ollama" | ||
ModelProviderNameGroq ModelProviderName = "groq" | ||
) | ||
|
||
type Model struct { | ||
DisplayName string | ||
Name string | ||
Provider ModelProviderName | ||
} | ||
|
||
type Provider interface { | ||
Close(ctx context.Context) error | ||
ChatStream(ctx context.Context, model Model, conversations []Conversation) (ChatStream, error) | ||
Chat(ctx context.Context, model Model, conversations []Conversation) (string, error) | ||
Models(ctx context.Context) ([]Model, error) | ||
} | ||
|
||
type ChatStream interface { | ||
Receive(ctx context.Context) (string, error) // will return io.EOF if no more messages | ||
} | ||
|
||
type ProviderConnectContext struct { | ||
Provider ModelProviderName | ||
|
||
ApiKey string | ||
Host string // E.g. "https://api.openai.com:8908" | ||
} | ||
|
||
func NewProvider(ctx context.Context, connectContext ProviderConnectContext) (Provider, error) { | ||
if connectContext.Provider == ModelProviderNameGoogle { | ||
return NewGoogleProvider(ctx, connectContext), nil | ||
} | ||
if connectContext.Provider == ModelProviderNameOpenAI { | ||
return NewOpenAIClient(ctx, connectContext), nil | ||
} | ||
if connectContext.Provider == ModelProviderNameOllama { | ||
return NewOllamaProvider(ctx, connectContext), nil | ||
} | ||
if connectContext.Provider == ModelProviderNameGroq { | ||
return NewGroqProvider(ctx, connectContext), nil | ||
} | ||
|
||
return nil, errors.New("unknown model provider") | ||
} |
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.