push of current changes
This commit is contained in:
parent
a67ad54bcc
commit
f4214f656b
@ -1,9 +1,10 @@
|
||||
package llm
|
||||
package go_llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
anth "github.com/liushuangls/go-anthropic/v2"
|
||||
"log"
|
||||
)
|
||||
|
||||
type anthropic struct {
|
||||
@ -45,15 +46,26 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
role = anth.RoleAssistant
|
||||
}
|
||||
|
||||
msgs = append(msgs, anth.Message{
|
||||
Role: role,
|
||||
Content: []anth.MessageContent{
|
||||
{
|
||||
Type: anth.MessagesContentTypeText,
|
||||
Text: &msg.Text,
|
||||
},
|
||||
},
|
||||
})
|
||||
m := anth.Message{
|
||||
Role: role,
|
||||
Content: []anth.MessageContent{},
|
||||
}
|
||||
|
||||
if msg.Text != "" {
|
||||
m.Content = append(m.Content, anth.MessageContent{
|
||||
Type: anth.MessagesContentTypeText,
|
||||
Text: &msg.Text,
|
||||
})
|
||||
}
|
||||
|
||||
if msg.ImageBase64 != "" {
|
||||
m.Content = append(m.Content, anth.NewImageMessageContent(anth.MessageContentImageSource{
|
||||
Type: "base64",
|
||||
MediaType: "image/png",
|
||||
Data: msg.ImageBase64,
|
||||
}))
|
||||
}
|
||||
msgs = append(msgs, m)
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,6 +79,12 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
|
||||
res.Messages = msgs
|
||||
|
||||
if req.Temperature != nil {
|
||||
res.Temperature = req.Temperature
|
||||
}
|
||||
|
||||
log.Println("llm request to anthropic request", res)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@ -97,6 +115,8 @@ func (a anthropic) responseToLLMResponse(in anth.MessagesResponse) Response {
|
||||
res.Choices = append(res.Choices, choice)
|
||||
}
|
||||
|
||||
log.Println("anthropic response to llm response", res)
|
||||
|
||||
return res
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package llm
|
||||
package go_llm
|
||||
|
||||
type Function struct {
|
||||
Name string `json:"name"`
|
25
go.mod
25
go.mod
@ -1,27 +1,8 @@
|
||||
module go-llm
|
||||
module gitea.stevedudenhoeffer.com/steve/go-llm
|
||||
|
||||
go 1.23.1
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/bubbles v0.20.0 // indirect
|
||||
github.com/charmbracelet/bubbletea v1.1.1 // indirect
|
||||
github.com/charmbracelet/lipgloss v0.13.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.2.3 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/liushuangls/go-anthropic/v2 v2.8.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.15.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/sashabaranov/go-openai v1.31.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
golang.org/x/text v0.3.8 // indirect
|
||||
github.com/liushuangls/go-anthropic/v2 v2.8.0
|
||||
github.com/sashabaranov/go-openai v1.31.0
|
||||
)
|
||||
|
43
go.sum
43
go.sum
@ -1,47 +1,4 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||
github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY=
|
||||
github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
|
||||
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
|
||||
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
|
||||
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
|
||||
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
||||
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
|
||||
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/liushuangls/go-anthropic/v2 v2.8.0 h1:0zH2jDNycbrlszxnLrG+Gx8vVT0yJAPWU4s3ZTkWzgI=
|
||||
github.com/liushuangls/go-anthropic/v2 v2.8.0/go.mod h1:8BKv/fkeTaL5R9R9bGkaknYBueyw2WxY20o7bImbOek=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
|
||||
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/sashabaranov/go-openai v1.31.0 h1:rGe77x7zUeCjtS2IS7NCY6Tp4bQviXNMhkQM6hz/UC4=
|
||||
github.com/sashabaranov/go-openai v1.31.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
|
@ -1,4 +1,4 @@
|
||||
package llm
|
||||
package go_llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -13,14 +13,16 @@ const (
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Role Role
|
||||
Name string
|
||||
Text string
|
||||
Role Role
|
||||
Name string
|
||||
Text string
|
||||
ImageBase64 string // ImageBase64 is the base64 string if the message contains an image, empty string otherwise.
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Messages []Message
|
||||
Toolbox []Function
|
||||
Messages []Message
|
||||
Toolbox []Function
|
||||
Temperature *float32
|
||||
}
|
||||
|
||||
type ToolCall struct {
|
@ -1,4 +1,4 @@
|
||||
package llm
|
||||
package go_llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -19,11 +19,24 @@ func (o openai) requestToOpenAIRequest(request Request) oai.ChatCompletionReques
|
||||
}
|
||||
|
||||
for _, msg := range request.Messages {
|
||||
res.Messages = append(res.Messages, oai.ChatCompletionMessage{
|
||||
m := oai.ChatCompletionMessage{
|
||||
Content: msg.Text,
|
||||
Role: string(msg.Role),
|
||||
Name: msg.Name,
|
||||
})
|
||||
}
|
||||
|
||||
if msg.ImageBase64 != "" {
|
||||
part := oai.ChatMessagePart{
|
||||
Type: "image_url",
|
||||
ImageURL: &oai.ChatMessageImageURL{
|
||||
URL: fmt.Sprintf("data:image/jpeg;base64,%s", msg.ImageBase64),
|
||||
},
|
||||
}
|
||||
|
||||
m.MultiContent = append(m.MultiContent, part)
|
||||
}
|
||||
|
||||
res.Messages = append(res.Messages, m)
|
||||
}
|
||||
|
||||
for _, tool := range request.Toolbox {
|
||||
@ -38,6 +51,10 @@ func (o openai) requestToOpenAIRequest(request Request) oai.ChatCompletionReques
|
||||
})
|
||||
}
|
||||
|
||||
if request.Temperature != nil {
|
||||
res.Temperature = *request.Temperature
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user