Compare commits
2 Commits
25dc7e42b4
...
70da8a4ddb
| Author | SHA1 | Date |
|---|---|---|
|
|
70da8a4ddb | |
|
|
e20c6f04ba |
|
|
@ -0,0 +1,2 @@
|
||||||
|
**/.venv/
|
||||||
|
**/__pycache__/
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
OPENAI_API_KEY=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
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
from openai import OpenAI
|
||||||
|
from fastapi import FastAPI, File, Response, Request
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
from json import dumps
|
||||||
|
from pydantic import BaseModel
|
||||||
|
import filetype
|
||||||
|
import whisper
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
openAI_clinet = OpenAI()
|
||||||
|
model = whisper.load_model("base")
|
||||||
|
|
||||||
|
|
||||||
|
class ConversationMessege(BaseModel):
|
||||||
|
role: str
|
||||||
|
content: str
|
||||||
|
|
||||||
|
|
||||||
|
class Conversation(BaseModel):
|
||||||
|
messages: list[ConversationMessege]
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/get-text")
|
||||||
|
def get_text(response: Response, audio: bytes = File()):
|
||||||
|
response.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
with open("audio", "wb") as f:
|
||||||
|
f.write(audio)
|
||||||
|
print(len(audio))
|
||||||
|
# transcript = openAI_clinet.audio.transcriptions.create(
|
||||||
|
# model="whisper-1",
|
||||||
|
# file=audio,
|
||||||
|
# response_format="text",
|
||||||
|
# RequestBody
|
||||||
|
# )
|
||||||
|
result = model.transcribe("audio")
|
||||||
|
data = {"len": len(audio), "user-transcript": result["text"]}
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/conversation")
|
||||||
|
async def get_next_response(request: Request, response: Response):
|
||||||
|
response.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
messages = await request.json()
|
||||||
|
res = openAI_clinet.chat.completions.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
messages=messages,
|
||||||
|
)
|
||||||
|
res_msg = res.choices[0].message.content
|
||||||
|
role = res.choices[0].message.role
|
||||||
|
print(res_msg)
|
||||||
|
return {"role": role, "content": res_msg}
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,4 @@
|
||||||
|
openai
|
||||||
|
fastapi
|
||||||
|
uvicorn
|
||||||
|
python-multipart
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Loading…
Reference in New Issue