Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
upgrading openai api
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale committed Nov 16, 2023
1 parent 8df8bcf commit cd07ff8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app
COPY . /app

RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --user Flask Flask_cors PyYAML openai==0.28.1 waitress
pip install --no-cache-dir --user Flask Flask_cors PyYAML openai waitress

# Runtime stage
FROM python:3.9-slim as runtime
Expand Down
26 changes: 13 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from flask import Flask, request, send_file, Response
from flask_cors import CORS
import yaml
import openai
from openai import OpenAI

client = OpenAI()

app = Flask(__name__)
CORS(app) # Enables CORS for all routes
Expand Down Expand Up @@ -112,14 +114,13 @@ def ask_chat_route():
{"role": "user", "content": query},
]

response = openai.ChatCompletion.create(
model="gpt-4",
messages=messages,
)
response = client.chat.completions.create(model="gpt-4",
messages=messages)


response_message = response["choices"][0]["message"]
csv_list = response_message['content']

response_message = response.choices[0].message
csv_list = response_message.content
print("csv_list", csv_list)


Expand Down Expand Up @@ -154,13 +155,12 @@ def stream():
if knowledge == '':
yield 'data: Sorry, I don\'t know about that topic. Please try again.\n\n'
return
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
stream=True
)
completion = client.chat.completions.create(model="gpt-3.5-turbo-16k",
messages=messages,
stream=True)
for line in completion:
chunk = line['choices'][0].get('delta', {}).get('content', '')
print(line.choices[0])
chunk = line.choices[0].delta.content
if chunk:
if chunk.endswith("\n"):
yield 'data: %s|CR|\n\n' % chunk.rstrip()
Expand Down

0 comments on commit cd07ff8

Please sign in to comment.