github.com/instill-ai/component@v0.16.0-beta/pkg/connector/openai/v0/text_generation.go (about) 1 package openai 2 3 const ( 4 completionsPath = "/v1/chat/completions" 5 ) 6 7 type TextMessage struct { 8 Role string `json:"role"` 9 Content []Content `json:"content"` 10 } 11 type TextCompletionInput struct { 12 Prompt string `json:"prompt"` 13 Images []string `json:"images"` 14 ChatHistory []*TextMessage `json:"chat_history,omitempty"` 15 Model string `json:"model"` 16 SystemMessage *string `json:"system_message,omitempty"` 17 Temperature *float32 `json:"temperature,omitempty"` 18 TopP *float32 `json:"top_p,omitempty"` 19 N *int `json:"n,omitempty"` 20 Stop *string `json:"stop,omitempty"` 21 MaxTokens *int `json:"max_tokens,omitempty"` 22 PresencePenalty *float32 `json:"presence_penalty,omitempty"` 23 FrequencyPenalty *float32 `json:"frequency_penalty,omitempty"` 24 ResponseFormat *ResponseFormatStruct `json:"response_format,omitempty"` 25 } 26 27 type ResponseFormatStruct struct { 28 Type string `json:"type,omitempty"` 29 } 30 31 type TextCompletionOutput struct { 32 Texts []string `json:"texts"` 33 } 34 35 type TextCompletionReq struct { 36 Model string `json:"model"` 37 Messages []interface{} `json:"messages"` 38 Temperature *float32 `json:"temperature,omitempty"` 39 TopP *float32 `json:"top_p,omitempty"` 40 N *int `json:"n,omitempty"` 41 Stop *string `json:"stop,omitempty"` 42 MaxTokens *int `json:"max_tokens,omitempty"` 43 PresencePenalty *float32 `json:"presence_penalty,omitempty"` 44 FrequencyPenalty *float32 `json:"frequency_penalty,omitempty"` 45 ResponseFormat *ResponseFormatStruct `json:"response_format,omitempty"` 46 } 47 48 type MultiModalMessage struct { 49 Role string `json:"role"` 50 Content []Content `json:"content"` 51 } 52 53 type Message struct { 54 Role string `json:"role"` 55 Content string `json:"content"` 56 } 57 58 type ImageURL struct { 59 URL string `json:"url"` 60 } 61 type Content struct { 62 Type string `json:"type"` 63 Text *string `json:"text,omitempty"` 64 ImageURL *ImageURL `json:"image_url,omitempty"` 65 } 66 67 type TextCompletionResp struct { 68 ID string `json:"id"` 69 Object string `json:"object"` 70 Created int `json:"created"` 71 Choices []Choices `json:"choices"` 72 Usage Usage `json:"usage"` 73 } 74 75 type OutputMessage struct { 76 Role string `json:"role"` 77 Content string `json:"content"` 78 } 79 80 type Choices struct { 81 Index int `json:"index"` 82 FinishReason string `json:"finish_reason"` 83 Message OutputMessage `json:"message"` 84 } 85 86 type Usage struct { 87 PromptTokens int `json:"prompt_tokens"` 88 CompletionTokens int `json:"completion_tokens"` 89 TotalTokens int `json:"total_tokens"` 90 }