fruitbars / simple-one-api

OpenAI 接口接入适配,支持千帆大模型平台、讯飞星火大模型、腾讯混元以及MiniMax、Deep-Seek,等兼容OpenAI接口,仅单可执行文件,配置超级简单,一键部署,开箱即用. Seamlessly integrate with OpenAI and compatible APIs using a single executable for quick setup and deployment.
MIT License
1.38k stars 121 forks source link

对外API怎么使用,文档中没有找到 #61

Closed lopins closed 3 months ago

lopins commented 3 months ago
from openai import OpenAI

client = OpenAI(
    api_key="apikey",
    base_url="http://127.0.0.1:9090/v1"
)

completion = client.chat.completions.create(
    model="glm-4",
    messages=[
        {"role": "system", "content": "你是一个聪明且富有创造力的小说作家"},
        {"role": "user",
         "content": "请你作为童话故事大王,写一篇短篇童话故事,故事的主题是要永远保持一颗善良的心,要能够激发儿童的学习兴趣和想象力,同时也能够帮助儿童更好地理解和接受故事中所蕴含的道理和价值观。"}
    ],
    top_p=0.7,
    temperature=0.9
)

print(completion.choices[0].message)

apikey这个参数?

lopins commented 3 months ago
from openai import OpenAI

client = OpenAI(
    api_key="apikey",
    base_url="http://127.0.0.1:9090/v1"
)

completion = client.chat.completions.create(
    model="glm-4",
    messages=[
        {"role": "system", "content": "你是一个聪明且富有创造力的小说作家"},
        {"role": "user",
         "content": "请你作为童话故事大王,写一篇短篇童话故事,故事的主题是要永远保持一颗善良的心,要能够激发儿童的学习兴趣和想象力,同时也能够帮助儿童更好地理解和接受故事中所蕴含的道理和价值观。"}
    ],
    top_p=0.7,
    temperature=0.9
)

print(completion.choices[0].message)

apikey这个参数?

image

https://github.com/fruitbars/simple-one-api/blob/125f0bd86405cdb7e593cb0ee70ba6dac0ea4593/README.md?plain=1#L85

fruitbars commented 3 months ago

支持api_key(单个)和api_keys(多个,并且支持设定可以调用哪些模型)

参考文档《2.7 api_keys和api_key字段详解》

https://rsxlecz746.feishu.cn/wiki/Tr8nwkkvii3DJrkCpjQcmReAndV

lopins commented 3 months ago

支持api_key(单个)和api_keys(多个,并且支持设定可以调用哪些模型)

参考文档《2.7 api_keys和api_key字段详解》

https://rsxlecz746.feishu.cn/wiki/Tr8nwkkvii3DJrkCpjQcmReAndV

api_key字符串的格式有要求吗,proxy配置和api_keys配置是否支持"enabled": true 控制字段:

  "proxy": {
    "strategy": "default",
    "type": "http",
    "http_proxy": "http://proxy.example.com:8080",
    "https_proxy": "http://proxy.example.com:8443",
    "socks5_proxy": "",
    "timeout": 30
  },
  "api_keys": [
    {
      "api_key": "key1",
      "supported_models": {
        "service1": ["model1", "model2"],
        "service2": ["*"]
      }
    },
    {
      "api_key": "key2",
      "supported_models": {
        "service1": ["model3"],
        "service3": ["model4", "model5"]
      }
    }
  ],
fruitbars commented 3 months ago

针对某个api_key的开关目前还没有哈

lopins commented 3 months ago

针对某个api_key的开关目前还没有哈

好的