This commit is contained in:
2025-05-23 09:33:05 +04:00
parent a16ac8f627
commit 79d66e4b6b
34 changed files with 603 additions and 608 deletions

View File

@@ -9,7 +9,7 @@ import (
"syscall"
"time"
proxy "github.com/freeflowuniverse/heroagent/pkg/proxies/openai"
openaiproxy "github.com/freeflowuniverse/heroagent/pkg/heroservices/openaiproxy"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
@@ -37,15 +37,15 @@ func testProxyWithClient() {
// Create a client that points to our proxy
// Note: The server is using "/ai" as the prefix for all routes
client := openai.NewClient(
client := openaiproxy.NewClient(
option.WithAPIKey("test-key"), // This is our test key, not a real OpenAI key
option.WithBaseURL("http://localhost:8080/ai"), // Use the /ai prefix to match the server routes
)
// Create a completion request
chatCompletion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Messages: []openai.ChatCompletionMessageParamUnion{
openai.UserMessage("Say this is a test"),
chatCompletion, err := client.Chat.Completions.New(context.Background(), openaiproxy.ChatCompletionNewParams{
Messages: []openaiproxy.ChatCompletionMessageParamUnion{
openaiproxy.UserMessage("Say this is a test"),
},
Model: "gpt-3.5-turbo", // Use a model that our proxy supports
})
@@ -70,9 +70,9 @@ func runServerMode() {
// Create a proxy configuration
config := proxy.ProxyConfig{
Port: 8080, // Use a non-privileged port for testing
OpenAIBaseURL: "https://api.openai.com", // Default OpenAI API URL
DefaultOpenAIKey: openaiKey, // Fallback API key if user doesn't have one
Port: 8080, // Use a non-privileged port for testing
OpenAIBaseURL: "https://api.openaiproxy.com", // Default OpenAI API URL
DefaultOpenAIKey: openaiKey, // Fallback API key if user doesn't have one
}
// Create a new factory with the configuration

View File

@@ -119,7 +119,7 @@ func createJob(c *fiber.Ctx, apiKey string, endpoint string, requestBody interfa
// Create a new job
job := jobsmanager.NewJob()
job.ParamsType = jobsmanager.ParamsTypeAI
job.Topic = "openai-proxy"
job.Topic = "openaiproxy-proxy"
job.CircleID = "ai"
// Serialize request body to JSON
@@ -183,7 +183,7 @@ func (s *Server) handleModels(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/models"
if url == "/v1/models" {
url = "https://api.openai.com/v1/models"
url = "https://api.openaiproxy.com/v1/models"
}
req, err := http.NewRequest("GET", url, nil)
@@ -250,7 +250,7 @@ func (s *Server) handleGetModel(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/models/" + modelID
if strings.HasPrefix(url, "/v1/models/") {
url = "https://api.openai.com/v1/models/" + modelID
url = "https://api.openaiproxy.com/v1/models/" + modelID
}
req, err := http.NewRequest("GET", url, nil)
@@ -337,7 +337,7 @@ func (s *Server) handleChatCompletions(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/chat/completions"
if url == "/v1/chat/completions" {
url = "https://api.openai.com/v1/chat/completions"
url = "https://api.openaiproxy.com/v1/chat/completions"
}
// Convert the request body back to JSON
@@ -461,7 +461,7 @@ func (s *Server) handleCompletions(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/completions"
if url == "/v1/completions" {
url = "https://api.openai.com/v1/completions"
url = "https://api.openaiproxy.com/v1/completions"
}
// Convert the request body back to JSON
@@ -585,7 +585,7 @@ func (s *Server) handleEmbeddings(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/embeddings"
if url == "/v1/embeddings" {
url = "https://api.openai.com/v1/embeddings"
url = "https://api.openaiproxy.com/v1/embeddings"
}
// Convert the request body back to JSON
@@ -724,7 +724,7 @@ func (s *Server) handleImagesGenerations(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/images/generations"
if url == "/v1/images/generations" {
url = "https://api.openai.com/v1/images/generations"
url = "https://api.openaiproxy.com/v1/images/generations"
}
// Convert the request body back to JSON
@@ -919,7 +919,7 @@ func (s *Server) handleListFiles(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/files"
if url == "/v1/files" {
url = "https://api.openai.com/v1/files"
url = "https://api.openaiproxy.com/v1/files"
}
req, err := http.NewRequest("GET", url, nil)
@@ -1017,7 +1017,7 @@ func (s *Server) handleGetFile(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/files/" + fileID
if strings.HasPrefix(url, "/v1/files/") {
url = "https://api.openai.com/v1/files/" + fileID
url = "https://api.openaiproxy.com/v1/files/" + fileID
}
req, err := http.NewRequest("GET", url, nil)
@@ -1084,7 +1084,7 @@ func (s *Server) handleDeleteFile(c *fiber.Ctx) error {
// Forward request to OpenAI
url := s.Factory.Config.OpenAIBaseURL + "/v1/files/" + fileID
if strings.HasPrefix(url, "/v1/files/") {
url = "https://api.openai.com/v1/files/" + fileID
url = "https://api.openaiproxy.com/v1/files/" + fileID
}
req, err := http.NewRequest("DELETE", url, nil)