以openai的gpt3 5为例的大模型流式输出实现(原始、Sanic、Flask)- 附免费的key
以openai的gpt3.5为例的大模型流式输出实现(原始、Sanic、Flask)- 附免费的apikey水龙头
type: Post
status: Draft
date: 2024/10/09
📝 原始
import openaiopenai.api_key = 'sk-xxx'
openai.base_url = 'xxx'resp = openai.chat.completions.create(model = 'gpt-3.5-turbo',messages = [{"role":'user', "content": '详细介绍一下内马尔'}],stream = True
)for chunk in resp:# if chunk.choices[0].delta.content:print(chunk.choices[0].delta.content, end='')
🤗 Sanic
import json
from sanic import Sanic, response
import openaiapp = Sanic(__name__)openai.api_key = "sk-xxx"
openai.base_url = "xxx"async def process_large_