Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,8 @@ import requests
|
|
| 6 |
import json
|
| 7 |
import openai
|
| 8 |
import time
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
class Text(BaseModel):
|
| 12 |
content: str = ""
|
|
@@ -172,6 +173,22 @@ def embeddings_ep(content: Text = None):
|
|
| 172 |
return JSONResponse(content=result.json())
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
@app.post("/create_image")
|
| 176 |
def create_image_ep(content: Text = None):
|
| 177 |
url = 'https://api.openai.com/v1/images/generations'
|
|
|
|
| 6 |
import json
|
| 7 |
import openai
|
| 8 |
import time
|
| 9 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 10 |
+
import langchain
|
| 11 |
|
| 12 |
class Text(BaseModel):
|
| 13 |
content: str = ""
|
|
|
|
| 173 |
return JSONResponse(content=result.json())
|
| 174 |
|
| 175 |
|
| 176 |
+
|
| 177 |
+
@app.post("/embedd")
|
| 178 |
+
def embed(content: Text = None):
|
| 179 |
+
url = 'https://api.openai.com/v1/embeddings'
|
| 180 |
+
data = {
|
| 181 |
+
"model": "text-embedding-ada-002",
|
| 182 |
+
"input": content.content
|
| 183 |
+
}
|
| 184 |
+
result = requests.post(url=url,
|
| 185 |
+
data=json.dumps(data),
|
| 186 |
+
headers=headers
|
| 187 |
+
)
|
| 188 |
+
embeddings = OpenAIEmbeddings(openai_api_key= key)
|
| 189 |
+
return embeddings
|
| 190 |
+
|
| 191 |
+
|
| 192 |
@app.post("/create_image")
|
| 193 |
def create_image_ep(content: Text = None):
|
| 194 |
url = 'https://api.openai.com/v1/images/generations'
|