upgrade openai chunked streaming
new file: .dockerignore modified: .gitignore modified: app.py new file: docker-compose.yml
This commit is contained in:
parent
edad9d46c7
commit
7f9432ea9f
4 changed files with 23 additions and 9 deletions
1
.dockerignore
Normal file
1
.dockerignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
instance/
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ env
|
|||
instance/
|
||||
__pycache__/
|
||||
.flaskenv
|
||||
.flaskenv-exported
|
||||
|
|
|
|||
17
app.py
17
app.py
|
|
@ -3,7 +3,9 @@ from flask_socketio import SocketIO, emit, join_room
|
|||
|
||||
import eventlet
|
||||
|
||||
import openai
|
||||
from openai import OpenAI
|
||||
|
||||
openai_client = OpenAI()
|
||||
|
||||
import os
|
||||
|
||||
|
|
@ -370,13 +372,10 @@ def chat_gpt(username, room_name, message, model_name="gpt-3.5-turbo"):
|
|||
msg_id = new_message.id
|
||||
|
||||
first_chunk = True
|
||||
for chunk in openai.ChatCompletion.create(
|
||||
model=model_name,
|
||||
messages=chat_history,
|
||||
temperature=0,
|
||||
stream=True,
|
||||
for chunk in openai_client.chat.completions.create(
|
||||
model=model_name, messages=chat_history, temperature=0, stream=True
|
||||
):
|
||||
content = chunk["choices"][0].get("delta", {}).get("content")
|
||||
content = chunk.choices[0].delta.content
|
||||
|
||||
if content:
|
||||
buffer += content # Accumulate content
|
||||
|
|
@ -442,10 +441,10 @@ def gpt_generate_room_title(messages, model_name):
|
|||
|
||||
# Interaction with LLM to generate summary
|
||||
# For example, using OpenAI's GPT model
|
||||
response = openai.ChatCompletion.create(
|
||||
response = openai_client.chat.completions.create(
|
||||
messages=chat_history,
|
||||
model=model_name, # or any appropriate model
|
||||
max_tokens=20, # Adjust as needed
|
||||
max_tokens=20,
|
||||
)
|
||||
|
||||
title = response.choices[0]["message"]["content"]
|
||||
|
|
|
|||
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
flask-app:
|
||||
build: .
|
||||
ports:
|
||||
- "5001:5001"
|
||||
volumes:
|
||||
- ./instance:/opt/server/instance
|
||||
env_file:
|
||||
- .flaskenv
|
||||
environment:
|
||||
- PYTHONPATH=/opt
|
||||
Loading…
Add table
Add a link
Reference in a new issue