mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
release v1.0.1
This commit is contained in:
41
gpt/gpt.go
41
gpt/gpt.go
@@ -27,8 +27,13 @@ type Chat struct {
|
||||
}
|
||||
|
||||
type Gpt3Request struct {
|
||||
Model string `json:"model"`
|
||||
Messages []Chat `json:"messages"`
|
||||
Model string `json:"model"`
|
||||
Stream bool `json:"stream"`
|
||||
Messages []Chat `json:"messages"`
|
||||
Options Gpt3Options `json:"options"`
|
||||
}
|
||||
|
||||
type Gpt3Options struct {
|
||||
Temperature float64 `json:"temperature"`
|
||||
}
|
||||
|
||||
@@ -38,6 +43,20 @@ type Gpt3Response struct {
|
||||
} `json:"choices"`
|
||||
}
|
||||
|
||||
// LlamaResponse represents the response structure.
|
||||
type OllamaResponse struct {
|
||||
Model string `json:"model"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Message Chat `json:"message"`
|
||||
Done bool `json:"done"`
|
||||
TotalDuration int64 `json:"total_duration"`
|
||||
LoadDuration int64 `json:"load_duration"`
|
||||
PromptEvalCount int64 `json:"prompt_eval_count"`
|
||||
PromptEvalDuration int64 `json:"prompt_eval_duration"`
|
||||
EvalCount int64 `json:"eval_count"`
|
||||
EvalDuration int64 `json:"eval_duration"`
|
||||
}
|
||||
|
||||
func (gpt3 *Gpt3) deleteApiKey() {
|
||||
filePath := gpt3.HomeDir + string(filepath.Separator) + gpt3.ApiKeyFile
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
@@ -132,17 +151,19 @@ func (gpt3 *Gpt3) Completions(ask string) string {
|
||||
panic(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+strings.TrimSpace(gpt3.ApiKey))
|
||||
// req.Header.Set("Authorization", "Bearer "+strings.TrimSpace(gpt3.ApiKey))
|
||||
|
||||
messages := []Chat{
|
||||
{"system", gpt3.Prompt},
|
||||
{"user", ask},
|
||||
{"user", ask + "." + gpt3.Prompt},
|
||||
}
|
||||
payload := Gpt3Request{
|
||||
gpt3.Model,
|
||||
messages,
|
||||
gpt3.Temperature,
|
||||
Model: gpt3.Model,
|
||||
Messages: messages,
|
||||
Stream: false,
|
||||
Options: Gpt3Options{gpt3.Temperature},
|
||||
}
|
||||
|
||||
payloadJson, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -166,11 +187,13 @@ func (gpt3 *Gpt3) Completions(ask string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var res Gpt3Response
|
||||
// var res Gpt3Response
|
||||
var res OllamaResponse
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(res.Choices[0].Message.Content)
|
||||
// return strings.TrimSpace(res.Choices[0].Message.Content)
|
||||
return strings.TrimSpace(res.Message.Content)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user