Next.js Discord

Discord Forum

Can I add a custom parameter when making a custom AI?

Unanswered
Large garden bumble bee posted this in #help-forum
Open in Discord
Large garden bumble beeOP
This page is exactly what I am trying to leverage, but mine uses a custom AI: https://sdk.vercel.ai/docs/ai-sdk-ui/chatbot
So, I did notice that there is an interface called LanguageModel that I am able to implement and create my own chatbot from. However, there's one problem: in order for me to stream a response, I will have to first make a chat then hand it the chat id
Is it possible to add these custom parameters to the doStream? Let me know if I am doing this wrong

class MyCustomModel implements LanguageModel {
  // ... setup here, don't worry
  public async doStream({ abortSignal, prompt }) {
    const response = await fetch(this.config.url({
      path: `/api/chat/${chat_id}/stream` // <- here is where the problem is
    }), {
      method: 'POST',
    });

    return {
      stream: response.pipeThrough({
        transform(chunk, controller) {
          // whatevah
        }
      }),
    }
  }
}

0 Replies