怎样在Python中使用oobabooga的API密钥,通过端口5000获取模型列表的授权

题意:

oobabooga-textgen-web-ui how to get authorization to view model list from port 5000 via the ooba's api-key in python

怎样在Python中使用oobabooga的API密钥,通过端口5000获取模型列表的授权

问题背景:

I wish to extract and print out a list of llm models from the oobabooga-text-gen-web-ui in python.

我希望从Python中的oobabooga-text-gen-web-ui中提取并打印出一系列LLM(大型语言模型)的列表

Some context first before i head over to my problem.

在我描述我的问题之前,先提供一些背景信息。

For those familiar with what ooba is its essentially a Gradio web UI for Large Language Models.

对于那些熟悉ooba的人来说,它本质上是一个为大型语言模型(Large Language Models)设计的Gradio网络用户界面。

I downloaded and loaded a few llm models onto this web ui. The web ui uses http://127.0.0.1:7860/ to display the web user interface on port 7860. But if I enable the openai and api extensions, and also edit the CMD_FLAGS.txt within the ooba folder into something like:

我下载并在这个网络用户界面上加载了几个大型语言模型(LLM)。该网络用户界面使用 http://127.0.0.1:7860/ 在7860端口上显示用户界面。但是,如果我启用了openai和api扩展,并且在ooba文件夹内编辑CMD_FLAGS.txt文件,内容类似于:

python 复制代码
--listen --api --api-key "enter-your-fake-api-key-here" 

the extensions will mimic an Open AI api key by connecting to ooba from a network via port 5000

这些扩展将通过端口5000从网络连接到ooba,从而模拟一个OpenAI API密钥。

Here come the problem... 问题出现了

this is my code to view the model list from ooba : 以下是我用来查看ooba中模型列表的代码

python 复制代码
import requests

url = "http://127.0.0.1:5000/v1"

#Model List
headers = {
    "Content-Type": "application/json"
}

response = requests.get(f'{url}/internal/model/list',
                        headers=headers,
                        verify=False)
print(response.json())

the output should look something like this: 输出应该看起来像这样:

python 复制代码
{'model_names': ['L3-8B-Stheno-v3.2', 'L3-8B-Stheno-v3.2_exl2_8h_8bpw', 'L3-8B-Stheno-v3.2_q8_0.gguf', 'MixTAO-7Bx2-MoE-v8.1_q8_0.gguf']}

but instead i got this: 但我得到了这个:

python 复制代码
{'detail': 'Unauthorized'}

After some fiddling around I found that if I leave CMD_FLAGS.txt blank the code works as intended and i get the model lists but i dont have access to an API key since its not enable on ooba.

经过一些尝试后,我发现如果我将CMD_FLAGS.txt文件留空,代码就能按预期工作,我可以获取到模型列表。但是,由于我没有在ooba上启用API密钥功能,因此我无法访问API密钥。

if I do enable it with CMD_FLAGS.txt and typing: 如果我在CMD_FLAGS.txt中启用它并输入:

python 复制代码
--listen --api --api-key "enter-your-fake-api-key-here" 

I'll have access to the openai api key but the code to extract the model list will return as : {'detail': 'Unauthorized'}

我将能够访问OpenAI的API密钥,但是用于提取模型列表的代码将返回:{'detail': 'Unauthorized'}

I need the api key enabled from ooba cuz i plan to use the openai.client feature for model interactions. How do I keep the configuration that enables the fake open ai api key but also allows me to extract the model list?

我需要从ooba启用API密钥,因为我计划使用openai.client功能来进行模型交互。我如何保持这种配置,即启用模拟的OpenAI API密钥,同时又能提取模型列表?

问题解决:

1 day later... Found the answer. Turns out if i want the api key to be enabled while also being able to view the model list from ooba via the api, I need to add an 'Authorization': f'Bearer {api_key}' in the header.

一天后...我找到了答案。原来,如果我想在启用API密钥的同时,也能够通过API从ooba查看模型列表,我需要在请求头中添加'Authorization': f'Bearer {api_key}'

The code should look something like this: 代码应该像这样:

python 复制代码
import requests

api_key = "enter-your-fake-api-key-here"
url = "http://127.0.0.1:5000/v1"

#Model List
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

response = requests.get(f'{url}/internal/model/list',
                        headers=headers,
                        verify=False)
print(response.json())
复制代码
相关推荐
hakesashou7 分钟前
python如何比较字符串
linux·开发语言·python
Elastic 中国社区官方博客34 分钟前
Elasticsearch:使用 LLM 实现传统搜索自动化
大数据·人工智能·elasticsearch·搜索引擎·ai·自动化·全文检索
_.Switch44 分钟前
Python机器学习模型的部署与维护:版本管理、监控与更新策略
开发语言·人工智能·python·算法·机器学习
Hoper.J1 小时前
PyTorch 模型保存与加载的三种常用方式
人工智能·pytorch·python
弱冠少年2 小时前
websockets库使用(基于Python)
开发语言·python·numpy
技术无疆2 小时前
【Python】Streamlit:为数据科学与机器学习打造的简易应用框架
开发语言·人工智能·python·深度学习·神经网络·机器学习·数据挖掘
羊小猪~~2 小时前
机器学习/数据分析--用通俗语言讲解时间序列自回归(AR)模型,并用其预测天气,拟合度98%+
人工智能·python·机器学习·数据挖掘·数据分析·回归·时序数据库
qq_273900232 小时前
解析TMalign文本文件中的转换矩阵
python·生物信息学
网安-搬运工3 小时前
RAG再总结之如何使大模型更好使用外部数据:四个不同层级及查询-文档对齐策略
人工智能·自然语言处理·大模型·llm·大语言模型·ai大模型·rag
大模型八哥3 小时前
大模型扫盲系列——大模型实用技术介绍(上)
人工智能·程序人生·ai·大模型·llm·llama·ai大模型