-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added deepseek support * Added docs to readme and usage
- Loading branch information
Showing
7 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package deepseek | ||
|
||
import ( | ||
"github.com/baalimago/clai/internal/text/generic" | ||
) | ||
|
||
var DEEPSEEK_DEFAULT = Deepseek{ | ||
Model: "deepseek-chat", | ||
Temperature: 1.0, | ||
TopP: 1.0, | ||
Url: ChatURL, | ||
} | ||
|
||
type Deepseek struct { | ||
generic.StreamCompleter | ||
Model string `json:"model"` | ||
FrequencyPenalty float64 `json:"frequency_penalty"` | ||
MaxTokens *int `json:"max_tokens"` // Use a pointer to allow null value | ||
PresencePenalty float64 `json:"presence_penalty"` | ||
Temperature float64 `json:"temperature"` | ||
TopP float64 `json:"top_p"` | ||
Url string `json:"url"` | ||
} |
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,32 @@ | ||
package deepseek | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/baalimago/clai/internal/tools" | ||
) | ||
|
||
const ChatURL = "https://api.deepseek.com/chat/completions" | ||
|
||
func (g *Deepseek) Setup() error { | ||
if os.Getenv("DEEPSEEK_API_KEY") == "" { | ||
os.Setenv("DEEPSEEK_API_KEY", "deepseek") | ||
} | ||
err := g.StreamCompleter.Setup("DEEPSEEK_API_KEY", ChatURL, "DEEPSEEK_DEBUG") | ||
if err != nil { | ||
return fmt.Errorf("failed to setup stream completer: %w", err) | ||
} | ||
g.StreamCompleter.Model = g.Model | ||
g.StreamCompleter.FrequencyPenalty = &g.FrequencyPenalty | ||
g.StreamCompleter.MaxTokens = g.MaxTokens | ||
g.StreamCompleter.Temperature = &g.Temperature | ||
g.StreamCompleter.TopP = &g.TopP | ||
toolChoice := "auto" | ||
g.ToolChoice = &toolChoice | ||
return nil | ||
} | ||
|
||
func (g *Deepseek) RegisterTool(tool tools.AiTool) { | ||
g.InternalRegisterTool(tool) | ||
} |
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,56 @@ | ||
package deepseek | ||
|
||
import "github.com/baalimago/clai/internal/tools" | ||
|
||
// Copy from novita, and openai | ||
type ChatCompletion struct { | ||
ID string `json:"id"` | ||
Object string `json:"object"` | ||
Created int64 `json:"created"` | ||
Model string `json:"model"` | ||
Choices []Choice `json:"choices"` | ||
Usage Usage `json:"usage"` | ||
SystemFingerprint string `json:"system_fingerprint"` | ||
} | ||
|
||
type Choice struct { | ||
Index int `json:"index"` | ||
Delta Delta `json:"delta"` | ||
Logprobs interface{} `json:"logprobs"` // null or complex object, hence interface{} | ||
FinishReason string `json:"finish_reason"` | ||
} | ||
|
||
type Usage struct { | ||
PromptTokens int `json:"prompt_tokens"` | ||
CompletionTokens int `json:"completion_tokens"` | ||
TotalTokens int `json:"total_tokens"` | ||
} | ||
|
||
type Delta struct { | ||
Content any `json:"content"` | ||
Role string `json:"role"` | ||
ToolCalls []ToolsCall `json:"tool_calls"` | ||
} | ||
|
||
type ToolsCall struct { | ||
Function GptFunc `json:"function"` | ||
ID string `json:"id"` | ||
Index int `json:"index"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type GptFunc struct { | ||
Arguments string `json:"arguments"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type GptTool struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Inputs tools.InputSchema `json:"parameters"` | ||
} | ||
|
||
type GptToolSuper struct { | ||
Type string `json:"type"` | ||
Function GptTool `json:"function"` | ||
} |
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