Skip to content

Ask openai.GPT4o with a file request #809

Open
@mihaiav

Description

@mihaiav

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I'm trying to ask openai.GPT4o to analyze a html document/ file and extract keywords but I cannot find how to attach the html document to the prompt request

Describe the solution you'd like
A clear and concise description of what you want to happen.
A File field on openai.ChatCompletionRequest

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I've added the html content itself in the prompt but it confuses chatGPT and returns gibberish responses. See the reduced code I've tried:

func main(){
   content,_ := ioutil.ReadFile("x.html")
   response, _ := fmt.Sprintf("analyze the html content below and return me 10 keywords: \n %s", content)
func chat(cx context.Context, text string) (string, error) {
	client := openai.NewClient(openAIKey)
	resp, err := client.CreateChatCompletion(
		cx,
		openai.ChatCompletionRequest{

			Temperature: 2,
			Model:       openai.GPT4o, //  openai.GPT3Dot5Turbo,
			//	FilePath:    "./x.html",
			Messages: []openai.ChatCompletionMessage{
				{
					Role:    openai.ChatMessageRoleUser,
					Content: text,
				},
			},
		},
	)

	if err != nil {
		return "", err

	}

	return resp.Choices[0].Message.Content, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions