OpenAI API测试

一、启用大模型服务

复制代码
nohup ./llama-server -m models/Qwen2-0.5B-Instruct/Qwen2-0.5B-Instruct-F16.gguf --host 0.0.0.0 --port 2001 > log.txt 2>&1 &

二、openai调用

复制代码
from openai import OpenAI

client = OpenAI(api_key='xx', base_url='http://localhost:2001/v1')
completion = client.chat.completions.create(
                model='qwen2',
                messages=[{'role': 'user', 'content': '为什么天空是蓝色的'}],
                stream=False
            )
print(completion.choices[-1].message.content)

三、性能测试

复制代码
import time
for i in range(5):
    start_time = time.time()
    text = test_ollama()
    end_time = time.time()
    print(f"第{i+1}次调用:{end_time-start_time}秒, token/s:{len(text)/(end_time-start_time)}")

参考链接:

1、https://mp.weixin.qq.com/s/majDONtuAUzN2SAaYWxH1Q

2、https://mp.weixin.qq.com/s/YuTHDfEzK8wV33Bifubc5A

3、https://mp.weixin.qq.com/s/9hUkDiEVM6mehkaHxU6VVw

相关推荐
vicky051722 分钟前
解决 ModuleNotFoundError: No module named ‘torch‘ 笔记
python
wuyk55527 分钟前
Python实战项目02:学生成绩管理系统(控制台|CSV导出|完整落地)
开发语言·python
qq5918406857 小时前
uiautomator2自动化安卓手机操作
python
80s7777 小时前
动态代理和静态代理的区别,动态代理怎么提高网络安全性
python
niucloud-admin9 小时前
JAVA V6 多商户商城 开发文档——job 计划任务开发
java·python·github
小叶肥辉9 小时前
LangChain链和LangGraph图的学习笔记【三】——分别用langchain_openai库和langchain_community库调用大模型
笔记·python·langchain
2401_8734794010 小时前
IP属地为什么有时显示外省?用IP查询工具核查动态分配、运营商出口与GeoIP库
python·tcp/ip·ip
OKkankan12 小时前
LangChain 能力详解!:输出解析、RAG、向量数据库与 Retriever 检索器
数据结构·python·langchain·ai应用
山哥ol12 小时前
【Geany 环境配置与中文乱码解决参考】
python
会飞锦鲤13 小时前
基于 Mask R-CNN 的药片缺陷检测系统
人工智能·pytorch·python·神经网络·resnet-50