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

Files created with client.Files.New() don't have names. Impossible to use them on vectorStore. #163

Open
ThadeuMelo opened this issue Jan 9, 2025 · 2 comments

Comments

@ThadeuMelo
Copy link

I'm trying to push some files and later use them on vectorstore assistants.
However, I can't add the files to VS because it rejects the names as not supported.

"{\n \"message\": \"Files with extensions [none] are not supported for retrieval. See https://platform.openai.com/docs/assistants/tools/file-search/supported-files\",\n \"type\": \"invalid_request_error\",\n \"param\": \"file_ids\",\n \"code\": \"unsupported_file\"\n }"

Checking the files created with this code.
I noticed that all of them are named 'anonymous_file'

content, err := os.ReadFile(config.FilePath + filename) // the file is inside the local directory if err != nil { fmt.Println("Err") } file, err := client.Files.New(context.TODO(), openai.FileNewParams{ File: openai.F(io.Reader(bytes.NewBuffer([]byte(content)))), Purpose: openai.F(openai.FilePurposeAssistants), })
Is that expected behavior?
I'm missing something?

@jacobzim-stl
Copy link
Collaborator

jacobzim-stl commented Jan 9, 2025

Thanks for bringing this up, try the solution in #91. We'll look into a better solution for the next launch too.

@dlo
Copy link

dlo commented Feb 24, 2025

In case it's helpful for anyone, I wanted to share a full solution here.

@jacobzim-stl FWIW, I think the biggest footgun is that it's not quite clear how to solve it based on the error message or the typings, so I think an updated example would do wonders here. I think the API design itself could be improved, but it definitely works as-is. It could just use better guardrails since (IMO) you shouldn't be able to upload an anonymous file to the assistants API since it can't really be used.

#150 specifically had the information that fixed this for me (use the openai.FileParam struct).

Here's a full example (also available at this gist):

package main

import (
	"bytes"
	"context"
	"io"

	"github.com/openai/openai-go"
)

func main() {
	client := openai.NewClient()

	s := "This is just random context"

	file, err := client.Files.New(context.TODO(), openai.FileNewParams{
		// IMPORTANT
		File:    openai.FileParam(io.Reader(bytes.NewBuffer([]byte(s))), "context.txt", "text/plain"),
		Purpose: openai.F(openai.FilePurposeAssistants),
	})
	if err != nil {
		panic(err)
	}
	vs, err := client.Beta.VectorStores.New(context.TODO(), openai.BetaVectorStoreNewParams{
		Name:    openai.F(" Vector Store"),
		FileIDs: openai.F([]string{file.ID}),
	})
	if err != nil {
		panic(err)
	}
	_, err = client.Beta.Assistants.New(context.TODO(), openai.BetaAssistantNewParams{
		Model:        openai.F(openai.ChatModelGPT4o),
		Name:         openai.F("Random Assistant"),
		Instructions: openai.F("You're a helpful assistant."),
		Tools: openai.F([]openai.AssistantToolUnionParam{openai.FileSearchToolParam{
			Type: openai.F(openai.FileSearchToolTypeFileSearch),
		}}),
		ToolResources: openai.F(openai.BetaAssistantNewParamsToolResources{
			FileSearch: openai.F(openai.BetaAssistantNewParamsToolResourcesFileSearch{
				VectorStoreIDs: openai.F([]string{vs.ID}),
			}),
		}),
	})
	if err != nil {
		panic(err)
	}
}

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

3 participants