sugarforever / chat-ollama

ChatOllama is an open source chatbot based on LLMs. It supports a wide range of language models, and knowledge base management.
MIT License
2.66k stars 416 forks source link

模型名称可调整为通过 API key 实时获取吗? #453

Open WanQuanXie opened 6 months ago

WanQuanXie commented 6 months ago

如题。现在基本都是硬编码写死的,感觉不是很灵活,类似 OpenAI 的模型未开通 plus 的话其实是用不了 4 的模型的,但由于硬编码的缘故,只要配置 API key,都会固定列出那几个模型。

satrong commented 6 months ago

据我目前所知没有获取模型的 api

WanQuanXie commented 6 months ago

据我目前所知没有获取模型的 api

OpenAI list model endport

https://platform.openai.com/docs/api-reference/models

Example request

curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

Response

{
  "object": "list",
  "data": [
    {
      "id": "model-id-0",
      "object": "model",
      "created": 1686935002,
      "owned_by": "organization-owner"
    },
    {
      "id": "model-id-1",
      "object": "model",
      "created": 1686935002,
      "owned_by": "organization-owner",
    },
    {
      "id": "model-id-2",
      "object": "model",
      "created": 1686935002,
      "owned_by": "openai"
    },
  ],
  "object": "list"
}

Groq

https://console.groq.com/docs/models

Javascript Example

const Groq = require("groq-sdk");
const groq = new Groq({
    apiKey: process.env.GROQ_API_KEY
});
const getModels = async ()=>{
    return await groq.models.list();
};
getModels().then((models)=>{
// console.log(models);
});

Gemini

https://ai.google.dev/api/rest/v1/models/list?hl=zh-cn

REST Endpoint

GET https://generativelanguage.googleapis.com/v1/models

Response

{
  "models": [
    {
      object ([Model](https://ai.google.dev/api/rest/v1/models?hl=zh-cn#Model))
    }
  ],
  "nextPageToken": string
}

Moonshot

https://platform.moonshot.cn/docs/api/chat#list-models

Endpoint

GET https://api.moonshot.cn/v1/models

Example

const OpenAI = require("openai");

const client = new OpenAI({
    apiKey: "$MOONSHOT_API_KEY",
    baseURL: "https://api.moonshot.cn/v1",
});

async function main() {
    const model_list = await client.models.list();
    for await (const model of model_list)
        console.log(model.id)
}
main();
satrong commented 6 months ago

感谢,可以规划一下

xiaolvtongxue-zt commented 5 months ago

@satrong

感谢,可以规划一下 你好。貌似这个需求好像没有得到更新。目前镜像还是硬编码。写死的。

sugarforever commented 5 months ago

@WanQuanXie 感谢分享。初始设计中硬编码的原因是简化代码,同时提高功能的执行效率。动态获取模型的好处是更精确地提供模型列表。

David-Zeng commented 3 months ago

动态获取模型列表应该是一个重要的功能。比如我现在使用的Deepinfra OpenAI compatiable API里面有很多其他的模型,比如llama 3.1。目前只能使用hardcoded的模型

satrong commented 3 months ago

@David-Zeng 可以使用自定义服务,自定义服务中可以自己自定义模型名