souljoy commited on
Commit
be57dbe
1 Parent(s): e83b077

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -106,6 +106,25 @@ def sale_ep(content: Text = None):
106
  return JSONResponse(content=content)
107
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  @app.post("/embeddings")
110
  def embeddings_ep(content: Text = None):
111
  url = 'https://api.openai.com/v1/embeddings'
 
106
  return JSONResponse(content=content)
107
 
108
 
109
+ @app.post("/chat_gpt")
110
+ def chat_gpt_ep(content: Text = None):
111
+ url = 'https://api.openai.com/v1/chat/completions'
112
+ obj = json.loads(content.content)
113
+ data = {
114
+ "model": "gpt-3.5-turbo",
115
+ "messages": obj['messages']
116
+ }
117
+ print("data = \n", data)
118
+ result = requests.post(url=url,
119
+ data=json.dumps(data),
120
+ headers=headers
121
+ )
122
+ res = str(result.json()['choices'][0]['message']['content']).strip()
123
+ content = {'content': res}
124
+ print('content:', content)
125
+ return JSONResponse(content=content)
126
+
127
+
128
  @app.post("/embeddings")
129
  def embeddings_ep(content: Text = None):
130
  url = 'https://api.openai.com/v1/embeddings'