Compare commits
No commits in common. "70da8a4ddba2362f6ef1646c79332ad653e521fd" and "25dc7e42b44d2f62398afcc18e573645b380ac30" have entirely different histories.
70da8a4ddb
...
25dc7e42b4
|
|
@ -1,2 +0,0 @@
|
||||||
**/.venv/
|
|
||||||
**/__pycache__/
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
OPENAI_API_KEY=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
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
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.
|
|
@ -1,4 +0,0 @@
|
||||||
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