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

Not able to integrate Deepseek with the multi modal architecture #733

Open
kulterryan opened this issue Jan 28, 2025 · 3 comments
Open

Not able to integrate Deepseek with the multi modal architecture #733

kulterryan opened this issue Jan 28, 2025 · 3 comments

Comments

@kulterryan
Copy link

I'm getting the following error with trying to integrate deepseek.

Image

index.ts

if (apiIdentifier.startsWith('deepseek')) {
    return wrapLanguageModel({
      model: deepseek('deepseek-chat'),
      middleware: customMiddleware,
    });
  }

models.ts

{
    id: 'deepseek-chat',
    label: 'DeepSeek',
    apiIdentifier: 'deepseek-chat',
    description: 'For deep research and analysis',
  }
@albertpco
Copy link

Try something like the following, keep the models.ts the same:

import { openai } from '@ai-sdk/openai';
import { deepseek } from '@ai-sdk/deepseek';
import { experimental_wrapLanguageModel as wrapLanguageModel, LanguageModelV1 } from 'ai';

import { customMiddleware } from './custom-middleware';

export const customModel = (apiIdentifier: string) => {

const getProvider = (identifier: string): ((id: string) => LanguageModelV1) => {

if (identifier.startsWith('deepseek')) {
  return (id) => deepseek(id) as LanguageModelV1;
}

return (id) => openai(id) as LanguageModelV1;

};

const provider = getProvider(apiIdentifier);

return wrapLanguageModel({
model: provider(apiIdentifier),
middleware: customMiddleware,
});
};

@kulterryan
Copy link
Author

tried the same earlier, but it's not rendering any replies from api other than openai

@YouCaptcha
Copy link

  1. Modify the file:lib/ai/models.ts
export interface Model {
  id: string
  label: string
  apiIdentifier: string
  description: string
}

export const models: Array<Model> = [
  {
    id: "gpt-4o-mini",
    label: "GPT 4o mini",
    apiIdentifier: "gpt-4o-mini",
    description: "Small model for fast, lightweight tasks"
  },
  {
    id: "gpt-4o",
    label: "GPT 4o",
    apiIdentifier: "gpt-4o",
    description: "For complex, multi-step tasks"
  },
  {
    id: "deepseek-chat",
    label: "DeepSeek Chat",
    apiIdentifier: "deepseek-chat",
    description: "For deep research and analysis"
  }
] as const

export const DEFAULT_MODEL_NAME: string = "gpt-4o-mini"
  1. Modify the file:lib/ai/index.ts

Install dependencies first:npm i @ai-sdk/deepseek

import { deepseek } from "@ai-sdk/deepseek"
import { openai } from "@ai-sdk/openai"
import { experimental_wrapLanguageModel as wrapLanguageModel } from "ai"

import { customMiddleware } from "./custom-middleware"

export const customModel = (apiIdentifier: string) => {
  let model

  if (apiIdentifier.startsWith("deepseek")) {
    model = deepseek(apiIdentifier)
  } else if (apiIdentifier.startsWith("openai")) {
    model = openai(apiIdentifier)
  } else {
    throw new Error(`Unsupported model: ${apiIdentifier}`)
  }

  return wrapLanguageModel({
    model: model,
    middleware: customMiddleware
  })
}

export const imageGenerationModel = (apiIdentifier: string) => {
  if (apiIdentifier.startsWith("openai")) {
    return openai.image("dall-e-3")
  } else {
    throw new Error(`Unsupported image generation model: ${apiIdentifier}`)
  }
}

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

3 participants