fix gpt refine prompt
This commit is contained in:
@@ -74,34 +74,40 @@ async def gpt_refine_text(
|
|||||||
ge: Generator[Segment, None, None], info: TranscriptionInfo, context: str
|
ge: Generator[Segment, None, None], info: TranscriptionInfo, context: str
|
||||||
) -> str:
|
) -> str:
|
||||||
text = build_json_result(ge, info).text.strip()
|
text = build_json_result(ge, info).text.strip()
|
||||||
|
model = os.environ.get("OPENAI_LLM_MODEL", "gpt-4o-mini")
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
async with aiohttp.ClientSession() as session:
|
body: dict = {
|
||||||
async with session.post(
|
"model": model,
|
||||||
os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
"temperature": 0.1,
|
||||||
+ "/chat/completions",
|
"stream": False,
|
||||||
json={
|
"messages": [
|
||||||
"model": os.environ.get("OPENAI_LLM_MODEL", "gpt-4o-mini"),
|
{
|
||||||
"temperature": 0.1,
|
"role": "system",
|
||||||
"stream": False,
|
"content": f"""
|
||||||
"messages": [
|
You are a audio transcription text refiner. You may refer to the context to correct the transcription text.
|
||||||
{
|
Your task is to correct the transcribed text by removing redundant and repetitive words, resolving any contradictions, and fixing punctuation errors.
|
||||||
"role": "system",
|
Keep my spoken language as it is, and do not change my speaking style. Only fix the text.
|
||||||
"content": f"""
|
Response directly with the text.
|
||||||
You are a audio transcription text refiner.
|
|
||||||
You may refeer to the context to refine the transcription text.
|
|
||||||
""".strip(),
|
""".strip(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": f"""
|
"content": f"""
|
||||||
context: {context}
|
context: {context}
|
||||||
---
|
---
|
||||||
transcription: {text}
|
transcription: {text}
|
||||||
""".strip(),
|
""".strip(),
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
print(f"Refining text length: {len(text)} with {model}")
|
||||||
|
print(body)
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.post(
|
||||||
|
os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
||||||
|
+ "/chat/completions",
|
||||||
|
json=body,
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f'Bearer {os.environ["OPENAI_API_KEY"]}',
|
"Authorization": f'Bearer {os.environ["OPENAI_API_KEY"]}',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user