Help to pass file id in correct object using the correct attribute

Hello guys, I have been created a code where I will ask for the AI to convert some sql scripts, for help the AI in this work I upload a file with the ddl of my base, and I get the file id.

Here my problem, where could I link the file id and how?
Its in assistant or thread or message? Because I had tryed all them and I got errors like file_ids dont exist or file_input dont exist, so or I put the file in wrong object or my attribute name is incorret, someone could help me please.

#file create - ok
file = openai.files.create(
  file=open('test/test.txt','rb'),
  purpose='assistants'
)

#{'id': 'file-7xfcQtHYhTDdjfFYwHmocd', 'bytes': 97137506, 'created_at': 1741605217, 'filename': 'completeDdl.txt', 'object': 'file', 'purpose': 'assistants', 'status': 'processed', 'expires_at': None, 'status_details': None}

#assistant - ok, but if i try put file_ids = [{file.id}], error file_ids dont exist show me
assistant = openai.beta.assistants.create(
  instructions = "You are a SQL Server DBA",
  name="SQL Server DBA",
  model="o3-mini"
)

#thread - ok, , but if i try put file_ids = [{file.id}], error file_ids dont exist show me
thread = openai.beta.threads.create()

#message - ok, but if i try put file_ids = [{file.id}], error file_ids dont exist show me
openai.beta.threads.messages.create(
  thread_id= thread.id,
  assistant_id = assistant .id,
  content = "my prompt"
)

#run-ok, but if i try put file_ids = [{file.id}], error file_ids dont exist show me
run = openai.beta.threads.run.create(
  thread_id= thread.id,
  assistant_id = assistant .id
)

#wait some seconds to finalize the run
while ....

#get return message
message_returne = openai.beta.threads.messages.list(thread_id = thread.id)
return message_returne.data[0].text.value
1 Like

check out this seciont on messages inside threads: https://platform.openai.com/docs/api-reference/messages/createMessage you create a message with the correct content. (This is for images). In your example I assume you want to add this text file as RAG, so then you would instead enable file_search in your RUN and give it the file_id https://platform.openai.com/docs/api-reference/runs/createRun look under tools here!

1 Like

Hi thank you for your support, I can do this using that code:

openai.beta.assistants.create(
                name="SQL Server Dba",
                instructions=prompt,                
                tools=[{"type": "code_interpreter"}],
                tool_resources={
                    "code_interpreter": {
                        "file_ids": [self.file_input.id]
                    }
                },
                model=self.model                
            )

But I think about and try to using code_interpreter and file_search the same time, its possible? Because I tried to do that and I get an error:
new code:

tools=[{"type": "code_interpreter"},{"type": "file_search"}],
             tool_resources={
                 "code_interpreter": {
                     "file_ids": [self.file_input.id]
                 },
                 "file_search": {
                     "file_ids": [self.file_input.id]
                 }
             },
             model=self.model   

Error code:

Exception has occurred: BadRequestError
Error code: 400 - {'error': {'message': "Unknown parameter: 'tool_resources.file_search.file_ids'.", 'type': 'invalid_request_error', 'param': 'tool_resources.file_search.file_ids', 'code': 'unknown_parameter'}}

I do it using Vector Store, which makes it possible to use Code Interpreter and File Search together. Thz for your help.

Code interpreter and file search combined is depending on the model. Not vector or file. Both can work with code interpreter.

1 Like