Skip to content
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

Ask openai.GPT4o with a file request #809

Open
mihaiav opened this issue Jul 29, 2024 · 2 comments
Open

Ask openai.GPT4o with a file request #809

mihaiav opened this issue Jul 29, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mihaiav
Copy link

mihaiav commented Jul 29, 2024

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
}
@mihaiav mihaiav added the enhancement New feature or request label Jul 29, 2024
@WillMatthews
Copy link

There's nowhere in the API that allows generic file uploads. It's only text and images, within the prompt structure. In order to achieve the effect you want, you will have to either insert all the HTML as text as part of your prompt, or find a way to parse it to extract portions of the HTML (so you can save on tokens).

@WillMatthews
Copy link

Also - your temperature is extremely high- which may explain some of the "gibberish". Start with 0.7 and maybe reduce/increase it incrementally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants