Skip to content

How to encapsulate the content of an image using ChatCompletionMessageParamUnion? #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
CNTWDev opened this issue Apr 6, 2025 · 0 comments

Comments

@CNTWDev
Copy link

CNTWDev commented Apr 6, 2025

i have a function to integrate the history messages.
how to do?

func (ai AIOfficialGPT) ParseMessages(q *AIParams) []openai.ChatCompletionMessageParamUnion {
	//  system prompt
	messages := make([]openai.ChatCompletionMessageParamUnion, 0)
	if len(q.PromptSystem) > 0 {
		messages = append(messages, openai.SystemMessage(q.PromptSystem))
	}
	for _, v := range q.History {
		if len(v.Message) > 0 {
			if v.Attachment != nil {
				//  gpt
				if v.Attachment.Type == "image" {
					messages = append(messages, openai.ChatCompletionMessageParamUnion{
						//Role: openai.ChatMessageRoleUser,
						//MultiContent: []openai.ChatMessagePart{
						//	{
						//		Type: "image_url",
						//		Text: "",
						//		ImageURL: &openai.ChatMessageImageURL{
						//			//  todo
						//			URL:    v.Attachment.FileUrl,
						//			Detail: "auto",
						//		},
						//	},
						//	{
						//		Type:     "text",
						//		Text:     v.Message,
						//		ImageURL: nil,
						//	},
						//},
					})
				}
			} else {
				messages = append(messages, openai.UserMessage(v.Message))
			}
		}
		if len(v.Reply) > 0 {
			messages = append(messages, openai.UserMessage(v.Reply))
		}
	}
	return messages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant