monarchwadia / ragged

33 stars 4 forks source link

Implement ollama #15

Closed markwylde closed 2 months ago

markwylde commented 2 months ago

This is my initial attempt at implementing the Ollama adapter.

Example usage:

const adapter = provideOllamaChatAdapter({
  config: {
    apiKey: process.env.OLLAMA_API_KEY,
    model: "llama3",
    stream: false,
  },
});

const request: ChatAdapterRequest = {
  history: [
    {
      type: "user",
      text: "Reply with only the single word Hello, and nothing else",
    },
  ],
};

const response = await adapter.chat(request);
markwylde commented 2 months ago

Am I right in thinking this should automatically work?

const c = Chat.with('ollama');
const messages = await c.chat('What is a rickroll?');
monarchwadia commented 2 months ago

This looks great! Thank you for the contribution-in-progress.

Am I right in thinking this should automatically work?

const c = Chat.with('ollama');
const messages = await c.chat('What is a rickroll?');

Great question. No, we don't support introspection of that kind automatically (although maybe we should, eventually? might be a way to do it if you extend an abstract class.... hmm.)

I would expose the config options you want to expose inside Chat.ts

// Chat.ts

// add the new overload
static with(provider: "ollama", config: any): Chat;

// a few lines below, add your case statement
case "ollama":
    adapter = provideOllamaChatAdapter({ config });
    break;

And then you can add a simple test to ensure it instantiates, in Chat.test.ts

// Chat.test.ts
it('can instantiate ollama', () => {
  const c = Chat.with('ollama', {
       // ...
  });
})
monarchwadia commented 2 months ago

Sent you an email to the same effect, but thought I should also leave a message here: Please let me know if you need help. This is such great work :-)

markwylde commented 2 months ago

Ahh nice one @monarchwadia. I'll get that added to the config today.

monarchwadia commented 2 months ago

Thanks for the great work, @markwylde ! I've merged into dev branch, will check out the issue above & merge + push soon