When using OpenAI Assistants, developers typically must manage their own mapping between file identifiers (file_id), URLs, and titles due to OpenAI's lack of metadata support on files. Ragwalla's Assistants API provides a simple solution by allowing developers to create and manage these mappings easily.

Managing File Mappings with Ragwalla and OpenAI

When using OpenAI Assistants, developers typically must manage their own mapping between file identifiers (file_id), URLs, and titles due to OpenAI's lack of metadata support on files. Ragwalla's Assistants API provides a simple solution by allowing developers to create and manage these mappings easily.

Creating a File Mapping

After uploading a file to OpenAI, you can associate it with a URL using Ragwalla:

Step 1: Upload File to OpenAI

const uploadedFile = await openai.files.create({
  file: file,
  purpose: 'assistants'
});

Step 2: Create a Mapping in Ragwalla

Define your URL and create the mapping:

const docId = "your-document-id";
const url = `https://example.com/document/${docId}`;
const title = `Ragwalla: A Wire-Compatible OpenAI Assistants API`

const mappingResponse = await fetch('https://example.ai.ragwalla.com/v1/mapping', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${env.RAGWALLA_API_KEY}`
  },
  body: JSON.stringify({
    file_id: uploadedFile.id,
    url: url,
    title: title
  }),
});

if (!mappingResponse.ok) {
  throw new Error('Mapping creation failed');
}

Retrieving a File Mapping

Retrieve an existing mapping by making a GET request:

const response = await fetch(
  `https://example.ai.ragwalla.com/v1/mapping/${fileId}`,
  {
    method: "GET",
    headers: {
      'Authorization': `Bearer ${env.RAGWALLA_API_KEY}`,
    },
  }
);

if (response.ok) {
  const mappingData = await response.json();
  console.log('Mapped URL:', mappingData.url);
} else {
  console.error('Mapping retrieval failed:', await response.text());
}

Key Points:

  • Ragwalla streamlines document handling with respect to file mapping in your OpenAI Assistant workflows, reducing manual management tasks.