chat compress and some features
This commit is contained in:
@@ -22,21 +22,18 @@ type OpenAIResponse struct {
|
||||
Usage Usage `json:"usage"`
|
||||
ServiceTier string `json:"service_tier"`
|
||||
}
|
||||
|
||||
type Choice struct {
|
||||
Index int64 `json:"index"`
|
||||
Message Message `json:"message"`
|
||||
Logprobs interface{} `json:"logprobs"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
Refusal interface{} `json:"refusal"`
|
||||
Annotations []interface{} `json:"annotations"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
PromptTokens int64 `json:"prompt_tokens"`
|
||||
CompletionTokens int64 `json:"completion_tokens"`
|
||||
@@ -44,19 +41,16 @@ type Usage struct {
|
||||
PromptTokensDetails PromptTokensDetails `json:"prompt_tokens_details"`
|
||||
CompletionTokensDetails CompletionTokensDetails `json:"completion_tokens_details"`
|
||||
}
|
||||
|
||||
type CompletionTokensDetails struct {
|
||||
ReasoningTokens int64 `json:"reasoning_tokens"`
|
||||
AudioTokens int64 `json:"audio_tokens"`
|
||||
AcceptedPredictionTokens int64 `json:"accepted_prediction_tokens"`
|
||||
RejectedPredictionTokens int64 `json:"rejected_prediction_tokens"`
|
||||
}
|
||||
|
||||
type PromptTokensDetails struct {
|
||||
CachedTokens int64 `json:"cached_tokens"`
|
||||
AudioTokens int64 `json:"audio_tokens"`
|
||||
}
|
||||
|
||||
type OpenAIAPI struct {
|
||||
Token string
|
||||
Model string
|
||||
@@ -67,7 +61,11 @@ type OpenAIAPI struct {
|
||||
|
||||
func NewOpenAIAPI(baseURL, token, model string) *OpenAIAPI {
|
||||
logger := laniakea.CreateLogger()
|
||||
logger = logger.Prefix("AI").Level(laniakea.DEBUG)
|
||||
level := laniakea.FATAL
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
level = laniakea.DEBUG
|
||||
}
|
||||
logger = logger.Prefix("AI").Level(level)
|
||||
proxy, err := url.Parse(os.Getenv("HTTPS_PROXY"))
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
@@ -160,9 +158,16 @@ func (o *OpenAIAPI) DoRequest(url string, params any, retries int) ([]byte, erro
|
||||
return responseBody, err
|
||||
}
|
||||
|
||||
func (o *OpenAIAPI) CreateCompletion(request CreateCompletionReq) (*OpenAIResponse, error) {
|
||||
func (o *OpenAIAPI) CreateCompletion(history []Message, message string, temp float32) (*OpenAIResponse, error) {
|
||||
u := fmt.Sprintf("%s/v1/chat/completions", o.BaseURL)
|
||||
request.Model = o.Model
|
||||
request := CreateCompletionReq{
|
||||
Model: o.Model,
|
||||
Messages: append(history, Message{
|
||||
Role: "user",
|
||||
Content: message,
|
||||
}),
|
||||
Temperature: temp,
|
||||
}
|
||||
data, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user