package fastgpt

import (
	"context"
	"github.com/sashabaranov/go-openai"
)

func ChatWithCustomConfig(baseURL, apiKey, prompt, systemPrompt string) (string, error) {
	// 创建OpenAI客户端配置
	config := openai.DefaultConfig(apiKey)
	config.BaseURL = baseURL

	// 创建OpenAI客户端
	openaiClient := openai.NewClientWithConfig(config)

	// 构建请求
	request := openai.ChatCompletionRequest{
		Model: openai.GPT4o,
		Messages: []openai.ChatCompletionMessage{
			{
				Role:    "user",
				Content: prompt,
			},
			{
				Role:    "system",
				Content: systemPrompt,
			},
		},
		Stream: false,
	}

	// 调用Chat接口
	response, err := openaiClient.CreateChatCompletion(context.Background(), request)
	if err != nil {
		return "", err
	}

	// 返回响应内容
	return response.Choices[0].Message.Content, nil
}
