您现在的位置是:网站首页> AI人工智能
AI人工智能应用编程
- AI人工智能
- 2025-02-13
- 1225人已阅读
AI人工智能应用编程
Dify 一个开源 LLM 应用开发平台【与coze对标】,点击查看扣子教程
喂饭教程!15分钟用Dify搭建基于智能体的聊天式数据查询应用
Stability Matrix,一款开源免费的,多平台,多模型,多WebUI的管理神器
GPT-4 All 免费开源!本地部署,无需GPU、可离线使用
LiblibAI客户端,内嵌哩布模型社区,集成WebUI和 ComfyUI两大启动器,简单好用的生图工具
***打包AI项目,打包CUDA,打包CUDNN,打包TensorRT,打包FFMPEG,AI项目整合包制作***
在Windows下,Python程序可以通过设置环境变量来临时指定使用特定的CUDA和cuDNN版本。
一键Python程序打包成EXE🟢通用脚本,适配Github各种AI项目
【ChatGPT+Quivr】快速部署本地AI知识库|私人定制
手把手带您三步骤轻松搞定ChatGPT模型训练,轻松拥有一个自己定制的ChatGPT模型
开源!如何把stable diffusion变成商用软件?教你正确的调用stable diffusion api!
LangChain 是一个为各种大型语言模型应用提供通用接口的框架
Coze与Dify知识库问答对比 | 国产AI应用开发平台扣子能遥遥领先吗
Dify 一个开源 LLM 应用开发平台
***第一次使用记得登录后点击头像选设置->模型供应商->配置好模型才能使用***
Dify 是一个开源 LLM 应用开发平台。Dify 的直观界面结合了 AI 工作流、RAG 管道、代理功能、模型管理、可观察性功能等,让您可以快速从原型转向生产
喂饭教程!15分钟用Dify搭建基于智能体的聊天式数据查询应用
Stability Matrix,一款开源免费的,多平台,多模型,多WebUI的管理神器
注意设置git的代理(安装模块需要git)
设置与取消git的代理
git config --global http.proxy http://127.0.0.1:10809
git config –global –unset http.proxy
GPT-4 All 免费开源!本地部署,无需GPU、可离线使用
GPT-4 ALL 安装包+本地模型下载:https://www.freedidi.com/11195.html
简化 AI 项目管理平台AIStarter
AIStarter是一款免费的AI项目管理平台,旨在让用户能够在Windows、Mac或Linux上快速轻松地下载、安装和分享各类热门AI开源项目。
***Stable Diffusion API 文档***
查看自己的SD接口文档:http://127.0.0.1:7860/docs
运行API服务:webui.bat --nowebui
cd stable-diffusion-webui
python launch.py --nowebui --xformers --opt-split-attention --listen --port 7862
命令描述
--nowebui 以 API 模式启动。
--xformers 改善内存消耗和速度。
--opt-split-attention Cross attention layer optimization 优化显着减少了内存使用。
--listen 默认启动绑定的 IP 是 127.0.0.1。
--port 默认端口是7860,可以配置并修改该参数,例如:--port 7862。
--gradio-auth username:password如果希望给 WebUI 设置登录密码,可以配置该参数,例如:--gradio-auth GitLqr:123456。
启动 StableDiffusion API 接口使用指南
配置完成后,在浏览器地址栏输入服务器 IP 地址:端口号/docs 可查看相关的 API 接口使用指南。
官方提供的常用 API 如下:
/sdapi/v1/txt2img文字生图 POST
/sdapi/v1/img2img图片生图 POST
/sdapi/v1/options获取设置 GET | 更新设置 POST(可用来更新远端的模型)
/sdapi/v1/sd-models获取所有的模型 GET
Stable Diffusion v3.0 api使用教程
今天Stable Diffusion v3.0的api终于可以使用, 效果真的出奇的好.
我这里测试了下给予Python环境的调用, 效果也是非常的好.
第一步, 注册API Key
如果想使用Stable Diffusion v3.0的API, 就要先注册并生成一个秘钥, 网址如下:
https://platform.stability.ai/account/keys
在下面的界面中点击"Create API Key"按钮, 就会生成红色框中的API Key, 然后点击蓝色框中复制按钮, 就可以保存下来.
第二步, 运行代码
import requests
response = requests.post(
f"https://api.stability.ai/v2beta/stable-image/generate/sd3",
headers={
"authorization": f"Bearer Your API Key",
"accept": "image/*"
},
files={"none": ''},
data={
"prompt": "An blue ship with golden wings",
"output_format": "jpeg",
},
)
if response.status_code == 200:
with open("./blue_ship_with_golden_wings.jpeg", 'wb') as file:
file.write(response.content)
else:
raise Exception(str(response.json()))
from PIL import Image
input_image = Image.open("./blue_ship_with_golden_wings.jpeg").convert("RGB")
display(input_image)
AI助手
将上面的"Your API Key"替换为你刚才生成的, 然后自定义prompt字段就可以生成你的图像
CUDA与cuDNN如何实现复制使用
CUDA和cuDNN的复制使用通常指的是将这些库从一个已经安装好的环境复制到另一个环境,以避免在新环境中重新安装。以下是实现复制使用的步骤:
确定CUDA和cuDNN的版本:
首先,确保你知道源环境中CUDA和cuDNN的版本。可以通过命令行输入nvcc --version来查看CUDA版本,cuDNN版本通常不直接显示,但可以通过查看cuDNN库文件的属性来获取。
复制CUDA文件夹:
在源环境中,找到CUDA的安装目录(通常是C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y,其中X.Y是版本号)。
将整个CUDA目录复制到目标机器的相应位置。
复制cuDNN文件:
在源环境中,找到cuDNN的文件,这些通常位于CUDA目录下的bin、include和lib\x64(或相应架构目录)中。
将这些文件复制到目标机器的CUDA对应目录中。
设置环境变量:
在目标机器上,设置环境变量以指向复制过来的CUDA和cuDNN目录。通常需要添加CUDA的bin目录到系统的PATH环境变量中。
验证安装:
在目标机器上打开命令行窗口,输入nvcc --version来验证CUDA Toolkit是否被正确识别。
输入nvidia-smi来检查GPU是否被系统识别,这虽然不直接验证cuDNN,但可以确保GPU驱动和CUDA Toolkit工作正常。
解决可能的兼容性问题:
如果目标机器的显卡驱动与复制的CUDA版本不兼容,可能需要更新或降级显卡驱动。
确保cuDNN版本与CUDA Toolkit版本兼容。
测试深度学习框架:
如果您使用深度学习框架(如TensorFlow或PyTorch),在目标机器上安装这些框架,并确保它们能够找到并使用复制的CUDA和cuDNN。
请注意,这种方法适用于CUDA和cuDNN的某些版本,但并不保证在所有情况下都能成功,特别是如果存在版本不兼容或系统环境差异时。如果可能,建议在每个目标机器上进行干净的安装,以避免潜在的问题。
在Windows下,Python程序可以通过设置环境变量来临时指定使用特定的CUDA和cuDNN版本。
在Windows下,Python程序可以通过设置环境变量来临时指定使用特定的CUDA和cuDNN版本。以下是一些步骤和方法:
设置CUDA环境变量:
打开命令行工具(如CMD或PowerShell)。
临时设置环境变量,可以通过以下命令来指定CUDA的路径:
shell
set CUDA_HOME=C:\path\to\your\cuda
set PATH=%CUDA_HOME%\bin;%PATH%
将C:\path\to\your\cuda替换为实际的CUDA安装目录。
设置cuDNN环境变量:
同样在命令行中,设置cuDNN的环境变量:
shell
set CUDNN_PATH=C:\path\to\your\cudnn
set PATH=%CUDNN_PATH%\bin;%PATH%
将C:\path\to\your\cudnn替换为实际的cuDNN解压目录。
使用Python环境:
在同一命令行窗口中,激活你的Python环境(如果使用虚拟环境):
shell
.\path\to\your\venv\Scripts\activate
替换path\to\your\venv为你的Python虚拟环境路径。
安装或使用深度学习框架:
确保你的深度学习框架(如TensorFlow或PyTorch)已经安装在当前激活的环境中,并且它们将使用新设置的环境变量。
运行Python脚本:
运行你的Python脚本或程序,它将使用指定的CUDA和cuDNN版本。
临时性:
请注意,这些环境变量的设置是临时的,只对当前打开的命令行窗口有效。一旦关闭窗口,设置将不再有效。
使用深度学习框架的API:
某些深度学习框架允许你通过代码来指定CUDA和cuDNN。例如,在TensorFlow中,你可以在程序开始时设置:
python
import os
os.environ['CUDA_HOME'] = 'C:\\path\\to\\your\\cuda'
os.environ['PATH'] += ';C:\\path\\to\\your\\cuda\\bin'
这种方法可以在Python脚本中直接设置环境变量。
通过上述步骤,你可以在Windows下临时指定Python程序使用的CUDA和cuDNN版本。这对于测试不同版本的CUDA和cuDNN或在没有管理员权限的情况下进行开发非常有用。
【ChatGPT+Quivr】快速部署本地AI知识库|私人定制
手把手带您三步骤轻松搞定ChatGPT模型训练,轻松拥有一个自己定制的ChatGPT模型
手把手带您三步骤轻松搞定ChatGPT模型训练,轻松拥有一个自己定制的ChatGPT模型。
ChatGPT模型训练介绍:
https://platform.openai.com/docs/guides/fine-tuning
数据格式说明:
https://platform.openai.com/docs/api-...
测试代码:
---
how to fine-tune ChatGPT mode
import os
import openai
def set_api_key():
set you openapi key
openai.api_key = "sk-YOUR-OPENAI-KEY-HERE"
def dataset_upload():
set_api_key()
result = openai.File.create(
file=open("path-to-your-local/dataset.jsonl", "rb"),
purpose='fine-tune'
)
print(result)
def tune_now(uploaded_file_id):
set_api_key()
result = openai.FineTuningJob.create(training_file=uploaded_file_id, model="gpt-3.5-turbo")
print(result)
def chat_with_yx_model(model_id):
set_api_key()
completion = openai.ChatCompletion.create(
model=model_id,
messages=[
{"role": "system",
"content": "Marv is mental healthy expert"},
{"role": "user", "content": "Who does mental illness affect?"}
]
)
print(completion)
main
if _name_ == '__main__':
step 1 : upload training dataset
dataset_upload()
step 2 : begin fine-tune ChatGPT model
tune_now("file-B9UjNJwHqVU1cBu1mZraLw1q")
step 3 : use my trained model
chat_with_yx_model("ft:gpt-3.5-turbo-0613:personal::84NbaCOS" )
---
训练数据样例:
如下数据保存到你本地命名为:dataset.jsonl
---
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "What does it mean to have a mental illness?"}, {"role": "assistant", "content": "Mental illnesses fall along a continuum of severity: some are fairly mild and only interfere with some aspects of life, such as certain phobias."}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "Who does mental illness affect?"}, {"role": "assistant", "content": "It is estimated that mental illness affects 1 in 5 adults in America, and that 1 in 24 adults have a serious mental illness. "}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "What causes mental illness?"},{"role": "assistant", "content": "Symptoms of mental health disorders vary depending on the type and severity of the condition. "}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "What are some of the warning signs of mental illness?"},{"role": "assistant", "content": "When healing from mental illness, early identification and treatment are of vital importance. Based on the nature of the illness, there are a range of effective treatments available. For any type of treatment, it is essential that the person affected is proactive and fully engaged in their own recovery process."}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "Can people with mental illness recover?"},{"role": "assistant", "content": "Vaping is the term for using a device where liquids, often flavoured, are turned into vapour (hence, vaping) and inhaled. A vaping device consists of a mouthpiece, tank or reservoir to hold the liquid, a heating element and a battery to power the element. "}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "What should I do if I know someone who appears to have the symptoms of a mental disorder?"},{"role": "assistant", "content": "It’s much more than sadness or low mood. People who experience depression may feel worthless or hopeless. They may feel unreasonable guilty. Some people may experience depression as anger or irritability."}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "How can I find a mental health professional for myself or my child?"},{"role": "assistant", "content": "Dysthymia, now called persistent depressive disorder or PDD, is a mood disorder. It is related depression (major depressive disorder). The difference between the two is in the number of symptoms and the amount of time that they last. S"}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "What treatment options are available?"},{"role": "assistant", "content": "Cyclothymic disorder is a subtype of bipolar disorder. Much like bipolar disorder, the symptoms of cyclothymia include three or more symptoms of hypomania, and five or more symptoms of depression."}]}
{"messages": [{"role": "system", "content": "Marv is mental healthy expert"}, {"role": "user", "content": "If I become involved in treatment, what do I need to know?"},{"role": "assistant", "content": "Rapid cycling means that someone diagnosed with bipolar disorder (or depression) experiences four or more episodes of depression and/or mania in one year. "}]}
2023公认最通俗易懂的【HuggingFace】教程
开源!如何把stable diffusion变成商用软件?教你正确的调用stable diffusion api!
sdwebui-api-manager: https://github.com/nftblackmagic/sdwebui-api-manager
sd-webui-hook-v2: https://github.com/nftblackmagic/sd-webui-hook-v2
stable diffusion webui: https://github.com/AUTOMATIC1111/stable-diffusion-webui
一键Python程序打包成EXE🟢通用脚本,适配Github各种AI项目
本视频文字资源:https://niugee.com/python2exe/
在本视频中,我们将展示如何使用Python脚本将程序打包成EXE文件。这是一个通用的脚本,可以适配各种Github上的AI项目。无论您是初学者还是有经验的开发者,这个教程都会帮助您轻松地将Python程序打包成独立的可执行文件。欢迎来到牛哥AI实验室(NIUGEE AI),让我们一起来探索更多的AI项目吧!
为什么这么做?
打包Python程序为EXE文件的主要好处是可以方便地分享程序,不需要用户安装Python,并且可以自定义图标和保护代码。
用什么打包?
PyInstaller:最常用,支持生成单个文件和窗口应用程序。
安装:pip install pyinstaller
打包:pyinstaller --onefile your_script.py
cx_Freeze:适合复杂项目。
安装:pip install cx_Freeze
编写 setup.py
打包:python setup.py build
Py2exe:适合简单项目,仅支持Windows。
安装:pip install py2exe
编写 setup.py
打包:python setup.py py2exe
Nuitka:适合需要性能优化的项目,将Python代码编译为C++代码。
安装:pip install nuitka
编译:nuitka --follow-imports --standalone your_script.py
总结
选择合适的打包工具根据项目需求和个人偏好决定。每种工具都有其独特的优势。
如何打包?
安装PyInstaller:pip install pyinstaller
使用PyInstaller打包:pyinstaller your_script.py
为什么有错误,怎么办?
Gradio UI 需要手动添加Gradio模块。
修改spec文件,添加:module_collection_mode={'gradio':'py',}
参数调用错误:
确保代码中的路径和参数配置正确。
缺少资源:
检查资源文件是否在正确位置,确保路径和配置正确。
onnxruntime AI模型调用框架
https://github.com/microsoft/onnxruntime
LangChain 是一个为各种大型语言模型应用提供通用接口的框架
理解 Agent 和 Chain
Chain
在 LangChain 中,Chain 是指一系列按顺序执行的任务或操作,这些任务通常涉及与语言模型的交互。Chain 可以看作是处理输入、执行一系列决策和操作,最终产生输出的流程。Chain 的复杂性可以从简单的单一提示(prompt)和语言模型调用,扩展到涉及多个步骤和决策点的复杂流程。
Agent
Agent 是 LangChain 中更为高级和自主的实体,负责管理和执行 Chain。Agent 可以决定何时、如何以及以何种顺序执行 Chain 中的各个步骤。通常,Agent 基于一组规则或策略来模拟决策过程,能够观察执行结果并根据这些结果调整后续行动。Agent 的引入使得 LangChain 能够构建更为复杂和动态的应用程序,如自动化聊天机器人或个性化问答系统。
示例
Agent:基于某模型实现的问答系统可以视为一个 Agent。
Chain:问答系统根据一个 prompt 给出回答的过程可以看作是一个 Chain,实际回答过程通常涉及多个任务(Chain)依次执行。
简单顺序链示例
from langchain import Chain, Agent
# 定义一个简单的 Chain
simple_chain = Chain([
{"task": "获取用户输入"},
{"task": "处理输入"},
{"task": "生成回答"}
])
# 定义一个 Agent
simple_agent = Agent(chain=simple_chain)
# 执行 Agent
response = simple_agent.execute()
print(response)
Coze与Dify知识库问答对比 | 国产AI应用开发平台扣子能遥遥领先吗
https://github.com/langgenius/dify
手把手教你FastGPT本地快速搭建部署
AI Agent开发相关
AI Agent全套教学
上一篇:人工智能应用学习笔记
下一篇:AI硬件