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

feat: Solve the problem of using openai interface protocol for user-d… #4480

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

Dean-YZG
Copy link
Contributor

@Dean-YZG Dean-YZG commented Apr 9, 2024

…efined claude model & add some famous webdav endpoints

…efined claude model & add some famous webdav endpoints
Copy link

vercel bot commented Apr 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextchat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2024 0:51am

Copy link
Contributor

github-actions bot commented Apr 9, 2024

Your build has completed!

Preview deployment

@Dean-YZG Dean-YZG mentioned this pull request Apr 9, 2024
3 tasks
Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just letting you know

@@ -173,7 +174,7 @@ export function useLoadData() {
var api: ClientApi;
if (config.modelConfig.model.startsWith("gemini")) {
api = new ClientApi(ModelProvider.GeminiPro);
} else if (config.modelConfig.model.startsWith("claude")) {
} else if (identifyDefaultClaudeModel(config.modelConfig.model)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way you can simplicity it by using this method

remove this

  var api: ClientApi;
  if (config.modelConfig.model.startsWith("gemini")) {
    api = new ClientApi(ModelProvider.GeminiPro);
  } else if (identifyDefaultClaudeModel(config.modelConfig.model)) {
    api = new ClientApi(ModelProvider.Claude);
  } else {
    api = new ClientApi(ModelProvider.GPT);
  }

then replace with this

const modelProviderMap: Record<string, ModelProvider> = {
  gemini: ModelProvider.GeminiPro,
  claude: ModelProvider.Claude,
};

const defaultModelProvider = ModelProvider.GPT;
const modelPrefix = config.modelConfig.model.split("-")[0];

const api = new ClientApi(
  modelProviderMap[modelPrefix] || identifyDefaultClaudeModel(config.modelConfig.model)
    ? ModelProvider.Claude
    : defaultModelProvider
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some users invoke the claude model using openai's interface protocol, possibly with a proxy service in between, so the problem I'm actually trying to solve with this code is: Only the default claude model provided by our system (marked anthropic on the corresponding provider) can use the anthropic interface protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, semantically, this code of yours does not solve the problem,but, you mentioned a very important point, that is the importance of "provider", next, the entity relationships will be sorted out, refactoring the logic, making it easier for the application to extend the new model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, semantically, this code of yours does not solve the problem,but, you mentioned a very important point, that is the importance of "provider", next, the entity relationships will be sorted out, refactoring the logic, making it easier for the application to extend the new model

it's looks bad so many if else if else statement, can't imagine if there is lot's of service provider

  var api: ClientApi;
  if (config.modelConfig.model.startsWith("gemini")) {
    api = new ClientApi(ModelProvider.GeminiPro);
  } else if (identifyDefaultClaudeModel(config.modelConfig.model)) {
    api = new ClientApi(ModelProvider.Claude);
  } else {
    api = new ClientApi(ModelProvider.GPT);
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one as well

import { useAccessStore } from "../store/access";
import { useAppConfig } from "../store/config";
import { collectModels } from "./model";

export function identifyDefaultClaudeModel(modelName: string) {
  const accessStore = useAccessStore.getState();
  const configStore = useAppConfig.getState();

  const allModals = collectModels(
    configStore.models,
    [configStore.customModels, accessStore.customModels].join(","),
  );

  const modelMeta = allModals.find((m) => m.name === modelName);

  return (
    modelName.startsWith("claude") &&
    modelMeta &&
    modelMeta.provider?.providerType === "anthropic"
  );
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, semantically, this code of yours does not solve the problem,but, you mentioned a very important point, that is the importance of "provider", next, the entity relationships will be sorted out, refactoring the logic, making it easier for the application to extend the new model

I think you can judge which protocol to use based on the secret key of the AI model, because the secret key formats of different models are different.

@Dean-YZG Dean-YZG merged commit 67acc38 into main Apr 10, 2024
3 checks passed
gaogao1030 pushed a commit to gaogao1030/ChatGPT-Next-Web that referenced this pull request May 16, 2024
feat: Solve the problem of using openai interface protocol for user-d…
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

Successfully merging this pull request may close these issues.

3 participants