尝试一下
2025年2月22日大约 2 分钟
尝试一下
一旦安装了LocalAI,你可以通过使用docker、cli或systemd服务来启动它。
默认情况下,LocalAI WebUI应该可以通过http://localhost:8080访问。你也可以使用第三方项目与LocalAI交互,就像使用OpenAI一样(也 see [Integrations])。
安装后,通过导航模型画廊或使用local-ai
CLI安装新模型。
你也可以通过复制文件到models
目录来[手动运行模型]。
文本生成
为给定的聊天对话创建模型响应。OpenAI文档。
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{ "model": "gpt-4", "messages": [{"role": "user", "content": "How are you doing?", "temperature": 0.1}] }'
GPT Vision
理解图像。
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4-vision-preview",
"messages": [
{
"role": "user", "content": [
{"type":"text", "text": "What is in the image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
}
}
],
"temperature": 0.9
}
]
}'
函数调用
调用函数
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'
图像生成
根据提示创建图像。OpenAI文档。
curl http://localhost:8080/v1/images/generations \
-H "Content-Type: application/json" -d '{
"prompt": "A cute baby sea otter",
"size": "256x256"
}'
文本转语音
从输入文本生成音频。OpenAI文档。
curl http://localhost:8080/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output speech.mp3
转录音频
将音频转录为输入语言。OpenAI文档。
首先下载一个样本进行转录:
wget --quiet --show-progress -O gb1.ogg https://upload.wikimedia.org/wikipedia/commons/1/1f/George_W_Bush_Columbia_FINAL.ogg
将示例音频文件发送到转录端点:
curl http://localhost:8080/v1/audio/transcriptions \
-H "Content-Type: multipart/form-data" \
-F file="@$PWD/gb1.ogg" -F model="whisper-1"
嵌入生成
获取给定输入的向量表示,以便机器学习模型和算法轻松使用。OpenAI嵌入。
curl http://localhost:8080/embeddings \
-X POST -H "Content-Type: application/json" \
-d '{
"input": "Your text string goes here",
"model": "text-embedding-ada-002"
}'
不要在请求中使用模型文件作为model
,除非你想自己处理提示模板。
使用模型名称,就像在下面的例子中那样使用OpenAI,例如gpt-4-vision-preview
,或gpt-4
。