題意:
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
文件,內容類似于:
--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中模型列表的代碼
import requestsurl = "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:????????輸出應該看起來像這樣:
{'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:????????但我得到了這個:
{'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
中啟用它并輸入:
--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:???????代碼應該像這樣:
import requestsapi_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())