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

相关推荐
金銀銅鐵4 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup119 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0011 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵12 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf13 小时前
Agent 流程编排
后端·python·agent
copyer_xyf14 小时前
Agent RAG
后端·python·agent
copyer_xyf14 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf14 小时前
Agent 记忆管理
后端·python·agent
星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程
python