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

File uploads hang indefinitely in SDK's uploadTempFile method #147

Open
MarianoMolina opened this issue Dec 9, 2024 · 0 comments
Open

Comments

@MarianoMolina
Copy link

MarianoMolina commented Dec 9, 2024

When trying to use image capabilities with the SDK, the uploadTempFile method in FilesNamespace hangs indefinitely. This prevents any functionality that relies on file uploads (like vision model usage) from working.

Steps to reproduce:

  1. Set up basic chat completion with vision model
  2. Try to process an image URL message:
{
    "role": "user",
    "content": [
        {
            "type": "image_url",
            "image_url": {
                "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Stadtbild_M%C3%BCnchen.jpg/2560px-Stadtbild_M%C3%BCnchen.jpg"
            }
        },
        {
            "type": "text",
            "text": "What city is this?"
        }
    ]
}

Code snippet:

        if (content.type === 'image_url' && content.image_url) {
            Logger.debug('Processing image:', content.image_url.url);
            let fileData: { mimeType: string; data: Uint8Array };

            try {
                if (this.isBase64DataUrl(content.image_url.url)) {
                    fileData = await this.processBase64DataUrl(content.image_url.url);
                } else {
                    fileData = await this.fetchFromUrl(content.image_url.url);
                }
                Logger.debug('Image processed:', fileData.mimeType, 'Size:', fileData.data.length);

                this.validateFileType(fileData.mimeType);
                this.validateFileSize(fileData.data);

                Logger.debug('Starting file upload...');
                const fileName = `image_${Date.now()}.${fileData.mimeType.split('/')[1]}`;
                Logger.debug('Generated filename:', fileName);

                try {
                    const fileHandle = await Promise.race([
                        this.filesNamespace.uploadTempFile(fileName, fileData.data),
                        new Promise((_, reject) =>
                            setTimeout(() => reject(new Error('Upload timeout after 30s')), 30000)
                        )
                    ]) as FileHandle;

                    Logger.debug('Upload successful. File handle:', {
                        identifier: fileHandle.identifier,
                        type: fileHandle.type,
                        size: fileHandle.sizeBytes
                    });

                    return { type: 'file', file: fileHandle };
                } catch (error: unknown) {
                    const errorMessage = error instanceof Error ? error.message : 'Unknown upload error';
                    Logger.error('Upload failed:', errorMessage);
                    throw new FileProcessingError(
                        `Failed to upload file: ${errorMessage}`,
                        'UPLOAD_FAILED'
                    );
                }

            } catch (error) {
                Logger.error('Image processing failed:', error);
                throw error;
            }
        }

The code hangs at:

const fileHandle = await this.filesNamespace.uploadTempFile(
    `image_${Date.now()}.${fileData.mimeType.split('/')[1]}`,
    fileData.data
);

Where data: Uint8Array

Expected behavior:

  • File should upload and return a FileHandle
  • Chat completion should proceed with the uploaded image

Actual behavior:

  • uploadTempFile never resolves or rejects
  • Program hangs indefinitely unless manually terminated

Environment:

  • LM Studio SDK version: 0.4.2
  • LM Studio: 0.3.5 b9
  • LMS cli: 0.0.28
  • OS: Windows

Other functionality like model loading/unloading works correctly, suggesting this is specific to the file upload implementation. Let me know if you need any additional information.

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

1 participant