| package main
|
|
|
|
|
|
|
|
|
| type ChatCompletionRequest struct {
|
| Model string `json:"model"`
|
| Messages []ChatMessage `json:"messages"`
|
| Temperature *float64 `json:"temperature,omitempty"`
|
| Stream bool `json:"stream,omitempty"`
|
| MaxTokens *int `json:"max_tokens,omitempty"`
|
| TopP *float64 `json:"top_p,omitempty"`
|
| Stop interface{} `json:"stop,omitempty"`
|
| User string `json:"user,omitempty"`
|
| Extra map[string]interface{} `json:"-"`
|
| }
|
|
|
|
|
| type ChatMessage struct {
|
| Role string `json:"role"`
|
| Content interface{} `json:"content"`
|
| }
|
|
|
| type Content struct {
|
| Type string `json:"type"`
|
| Text string `json:"text"`
|
| }
|
|
|
|
|
| func (r *ChatCompletionRequest) ToOpenAIRequest() ChatCompletionRequest {
|
|
|
| messages := make([]ChatMessage, len(r.Messages))
|
| for i, msg := range r.Messages {
|
| var content string
|
| switch v := msg.Content.(type) {
|
| case string:
|
| content = v
|
| case []Content:
|
| for _, c := range v {
|
| content += c.Text
|
| }
|
| case []interface{}:
|
| for _, c := range v {
|
| if contentMap, ok := c.(map[string]interface{}); ok {
|
| if text, ok := contentMap["text"].(string); ok {
|
| content += text
|
| }
|
| }
|
| }
|
| }
|
| messages[i] = ChatMessage{
|
| Role: msg.Role,
|
| Content: content,
|
| }
|
| }
|
|
|
|
|
| return ChatCompletionRequest{
|
| Model: r.Model,
|
| Temperature: r.Temperature,
|
| Messages: messages,
|
| Stream: r.Stream,
|
| }
|
| }
|
|
|
|
|
| type ChatCompletionResponse struct {
|
| ID string `json:"id"`
|
| Object string `json:"object"`
|
| Created int64 `json:"created"`
|
| Model string `json:"model"`
|
| Choices []ChatCompletionChoice `json:"choices"`
|
| Usage ChatCompletionUsage `json:"usage"`
|
| }
|
|
|
|
|
| type ChatCompletionChoice struct {
|
| Index int `json:"index"`
|
| Message *ChatMessage `json:"message,omitempty"`
|
| Delta *ChatMessage `json:"delta,omitempty"`
|
| FinishReason *string `json:"finish_reason"`
|
| }
|
|
|
|
|
| type ChatCompletionUsage struct {
|
| PromptTokens *int `json:"prompt_tokens"`
|
| CompletionTokens *int `json:"completion_tokens"`
|
| TotalTokens *int `json:"total_tokens"`
|
| }
|
|
|
|
|
| type ChatCompletionStreamResponse struct {
|
| ID string `json:"id"`
|
| Object string `json:"object"`
|
| Created int64 `json:"created"`
|
| Model string `json:"model"`
|
| Choices []ChatCompletionChoice `json:"choices"`
|
| }
|
|
|
|
|
| type ModelsResponse struct {
|
| Object string `json:"object"`
|
| Data []Model `json:"data"`
|
| }
|
|
|
|
|
| type Model struct {
|
| ID string `json:"id"`
|
| Object string `json:"object"`
|
| Created int64 `json:"created"`
|
| OwnedBy string `json:"owned_by"`
|
| }
|
|
|
|
|
|
|
|
|
| type AtlassianRequest struct {
|
| RequestPayload AtlassianRequestPayload `json:"request_payload"`
|
| PlatformAttributes AtlassianPlatformAttrs `json:"platform_attributes"`
|
| }
|
|
|
|
|
| type AtlassianRequestPayload struct {
|
| Messages []ChatMessage `json:"messages"`
|
| Temperature *float64 `json:"temperature,omitempty"`
|
| Stream bool `json:"stream,omitempty"`
|
| }
|
|
|
|
|
| type AtlassianPlatformAttrs struct {
|
| Model string `json:"model"`
|
| }
|
|
|
|
|
| type AtlassianResponse struct {
|
| ResponsePayload AtlassianResponsePayload `json:"response_payload"`
|
| PlatformAttributes AtlassianPlatformAttrs `json:"platform_attributes"`
|
| }
|
|
|
|
|
| type AtlassianResponsePayload struct {
|
| ID string `json:"id"`
|
| Created int64 `json:"created"`
|
| Choices []AtlassianResponseChoice `json:"choices"`
|
| }
|
|
|
|
|
| type AtlassianResponseChoice struct {
|
| Index int `json:"index"`
|
| Message AtlassianResponseMessage `json:"message"`
|
| FinishReason *string `json:"finish_reason"`
|
| }
|
|
|
|
|
| type AtlassianResponseMessage struct {
|
| Role string `json:"role"`
|
| Content []AtlassianContentElement `json:"content"`
|
| }
|
|
|
|
|
| type AtlassianContentElement struct {
|
| Text string `json:"text"`
|
| }
|
|
|
|
|
| type AtlassianMetrics struct {
|
| Usage ChatCompletionUsage `json:"usage"`
|
| }
|
|
|
|
|
| type AtlassianStreamChunk struct {
|
| ResponsePayload AtlassianResponsePayload `json:"response_payload"`
|
| }
|
|
|