change ai provider from openai to openrouter
All checks were successful
Build and Push Docker Container / build-and-push (push) Successful in 2m1s
All checks were successful
Build and Push Docker Container / build-and-push (push) Successful in 2m1s
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# --- Stage 1: Build the Go application ---
|
# --- Stage 1: Build the Go application ---
|
||||||
FROM golang:1.23 AS builder
|
FROM golang:1.24 AS builder
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ENV GOOS=linux
|
ENV GOOS=linux
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/pkoukk/tiktoken-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
@@ -24,14 +22,14 @@ type OpenAi struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (oai *OpenAi) Summarize(text string) (string, error) {
|
func (oai *OpenAi) Summarize(text string) (string, error) {
|
||||||
apiURL := "https://api.openai.com/v1/chat/completions"
|
apiURL := "https://openrouter.ai/api/v1/chat/completions"
|
||||||
|
|
||||||
// Request payload
|
// Request payload
|
||||||
payload := map[string]interface{}{
|
payload := map[string]interface{}{
|
||||||
"model": "gpt-4o-mini",
|
"model": "google/gemini-2.5-flash-lite",
|
||||||
"messages": []map[string]string{
|
"messages": []map[string]string{
|
||||||
{
|
{
|
||||||
"role": "developer",
|
"role": "system",
|
||||||
"content": "Fasse den folgenden Zeitungsartikel in maximal 75 Wörtern zusammen. Konzentriere dich auf die wichtigsten Informationen, wie das Hauptthema, die zentralen Aussagen und relevante Hintergründe. Gib **außschließlich** die Zusammenfassung zurück.",
|
"content": "Fasse den folgenden Zeitungsartikel in maximal 75 Wörtern zusammen. Konzentriere dich auf die wichtigsten Informationen, wie das Hauptthema, die zentralen Aussagen und relevante Hintergründe. Gib **außschließlich** die Zusammenfassung zurück.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -88,16 +86,3 @@ func (oai *OpenAi) Summarize(text string) (string, error) {
|
|||||||
|
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (oai *OpenAi) CountTokens(text string) int {
|
|
||||||
tkm, err := tiktoken.GetEncoding("o200k_base")
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("getEncoding: %v", err)
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// encode
|
|
||||||
token := tkm.Encode(text, nil, nil)
|
|
||||||
|
|
||||||
return len(token)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user