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

ollama.create should not use process unless necessary to support client side use #164

Open
willcallender opened this issue Nov 18, 2024 · 0 comments

Comments

@willcallender
Copy link

Every other function in this library works in React, and is much more convenient than manually writing a function to handle the CURL API. However trying to run ollama.create in React gives an error due to process being unavailable. This might be neccessary when paths are provided, but when their not process.cwd doesn't need to be called at all. Tthis worked fine for me.

interface OllamaCreateParams {
  model: string;
  modelfile: string;
}

export async function ollama_create({ model, modelfile }: OllamaCreateParams) {
  try {
    const response = await fetch('http://localhost:11434/api/create', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ 'model': model, 'modelfile': modelfile, 'stream': false }),
    });
    
    if (!response.ok) {
      throw new Error('Failed to create model');
    }

    return response.status;

  } catch (error) {
    console.error('Error creating model:', error);
    throw error;
  }
}
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