-
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.
The commit introduces AI providers in Wox setting, replacing the existing LLM model. It includes changes in the structure and usage of AIProviders throughout the program. The code now supports AI chat, models, and AI provider settings. Also, the naming consistency has been maintained by renaming 'llm.go' to 'ai_command.go'.
- Loading branch information
1 parent
1f183c5
commit fc61348
Showing
21 changed files
with
607 additions
and
709 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ai | ||
|
||
type ConversationRole string | ||
|
||
var ( | ||
ConversationRoleUser ConversationRole = "user" | ||
ConversationRoleSystem ConversationRole = "system" | ||
) | ||
|
||
type Conversation struct { | ||
Role ConversationRole | ||
Text string | ||
Timestamp int64 | ||
} |
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 @@ | ||
package ai |
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,6 @@ | ||
package ai | ||
|
||
type Model struct { | ||
Name string | ||
Provider ProviderName | ||
} |
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,53 @@ | ||
package ai | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"wox/setting" | ||
) | ||
|
||
type ProviderName string | ||
|
||
var ( | ||
ProviderNameOpenAI ProviderName = "openai" | ||
ProviderNameGoogle ProviderName = "google" | ||
ProviderNameOllama ProviderName = "ollama" | ||
ProviderNameGroq ProviderName = "groq" | ||
) | ||
|
||
type Provider interface { | ||
Close(ctx context.Context) error | ||
ChatStream(ctx context.Context, model Model, conversations []Conversation) (ChatStream, error) | ||
Models(ctx context.Context) ([]Model, error) | ||
} | ||
|
||
type ChatStreamDataType string | ||
|
||
const ( | ||
ChatStreamTypeStreaming ChatStreamDataType = "streaming" | ||
ChatStreamTypeFinished ChatStreamDataType = "finished" | ||
ChatStreamTypeError ChatStreamDataType = "error" | ||
) | ||
|
||
type ChatStreamFunc func(t ChatStreamDataType, data string) | ||
|
||
type ChatStream interface { | ||
Receive(ctx context.Context) (string, error) // will return io.EOF if no more messages | ||
} | ||
|
||
func NewProvider(ctx context.Context, providerSetting setting.AIProvider) (Provider, error) { | ||
if providerSetting.Name == string(ProviderNameGoogle) { | ||
return NewGoogleProvider(ctx, providerSetting), nil | ||
} | ||
if providerSetting.Name == string(ProviderNameOpenAI) { | ||
return NewOpenAIClient(ctx, providerSetting), nil | ||
} | ||
if providerSetting.Name == string(ProviderNameOllama) { | ||
return NewOllamaProvider(ctx, providerSetting), nil | ||
} | ||
if providerSetting.Name == string(ProviderNameGroq) { | ||
return NewGroqProvider(ctx, providerSetting), 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
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.