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

相关推荐
汤姆小白24 分钟前
01-环境搭建与项目导览
人工智能·python·机器学习·numpy
向日的葵0066 小时前
langchain的Tools教程(三)
python·langchain·tools
言乐68 小时前
Python实现可运行解密游戏游戏框架
python·游戏·小程序·游戏程序·关卡设计
YUS云生8 小时前
Python学习笔记·第31天:FastAPI入门——路由、路径参数、查询参数与请求体
笔记·python·学习
智写-AI9 小时前
真实有效的免费降英文AI工具服务商
人工智能·python
yuhuofei20219 小时前
【Python入门】了解掌握Python中函数的基本使用
python
白帽小阳10 小时前
2026前端面试题!(附答案及解析)
javascript·网络·python·安全·web安全·网络安全·护网行动
乱写代码11 小时前
Python开发技巧--类型注解Literal
python
卷无止境11 小时前
Python FFI 技术深度解析:ctypes、cffi 与 pybind11 的性能差异与实践挑战
后端·python