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小工具win7翻车事故现场
python
岁月宁静6 小时前
从零拆解 AI 语音模拟面试系统
人工智能·python·agent
benchmark_cc6 小时前
个人开发者接入五档盘口:用 QuantDash 读取单只股票的验收清单与易错点
python·数据分析·pandas·量化交易·股票数据·quantdash
ZhengEnCi7 小时前
项目越写越乱?先别改架构:用一次目录重排 + 一份可复算的体检脚本把乱治住
python·架构·ai编程
Dmz丶8 小时前
前端转 AI 100 天 Day 45:阶段复盘——从“会调 API”到“做出 AI 产品”
python
Sakura_j_h_8 小时前
MCP SDK 2.0 实战:用 MCPServer 搭本地笔记检索服务
开发语言·笔记·python·qt·ai工具·mcp·mcpserver
QuZhengRong9 小时前
【AI】Agent 全栈进阶|AgentScope 沙箱源码解析
python·学习·ai·agent·沙箱
Eider19989 小时前
Python基础语法之并发相关3
开发语言·python
M--Y10 小时前
LangGraph 架构基石:持久化与运行控制
python·langchain·大模型·llm·持久化·langgraph
用户0190275816111 小时前
新浪财经 / 东方财富股票接口不稳、被限?稳定替代方案
python