-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: provider handling and core interfaces (#173)
- Add error handling for invalid provider in `commit.go` - Replace `NewOpenAI` initialization with a switch case for different providers - Simplify the summary prefix retrieval logic in `commit.go` - Create a new `core/openai.go` file defining `Usage`, `Response`, and `Generative` interface - Create a new `core/platform.go` file defining `Platform` type and its methods - Implement `Completion` and `GetSummaryPrefix` methods in `openai.go` for the `core.Generative` interface - Refactor `Completion` method to `completion` in `openai.go` Signed-off-by: appleboy <appleboy.tw@gmail.com>
- Loading branch information
Showing
4 changed files
with
116 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Usage struct { | ||
PromptTokens int | ||
CompletionTokens int | ||
TotalTokens int | ||
} | ||
|
||
type Response struct { | ||
Content string | ||
Usage Usage | ||
} | ||
|
||
type Generative interface { | ||
// CreateCompletion is an API call to create a completion. | ||
Completion(ctx context.Context, content string) (resp *Response, err error) | ||
// GetSummaryPrefix is an API call to get a summary prefix using function call. | ||
GetSummaryPrefix(ctx context.Context, content string) (resp *Response, err error) | ||
} |
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 core | ||
|
||
type Platform string | ||
|
||
const ( | ||
OpenAI Platform = "openai" | ||
Azure Platform = "azure" | ||
Gemini Platform = "gemini" | ||
) | ||
|
||
// String returns the string representation of the Platform. | ||
func (p Platform) String() string { | ||
return string(p) | ||
} | ||
|
||
// IsValid returns true if the Platform is valid. | ||
func (p Platform) IsValid() bool { | ||
switch p { | ||
case OpenAI, Azure, Gemini: | ||
return true | ||
} | ||
return false | ||
} |
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