upgrade openai chunked streaming

new file:   .dockerignore
	modified:   .gitignore
	modified:   app.py
	new file:   docker-compose.yml
This commit is contained in:
Russell Ballestrini 2023-12-02 13:46:50 -05:00
parent edad9d46c7
commit 7f9432ea9f
4 changed files with 23 additions and 9 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
instance/

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ env
instance/
__pycache__/
.flaskenv
.flaskenv-exported

17
app.py
View file

@ -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
View 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