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

相关推荐
路边草随风18 分钟前
python 调用 spring ai sse mcp
人工智能·python·spring
Dr.Kun1 小时前
【鲲码园Python】基于pytorch的鸟品种分类系统(25类)
pytorch·python·分类
是有头发的程序猿1 小时前
Python爬虫实战:面向对象编程在淘宝商品数据抓取中的应用
开发语言·爬虫·python
萑澈1 小时前
Windows系统Anaconda/Miniconda的安装、配置、基础使用、清理缓存空间和Pycharm/VSCode配置指南
python
Onebound_Ed2 小时前
Python爬虫进阶:面向对象设计构建高可维护的1688商品数据采集系统
开发语言·爬虫·python
阿蔹2 小时前
JavaWeb-Selenium 配置以及Selenim classnotfound问题解决
java·软件测试·python·selenium·测试工具·自动化
万粉变现经纪人2 小时前
如何解决 pip install 代理报错 407 Proxy Authentication Required 问题
windows·python·pycharm·beautifulsoup·bug·pandas·pip
李剑一3 小时前
Python学习笔记3
python
luod3 小时前
Python包
python
Mr Lee_3 小时前
Smali 文件生成dex装箱算法整合
开发语言·python·算法